summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1997-11-18 00:14:02 +0000
committerGurusamy Sarathy <gsar@cpan.org>1997-11-18 00:14:02 +0000
commit55d256264fa5ff79990a3e74153691aa2e477d37 (patch)
treed23a355f6d5d570745c612c9e570b68537a96bf4
parentfb223100faea9c444d933b6dea326556981d694c (diff)
downloadperl-55d256264fa5ff79990a3e74153691aa2e477d37.tar.gz
[Win32] Export our own FD_SET() et al to complete sockets-as-handles pretense.
p4raw-id: //depot/win32/perl@261
-rw-r--r--win32/config.bc2
-rw-r--r--win32/config.vc2
-rw-r--r--win32/config_H.bc2
-rw-r--r--win32/config_H.vc2
-rw-r--r--win32/include/sys/socket.h54
-rw-r--r--win32/win32sck.c86
6 files changed, 76 insertions, 72 deletions
diff --git a/win32/config.bc b/win32/config.bc
index 5dd96fd8e8..e3559a041a 100644
--- a/win32/config.bc
+++ b/win32/config.bc
@@ -438,7 +438,7 @@ runnm='true'
scriptdir='~INST_TOP~\bin'
scriptdirexp='~INST_TOP~\bin'
sed='sed'
-selecttype='int *'
+selecttype='Perl_fd_set *'
sendmail='blat'
sh='cmd /x /c'
shar=''
diff --git a/win32/config.vc b/win32/config.vc
index d34b1f93fb..c117689b0b 100644
--- a/win32/config.vc
+++ b/win32/config.vc
@@ -438,7 +438,7 @@ runnm='true'
scriptdir='~INST_TOP~\bin'
scriptdirexp='~INST_TOP~\bin'
sed='sed'
-selecttype='int *'
+selecttype='Perl_fd_set *'
sendmail='blat'
sh='cmd /x /c'
shar=''
diff --git a/win32/config_H.bc b/win32/config_H.bc
index 61fb5a3241..3ba2481a0f 100644
--- a/win32/config_H.bc
+++ b/win32/config_H.bc
@@ -1376,7 +1376,7 @@
* is defined, and 'int *' otherwise. This is only useful if you
* have select(), of course.
*/
-#define Select_fd_set_t int * /**/
+#define Select_fd_set_t Perl_fd_set * /**/
/* Size_t:
* This symbol holds the type used to declare length parameters
diff --git a/win32/config_H.vc b/win32/config_H.vc
index 4634072a4e..d2c6d47afb 100644
--- a/win32/config_H.vc
+++ b/win32/config_H.vc
@@ -1376,7 +1376,7 @@
* is defined, and 'int *' otherwise. This is only useful if you
* have select(), of course.
*/
-#define Select_fd_set_t int * /**/
+#define Select_fd_set_t Perl_fd_set * /**/
/* Size_t:
* This symbol holds the type used to declare length parameters
diff --git a/win32/include/sys/socket.h b/win32/include/sys/socket.h
index 487f9d5877..c6d0123143 100644
--- a/win32/include/sys/socket.h
+++ b/win32/include/sys/socket.h
@@ -44,6 +44,41 @@ typedef struct _OVERLAPPED {
#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);
@@ -63,7 +98,8 @@ u_short win32_ntohs (u_short netshort);
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);
@@ -95,6 +131,7 @@ void win32_endnetent(void);
void win32_endprotoent(void);
void win32_endservent(void);
+#ifndef WIN32SCK_IS_STDSCK
//
// direct to our version
//
@@ -143,6 +180,21 @@ void win32_endservent(void);
#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
diff --git a/win32/win32sck.c b/win32/win32sck.c
index b4f40f0de1..559691a350 100644
--- a/win32/win32sck.c
+++ b/win32/win32sck.c
@@ -9,6 +9,7 @@
*/
#define WIN32IO_IS_STDIO
+#define WIN32SCK_IS_STDSCK
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "EXTERN.h"
@@ -19,50 +20,6 @@
#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)
@@ -292,13 +249,15 @@ win32_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, i
/* 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
@@ -317,13 +276,11 @@ win32_select(int nfds, int* rd, int* wr, int* ex, const struct timeval* timeout)
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);
}
@@ -331,21 +288,16 @@ win32_select(int nfds, int* rd, int* wr, int* ex, const struct timeval* timeout)
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;
}