2

In our program, communication is happening over unix domain socket. When socket is created we are enabling socket option SO_KEEPALIVE on the socket. Call to setsockopt() is successful but netstats output doesn't so it. Output is as follows.

tcp 0 0 nemo:diamServ nemo:15388 ESTABLISHED 19997/process_name keepalive (7221.16/0/0)

unix 3 [ ] STREAM CONNECTED 228473 19997/process_name /tmp/uds1.socket

In above output we can see that "keepalive" keyword for tcp socket but for unix socket this keyword is not there. We are not sure whether keepalive is enabled for unix socket or not?

Note that diamServ is the service name corresponding to the port used for tcp socket. and /tmp/uds1.socket is unix socket file generated.

Community
  • 1
  • 1
  • One purpose of `SO_KEEPALIVE` is to make sure there's no problems in the network between the two peers. Since `AF_LOCAL` (a.k.a. `AF_UNIX`) sockets are all local to a single system the chances of network problems are slim to none. – Some programmer dude Jan 15 '20 at 11:22
  • That I agree. But as we have enabled `SO_KEEPALIVE`, is there a way I can check if keepalive is enabled or not on the socket? Or the `setsockopt()` call for enabling keepalive on `AF_UNIX` socket doesn't have any effect? – alekh chaudhary Jan 16 '20 at 11:16
  • First of all you should check what `setsockopt` returns. Does it return with an error? If so what does e.g. `perror("setsockopet")` report? Otherwise have you checked using `getsockopt` if the option is enabled? – Some programmer dude Jan 16 '20 at 11:37
  • I don't think it returns with error as return of `setsockopt` is 0. – alekh chaudhary Jan 16 '20 at 12:04
  • I'm looking for an answer too but I've found two interesting documents : **(First)** SO_KEEPALIVE Enable sending of keep-alive messages on connection-oriented sockets. Expects an integer boolean flag. https://man7.org/linux/man-pages/man7/socket.7.html **(Second)** Sockets that use the AF_UNIX or AF_UNIX_CCSID address family can be connection-oriented (type SOCK_STREAM) or connectionless (type SOCK_DGRAM). https://www.ibm.com/docs/api/v1/content/ssw_ibm_i_74/rzab6/uafunix.htm It suggests that `SO_KEEPALIVE` can work on `AF_UNIX` sockets too. – Skywalker13 Jun 28 '22 at 16:09

0 Answers0