From 401ef382596273d18ae12637e4c3df0e9ffcd72f Mon Sep 17 00:00:00 2001 From: Steve Nielsen Date: Thu, 12 Mar 1998 05:48:20 -0600 Subject: [PATCH] [win32] set sockets to nonoverlapped mode for every thread 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 | 3 +++ win32/win32sck.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/win32/win32.h b/win32/win32.h index 259ffdc..781c720 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -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 diff --git a/win32/win32sck.c b/win32/win32sck.c index 14d2e6a..b07d1f1 100644 --- a/win32/win32sck.c +++ b/win32/win32sck.c @@ -32,11 +32,22 @@ # 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; } -- 2.7.4