3 /* portable -- header loading to write portable code */
5 /* Copyright (c) 2004 Martin Quinson. */
8 #ifndef GRAS_PORTABLE_H
9 #define GRAS_PORTABLE_H
11 #include "gras_config.h"
14 #include <sys/time.h> /* struct timeval */
15 #include <sys/types.h>
22 #ifdef HAVE_SYS_SOCKET_H
23 # include <sys/socket.h>
24 # include <netinet/in.h> /* sometimes required for #include <arpa/inet.h> */
25 # include <netinet/tcp.h> /* TCP_NODELAY */
26 # include <netdb.h> /* getprotobyname() */
27 # include <arpa/inet.h> /* inet_ntoa() */
30 #ifdef HAVE_WINSOCK2_H
31 # include <winsock2.h>
32 # include <ws2tcpip.h> /* socklen_t, but doubtful */
38 # define tcp_read( s, buf, len ) recv( s, buf, len, 0 )
39 # define tcp_write( s, buf, len ) send( s, buf, len, 0 )
40 # define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) )
41 # define ioctl_t u_long
42 # define AC_SOCKET_INVALID ((unsigned int) ~0)
45 # define tcp_close( s ) (shutdown( s, SD_BOTH ), closesocket( s ))
47 # define tcp_close( s ) closesocket( s )
50 # define EWOULDBLOCK WSAEWOULDBLOCK
51 # define EINPROGRESS WSAEINPROGRESS
52 # define ETIMEDOUT WSAETIMEDOUT
56 # define sock_errno() WSAGetLastError()
57 # define sock_errstr(e) ber_pvt_wsa_err2string(e)
59 char *ber_pvt_wsa_err2string(int errcode);
65 # define tcp_read( s, buf, len) read( s, buf, len )
66 # define tcp_write( s, buf, len) write( s, buf, len )
69 # define tcp_close( s ) (shutdown( s, SHUT_RDWR ), close( s ))
71 # define tcp_close( s ) close( s )
73 #endif /* windows or unix ? */
81 #ifdef HAVE_SYS_STAT_H
89 #if TIME_WITH_SYS_TIME
90 # include <sys/time.h>
94 # include <sys/time.h>
101 #define sleep _sleep /* else defined in stdlib.h */
105 #endif /* GRAS_PORTABLE_H */