]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/nfs/svc_socket.c
multiple threads for mountd
[nfs-utils.git] / support / nfs / svc_socket.c
index ca323e6b9aa57c3251e854f5e98bf04b2c84d82a..888c915931b000f42d86d026bc94e86ed8329139 100644 (file)
 #include <netdb.h>
 #include <rpc/rpc.h>
 #include <sys/socket.h>
+#include <sys/fcntl.h>
 #include <errno.h>
 
 #ifdef _LIBC
 # include <libintl.h>
 #else
-# include "config.h"
 # ifndef _
 #  define _(s)                 (s)
 # endif
@@ -35,7 +35,6 @@
 # define __close(f)            close ((f))
 #endif
 
-#if !defined HAVE_SVCTCP_SOCKET || !defined HAVE_SVCUDP_SOCKET
 static int
 svc_socket (u_long number, int type, int protocol, int reuse)
 {
@@ -114,11 +113,29 @@ svc_socket (u_long number, int type, int protocol, int reuse)
        }
     }
 
+  if (sock >= 0 && protocol == IPPROTO_TCP)
+    {
+       /* Make the TCP rendezvous socket non-block to avoid
+        * problems with blocking in accept() after a spurious
+        * wakeup from the kernel */
+       int flags;
+       if ((flags = fcntl(sock, F_GETFL)) < 0)
+         {
+             perror (_("svc_socket: can't get socket flags"));
+             (void) __close (sock);
+             sock = -1;
+         }
+       else if (fcntl(sock, F_SETFL, flags|O_NONBLOCK) < 0)
+         {
+             perror (_("svc_socket: can't set socket flags"));
+             (void) __close (sock);
+             sock = -1;
+         }
+    }
+
   return sock;
 }
-#endif
 
-#ifndef HAVE_SVCTCP_SOCKET
 /*
  * Create and bind a TCP socket based on program number
  */
@@ -127,9 +144,7 @@ svctcp_socket (u_long number, int reuse)
 {
   return svc_socket (number, SOCK_STREAM, IPPROTO_TCP, reuse);
 }
-#endif
 
-#ifndef HAVE_SVCUDP_SOCKET
 /*
  * Create and bind a UDP socket based on program number
  */
@@ -138,7 +153,6 @@ svcudp_socket (u_long number, int reuse)
 {
   return svc_socket (number, SOCK_DGRAM, IPPROTO_UDP, reuse);
 }
-#endif
 
 #ifdef TEST
 static int