[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
CommitLineData
0a753a76 1// sys/socket.h
2
3// djl
4// Provide UNIX compatibility
5
0a753a76 6#ifndef _INC_SYS_SOCKET
7#define _INC_SYS_SOCKET
8
7bac28a0 9#ifdef __cplusplus
10extern "C" {
11#endif
0a753a76 12
13#ifndef _WINDOWS_
14#define _WINDOWS_
15
16#define FAR
17#define PASCAL __stdcall
18#define WINAPI __stdcall
19
20#undef WORD
21typedef int BOOL;
22typedef unsigned short WORD;
23typedef void* HANDLE;
24typedef void* HWND;
25typedef int (FAR WINAPI *FARPROC)();
26
27typedef unsigned long DWORD;
28typedef void *PVOID;
29
30#define IN
31#define OUT
32
33typedef struct _OVERLAPPED {
34 DWORD Internal;
35 DWORD InternalHigh;
36 DWORD Offset;
37 DWORD OffsetHigh;
38 HANDLE hEvent;
39} OVERLAPPED, *LPOVERLAPPED;
40
41#endif //_WINDOWS_
42#include <winsock.h>
43
44#define ENOTSOCK WSAENOTSOCK
45#undef HOST_NOT_FOUND
46
55d25626 47#ifdef USE_SOCKETS_AS_HANDLES
48
49#ifndef PERL_FD_SETSIZE
50#define PERL_FD_SETSIZE 64
51#endif
52
53#define PERL_BITS_PER_BYTE 8
54#define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
55
56typedef int Perl_fd_mask;
57
58typedef struct Perl_fd_set {
59 Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
60} Perl_fd_set;
61
62#define PERL_FD_CLR(n,p) \
63 ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
64
65#define PERL_FD_SET(n,p) \
66 ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
67
68#define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
69
70#define PERL_FD_ISSET(n,p) \
71 ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
72
73#else /* USE_SOCKETS_AS_HANDLES */
74
75#define Perl_fd_set fd_set
76#define PERL_FD_SET(n,p) FD_SET(n,p)
77#define PERL_FD_CLR(n,p) FD_CLR(n,p)
78#define PERL_FD_ISSET(n,p) FD_ISSET(n,p)
79#define PERL_FD_ZERO(p) FD_ZERO(p)
80
81#endif /* USE_SOCKETS_AS_HANDLES */
0a753a76 82
83SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
84int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
85int win32_closesocket (SOCKET s);
86int win32_connect (SOCKET s, const struct sockaddr *name, int namelen);
87int win32_ioctlsocket (SOCKET s, long cmd, u_long *argp);
88int win32_getpeername (SOCKET s, struct sockaddr *name, int * namelen);
89int win32_getsockname (SOCKET s, struct sockaddr *name, int * namelen);
90int win32_getsockopt (SOCKET s, int level, int optname, char * optval, int *optlen);
91u_long win32_htonl (u_long hostlong);
92u_short win32_htons (u_short hostshort);
93unsigned long win32_inet_addr (const char * cp);
94char * win32_inet_ntoa (struct in_addr in);
95int win32_listen (SOCKET s, int backlog);
96u_long win32_ntohl (u_long netlong);
97u_short win32_ntohs (u_short netshort);
98int win32_recv (SOCKET s, char * buf, int len, int flags);
99int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
100 struct sockaddr *from, int * fromlen);
55d25626 101int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
102 const struct timeval *timeout);
0a753a76 103int win32_send (SOCKET s, const char * buf, int len, int flags);
104int win32_sendto (SOCKET s, const char * buf, int len, int flags,
105 const struct sockaddr *to, int tolen);
106int win32_setsockopt (SOCKET s, int level, int optname,
107 const char * optval, int optlen);
108SOCKET win32_socket (int af, int type, int protocol);
109int win32_shutdown (SOCKET s, int how);
110
111/* Database function prototypes */
112
113struct hostent * win32_gethostbyaddr(const char * addr, int len, int type);
114struct hostent * win32_gethostbyname(const char * name);
115int win32_gethostname (char * name, int namelen);
116struct servent * win32_getservbyport(int port, const char * proto);
117struct servent * win32_getservbyname(const char * name, const char * proto);
118struct protoent * win32_getprotobynumber(int proto);
119struct protoent * win32_getprotobyname(const char * name);
120struct protoent *win32_getprotoent(void);
121struct servent *win32_getservent(void);
122void win32_sethostent(int stayopen);
123void win32_setnetent(int stayopen);
3e3baf6d 124struct netent * win32_getnetent(void);
125struct netent * win32_getnetbyname(char *name);
126struct netent * win32_getnetbyaddr(long net, int type);
0a753a76 127void win32_setprotoent(int stayopen);
128void win32_setservent(int stayopen);
3e3baf6d 129void win32_endhostent(void);
130void win32_endnetent(void);
131void win32_endprotoent(void);
132void win32_endservent(void);
0a753a76 133
55d25626 134#ifndef WIN32SCK_IS_STDSCK
0a753a76 135//
136// direct to our version
137//
138#define htonl win32_htonl
139#define htons win32_htons
140#define ntohl win32_ntohl
141#define ntohs win32_ntohs
142#define inet_addr win32_inet_addr
143#define inet_ntoa win32_inet_ntoa
144
145#define socket win32_socket
146#define bind win32_bind
147#define listen win32_listen
148#define accept win32_accept
149#define connect win32_connect
150#define send win32_send
151#define sendto win32_sendto
152#define recv win32_recv
153#define recvfrom win32_recvfrom
154#define shutdown win32_shutdown
3a25acb4 155#define closesocket win32_closesocket
0a753a76 156#define ioctlsocket win32_ioctlsocket
157#define setsockopt win32_setsockopt
158#define getsockopt win32_getsockopt
159#define getpeername win32_getpeername
160#define getsockname win32_getsockname
161#define gethostname win32_gethostname
162#define gethostbyname win32_gethostbyname
163#define gethostbyaddr win32_gethostbyaddr
164#define getprotobyname win32_getprotobyname
165#define getprotobynumber win32_getprotobynumber
166#define getservbyname win32_getservbyname
167#define getservbyport win32_getservbyport
168#define select win32_select
169#define endhostent win32_endhostent
170#define endnetent win32_endnetent
171#define endprotoent win32_endprotoent
172#define endservent win32_endservent
173#define getnetent win32_getnetent
174#define getnetbyname win32_getnetbyname
175#define getnetbyaddr win32_getnetbyaddr
176#define getprotoent win32_getprotoent
177#define getservent win32_getservent
178#define sethostent win32_sethostent
179#define setnetent win32_setnetent
180#define setprotoent win32_setprotoent
181#define setservent win32_setservent
182
55d25626 183#ifdef USE_SOCKETS_AS_HANDLES
184#undef fd_set
185#undef FD_SET
186#undef FD_CLR
187#undef FD_ISSET
188#undef FD_ZERO
189#define fd_set Perl_fd_set
190#define FD_SET(n,p) PERL_FD_SET(n,p)
191#define FD_CLR(n,p) PERL_FD_CLR(n,p)
192#define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
193#define FD_ZERO(p) PERL_FD_ZERO(p)
194#endif /* USE_SOCKETS_AS_HANDLES */
195
196#endif /* WIN32SCK_IS_STDSCK */
197
0a753a76 198#ifdef __cplusplus
199}
200#endif
201
202#endif // _INC_SYS_SOCKET