[Win32] Export our own FD_SET() et al to complete sockets-as-handles pretense.
[p5sagit/p5-mst-13.2.git] / win32 / include / sys / socket.h
index 7485195..c6d0123 100644 (file)
@@ -3,12 +3,12 @@
 // djl
 // Provide UNIX compatibility
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 #ifndef  _INC_SYS_SOCKET
 #define  _INC_SYS_SOCKET
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 #ifndef  _WINDOWS_
 #define  _WINDOWS_
@@ -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);
@@ -85,13 +121,17 @@ struct protoent *win32_getprotoent(void);
 struct servent *win32_getservent(void);
 void win32_sethostent(int stayopen);
 void win32_setnetent(int stayopen);
+struct netent * win32_getnetent(void);
+struct netent * win32_getnetbyname(char *name);
+struct netent * win32_getnetbyaddr(long net, int type);
 void win32_setprotoent(int stayopen);
 void win32_setservent(int stayopen);
-void win32_endhostent();
-void win32_endnetent();
-void win32_endprotoent();
-void win32_endservent();
+void win32_endhostent(void);
+void win32_endnetent(void);
+void win32_endprotoent(void);
+void win32_endservent(void);
 
+#ifndef WIN32SCK_IS_STDSCK
 //
 // direct to our version
 //
@@ -112,6 +152,7 @@ void win32_endservent();
 #define recv           win32_recv
 #define recvfrom       win32_recvfrom
 #define shutdown       win32_shutdown
+#define closesocket    win32_closesocket
 #define ioctlsocket    win32_ioctlsocket
 #define setsockopt     win32_setsockopt
 #define getsockopt     win32_getsockopt
@@ -139,6 +180,21 @@ void win32_endservent();
 #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