#define ENOTSOCK WSAENOTSOCK
#undef HOST_NOT_FOUND
+#ifdef USE_SOCKETS_AS_HANDLES
+
+#ifndef PERL_FD_SETSIZE
+#define PERL_FD_SETSIZE 64
+#endif
+
+#define PERL_BITS_PER_BYTE 8
+#define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
+
+typedef int Perl_fd_mask;
+
+typedef struct Perl_fd_set {
+ Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
+} Perl_fd_set;
+
+#define PERL_FD_CLR(n,p) \
+ ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
+
+#define PERL_FD_SET(n,p) \
+ ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
+
+#define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
+
+#define PERL_FD_ISSET(n,p) \
+ ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
+
+#else /* USE_SOCKETS_AS_HANDLES */
+
+#define Perl_fd_set fd_set
+#define PERL_FD_SET(n,p) FD_SET(n,p)
+#define PERL_FD_CLR(n,p) FD_CLR(n,p)
+#define PERL_FD_ISSET(n,p) FD_ISSET(n,p)
+#define PERL_FD_ZERO(p) FD_ZERO(p)
+
+#endif /* USE_SOCKETS_AS_HANDLES */
SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
int win32_recv (SOCKET s, char * buf, int len, int flags);
int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
struct sockaddr *from, int * fromlen);
-int win32_select (int nfds, int *readfds, int *writefds, int *exceptfds, const struct timeval *timeout);
+int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
+ const struct timeval *timeout);
int win32_send (SOCKET s, const char * buf, int len, int flags);
int win32_sendto (SOCKET s, const char * buf, int len, int flags,
const struct sockaddr *to, int tolen);
void win32_endprotoent(void);
void win32_endservent(void);
+#ifndef WIN32SCK_IS_STDSCK
//
// direct to our version
//
#define setprotoent win32_setprotoent
#define setservent win32_setservent
+#ifdef USE_SOCKETS_AS_HANDLES
+#undef fd_set
+#undef FD_SET
+#undef FD_CLR
+#undef FD_ISSET
+#undef FD_ZERO
+#define fd_set Perl_fd_set
+#define FD_SET(n,p) PERL_FD_SET(n,p)
+#define FD_CLR(n,p) PERL_FD_CLR(n,p)
+#define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
+#define FD_ZERO(p) PERL_FD_ZERO(p)
+#endif /* USE_SOCKETS_AS_HANDLES */
+
+#endif /* WIN32SCK_IS_STDSCK */
+
#ifdef __cplusplus
}
#endif
*/
#define WIN32IO_IS_STDIO
+#define WIN32SCK_IS_STDSCK
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "EXTERN.h"
#include <assert.h>
#include <io.h>
-#undef htonl
-#undef htons
-#undef ntohl
-#undef ntohs
-#undef inet_addr
-#undef inet_ntoa
-#undef socket
-#undef bind
-#undef listen
-#undef accept
-#undef connect
-#undef send
-#undef sendto
-#undef recv
-#undef recvfrom
-#undef shutdown
-#undef closesocket
-#undef ioctlsocket
-#undef setsockopt
-#undef getsockopt
-#undef getpeername
-#undef getsockname
-#undef gethostname
-#undef gethostbyname
-#undef gethostbyaddr
-#undef getprotobyname
-#undef getprotobynumber
-#undef getservbyname
-#undef getservbyport
-#undef select
-#undef endhostent
-#undef endnetent
-#undef endprotoent
-#undef endservent
-#undef getnetent
-#undef getnetbyname
-#undef getnetbyaddr
-#undef getprotoent
-#undef getservent
-#undef sethostent
-#undef setnetent
-#undef setprotoent
-#undef setservent
-
/* thanks to Beverly Brown (beverly@datacube.com) */
#ifdef USE_SOCKETS_AS_HANDLES
# define OPEN_SOCKET(x) _open_osfhandle(x,O_RDWR|O_BINARY)
/* select contributed by Vincent R. Slyngstad (vrs@ibeam.intel.com) */
int
-win32_select(int nfds, int* rd, int* wr, int* ex, const struct timeval* timeout)
+win32_select(int nfds, Perl_fd_set* rd, Perl_fd_set* wr, Perl_fd_set* ex, const struct timeval* timeout)
{
- long r;
- int dummy = 0;
+ int r;
+#ifdef USE_SOCKETS_AS_HANDLES
+ Perl_fd_set dummy;
int i, fd, bit, offset;
- FD_SET nrd, nwr, nex,*prd,*pwr,*pex;
+ FD_SET nrd, nwr, nex, *prd, *pwr, *pex;
+ PERL_FD_ZERO(&dummy);
if (!rd)
rd = &dummy, prd = NULL;
else
FD_ZERO(&nex);
for (i = 0; i < nfds; i++) {
fd = TO_SOCKET(i);
- bit = 1L<<(i % (sizeof(int)*8));
- offset = i / (sizeof(int)*8);
- if (rd[offset] & bit)
+ if (PERL_FD_ISSET(i,rd))
FD_SET(fd, &nrd);
- if (wr[offset] & bit)
+ if (PERL_FD_ISSET(i,wr))
FD_SET(fd, &nwr);
- if (ex[offset] & bit)
+ if (PERL_FD_ISSET(i,ex))
FD_SET(fd, &nex);
}
for (i = 0; i < nfds; i++) {
fd = TO_SOCKET(i);
- bit = 1L<<(i % (sizeof(int)*8));
- offset = i / (sizeof(int)*8);
- if (rd[offset] & bit) {
- if (!__WSAFDIsSet(fd, &nrd))
- rd[offset] &= ~bit;
- }
- if (wr[offset] & bit) {
- if (!__WSAFDIsSet(fd, &nwr))
- wr[offset] &= ~bit;
- }
- if (ex[offset] & bit) {
- if (!__WSAFDIsSet(fd, &nex))
- ex[offset] &= ~bit;
- }
+ if (PERL_FD_ISSET(i,rd) && !FD_ISSET(fd, &nrd))
+ PERL_FD_CLR(i,rd);
+ if (PERL_FD_ISSET(i,wr) && !FD_ISSET(fd, &nwr))
+ PERL_FD_CLR(i,wr);
+ if (PERL_FD_ISSET(i,ex) && !FD_ISSET(fd, &nex))
+ PERL_FD_CLR(i,ex);
}
+#else
+ SOCKET_TEST_ERROR(r = select(nfds, rd, wr, ex, timeout));
+#endif
return r;
}