#define WIN32_LEAN_AND_MEAN
#ifdef __GNUC__
#define Win32_Winsock
+# ifdef __cplusplus
+#undef __attribute__ /* seems broken in 2.8.0 */
+#define __attribute__(p)
+# endif
#endif
#include <windows.h>
#include "EXTERN.h"
#include "perl.h"
+
+#if defined(PERL_OBJECT)
+#define NO_XSLOCKS
+extern CPerlObj* pPerl;
+#include "XSUB.h"
+#endif
+
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/stat.h>
# 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 { \
#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;
unsigned short version;
WSADATA retdata;
int ret;
- int iSockOpt = SO_SYNCHRONOUS_NONALERT;
/*
* initalize the winsock interface and insure that it is
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;
}
int i, fd, bit, offset;
FD_SET nrd, nwr, nex, *prd, *pwr, *pex;
+ /* winsock seems incapable of dealing with all three null fd_sets,
+ * so do the (millisecond) sleep as a special case
+ */
+ if (!(rd || wr || ex)) {
+ Sleep(timeout->tv_sec * 1000 +
+ timeout->tv_usec / 1000); /* do the best we can */
+ return 0;
+ }
+ StartSockets();
PERL_FD_ZERO(&dummy);
if (!rd)
rd = &dummy, prd = NULL;
d->s_proto = s->s_proto;
else
#endif
- if (proto && strlen(proto))
+ if (proto && strlen(proto))
d->s_proto = (char *)proto;
else
d->s_proto = "tcp";