From: Steve Nielsen Date: Thu, 12 Mar 1998 11:48:20 +0000 (-0600) Subject: [win32] set sockets to nonoverlapped mode for every thread X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=401ef382596273d18ae12637e4c3df0e9ffcd72f;p=p5sagit%2Fp5-mst-13.2.git [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 --- 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; }