]> git.sur5r.net Git - openldap/blob - include/ac/socket.h
Implement TCP_NODELAY on both client and server side.
[openldap] / include / ac / socket.h
1 /*
2  * Generic socket.h
3  */
4 /*
5  * Copyright 1998,1999 The OpenLDAP Foundation, Redwood City, California, USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms are permitted only
9  * as authorized by the OpenLDAP Public License.  A copy of this
10  * license is available at http://www.OpenLDAP.org/license.html or
11  * in file LICENSE in the top-level directory of the distribution.
12  */
13
14 #ifndef _AC_SOCKET_H_
15 #define _AC_SOCKET_H_
16
17 #ifdef HAVE_SYS_TYPES_H
18 #include <sys/types.h>
19 #endif
20
21 #ifdef HAVE_SYS_SOCKET_H
22 #include <sys/socket.h>
23
24 #ifdef HAVE_SYS_SELECT_H
25 #include <sys/select.h>
26 #endif
27
28 #include <netinet/in.h>
29 #include <netinet/tcp.h>
30
31 #ifdef HAVE_ARPA_INET_H
32 #include <arpa/inet.h>
33 #endif
34
35 #ifdef HAVE_ARPA_NAMESER_H
36 #include <arpa/nameser.h>
37 #endif
38
39 #include <netdb.h>
40
41 #ifdef HAVE_RESOLV_H
42 #include <resolv.h>
43 #endif
44
45 #endif /* HAVE_SYS_SOCKET_H */
46
47 #ifdef HAVE_WINSOCK2
48 #include <winsock2.h>
49 #elif HAVE_WINSOCK
50 #include <winsock.h>
51 #else
52 #define WSACleanup()
53 #endif
54
55 #ifdef HAVE_PCNFS
56 #include <tklib.h>
57 #endif /* HAVE_PCNFS */
58
59 #ifndef INADDR_LOOPBACK
60 #define INADDR_LOOPBACK (0x7f000001UL)
61 #endif
62
63 #ifndef MAXHOSTNAMELEN
64 #define MAXHOSTNAMELEN  64
65 #endif
66
67 #ifdef HAVE_WINSOCK
68 #       define tcp_close( s )           closesocket( s );
69 #       define ioctl( s, c, a )         ioctlsocket( (s), (c), (a) )
70 #       define ioctl_t                          u_long
71 #       define AC_SOCKET_INVALID        ((unsigned int) ~0)
72
73 #define EWOULDBLOCK WSAEWOULDBLOCK
74
75 #elif MACOS
76 #       define tcp_close( s )           tcpclose( s )
77
78 #elif DOS
79 #       ifdef PCNFS
80 #               define tcp_close( s )   close( s )
81 #       endif /* PCNFS */
82 #       ifdef NCSA
83 #               define tcp_close( s )   do { netclose( s ); netshut() } while(0)
84 #       endif /* NCSA */
85
86 #elif HAVE_CLOSESOCKET
87 #       define tcp_close( s )           closesocket( s )
88
89 #else
90 #       define tcp_close( s )           close( s )
91 #endif /* MACOS */
92
93 #ifndef ioctl_t
94 #       define ioctl_t                          int
95 #endif
96
97 #ifndef AC_SOCKET_INVALID
98 #       define AC_SOCKET_INVALID        (-1)
99 #endif
100
101 #if     defined(__WIN32) && defined(_ALPHA)
102 /* NT on Alpha is hosed. */
103 #define AC_HTONL( l ) \
104         ((((l)&0xff)<<24) + (((l)&0xff00)<<8) + \
105          (((l)&0xff0000)>>8) + (((l)&0xff000000)>>24))
106 #define AC_NTOHL(l) AC_HTONL(l)
107
108 #elif defined(__alpha) && !defined(VMS)
109 /*
110  * htonl and ntohl on the DEC Alpha under OSF 1 seem to only swap the
111  * lower-order 32-bits of a (64-bit) long, so we define correct versions
112  * here.
113  */ 
114 #define AC_HTONL( l )   (((long)htonl( (l) & 0x00000000FFFFFFFF )) << 32 \
115         | htonl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
116
117 #define AC_NTOHL( l ) (((long)ntohl( (l) & 0x00000000FFFFFFFF )) << 32 \
118         | ntohl( ( (l) & 0xFFFFFFFF00000000 ) >> 32 ))
119
120 #else
121 #define AC_HTONL( l ) htonl( l )
122 #define AC_NTOHL( l ) ntohl( l )
123 #endif
124
125 /* htons()/ntohs() may be broken much like htonl()/ntohl() */
126 #define AC_HTONS( s ) htons( s )
127 #define AC_NTOHS( s ) ntohs( s )
128
129
130 #endif /* _AC_SOCKET_H_ */