[win32] set sockets to nonoverlapped mode for every thread
Steve Nielsen [Thu, 12 Mar 1998 11:48:20 +0000 (05:48 -0600)]
Message-Id: <35081FE4.965A484D@enteract.com>
Subject: [PATCH 5.004_62] win32: set sockopt on a per-thread basis

p4raw-id: //depot/win32/perl@808

win32/win32.h
win32/win32sck.c

index 259ffdc..781c720 100644 (file)
@@ -229,6 +229,9 @@ struct thread_intern {
     char               Wstrerror_buffer[512];
     struct servent     Wservent;
     char               Wgetlogin_buffer[128];
+#    ifdef USE_SOCKETS_AS_HANDLES
+    int                        Winit_socktype;
+#    endif
 #    ifdef HAVE_DES_FCRYPT
     char               Wcrypt_buffer[30];
 #    endif
index 14d2e6a..b07d1f1 100644 (file)
 #      define TO_SOCKET(x)     (x)
 #endif /* USE_SOCKETS_AS_HANDLES */
 
+#ifdef USE_THREADS
 #define StartSockets() \
     STMT_START {                                       \
        if (!wsock_started)                             \
            start_sockets();                            \
+       set_socktype();                         \
+    } STMT_END
+#else
+#define StartSockets() \
+    STMT_START {                                       \
+       if (!wsock_started) {                           \
+           start_sockets();                            \
+           set_socktype();                             \
+       }                                               \
     } STMT_END
+#endif
 
 #define EndSockets() \
     STMT_START {                                       \
@@ -60,8 +71,10 @@ static struct servent* win32_savecopyservent(struct servent*d,
 #ifdef USE_THREADS
 #ifdef USE_DECLSPEC_THREAD
 __declspec(thread) struct servent myservent;
+__declspec(thread) int init_socktype;
 #else
 #define myservent (thr->i.Wservent)
+#define init_socktype (thr->i.Winit_socktype)
 #endif
 #else
 static struct servent myservent;
@@ -75,7 +88,6 @@ start_sockets(void)
     unsigned short version;
     WSADATA retdata;
     int ret;
-    int iSockOpt = SO_SYNCHRONOUS_NONALERT;
 
     /*
      * initalize the winsock interface and insure that it is
@@ -88,15 +100,28 @@ start_sockets(void)
        croak("Could not find version 1.1 of winsock dll\n");
 
     /* atexit((void (*)(void)) EndSockets); */
+    wsock_started = 1;
+}
 
+void
+set_socktype(void)
+{
 #ifdef USE_SOCKETS_AS_HANDLES
+#ifdef USE_THREADS
+    dTHR;
+    if(!init_socktype) {
+#endif
+    int iSockOpt = SO_SYNCHRONOUS_NONALERT;
     /*
      * Enable the use of sockets as filehandles
      */
     setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
                (char *)&iSockOpt, sizeof(iSockOpt));
+#ifdef USE_THREADS
+    init_socktype = 1;
+    }
+#endif
 #endif /* USE_SOCKETS_AS_HANDLES */
-    wsock_started = 1;
 }