Add explanatory comment to make_unix_socket().
[openvswitch] / lib / socket-util.c
index 8fa663ad75fc3784c8560390f2ddcb4422343f4a..7d54a4818514416ce827346efb489cfea5d13bed 100644 (file)
@@ -201,6 +201,10 @@ make_unix_socket(int style, bool nonblock, bool passcred UNUSED,
         return -errno;
     }
 
+    /* Set nonblocking mode right away, if we want it.  This prevents blocking
+     * in connect(), if connect_path != NULL.  (In turn, that's a corner case:
+     * it will only happen if style is SOCK_STREAM or SOCK_SEQPACKET, and only
+     * if a backlog of un-accepted connections has built up in the kernel.)  */
     if (nonblock) {
         int flags = fcntl(fd, F_GETFL, 0);
         if (flags == -1) {
@@ -254,3 +258,11 @@ error:
     close(fd);
     return -error;
 }
+
+int
+get_unix_name_len(socklen_t sun_len)
+{
+    return (sun_len >= offsetof(struct sockaddr_un, sun_path)
+            ? sun_len - offsetof(struct sockaddr_un, sun_path)
+            : 0);
+}