Merged r158229 through r158464 into branch.
[official-gcc.git] / gcc / ada / gsocket.h
blobca016c921c0aaf2bc6163a9736203648ade1e29d
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * G S O C K E T *
6 * *
7 * C Header File *
8 * *
9 * Copyright (C) 2004-2010, Free Software Foundation, Inc. *
10 * *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 3, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. *
17 * *
18 * As a special exception under Section 7 of GPL version 3, you are granted *
19 * additional permissions described in the GCC Runtime Library Exception, *
20 * version 3.1, as published by the Free Software Foundation. *
21 * *
22 * You should have received a copy of the GNU General Public License and *
23 * a copy of the GCC Runtime Library Exception along with this program; *
24 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see *
25 * <http://www.gnu.org/licenses/>. *
26 * *
27 * GNAT was originally developed by the GNAT team at New York University. *
28 * Extensive contributions were provided by Ada Core Technologies Inc. *
29 * *
30 ****************************************************************************/
32 #if defined(__nucleus__) || defined(VTHREADS)
34 #warning Sockets not supported on these platforms
35 #undef HAVE_SOCKETS
37 #else
39 #define HAVE_SOCKETS
41 #ifndef _XOPEN_SOURCE_EXTENDED
42 #define _XOPEN_SOURCE_EXTENDED 1
43 /* For HP-UX */
44 #endif
46 #ifndef BSD_COMP
47 #define BSD_COMP 1
48 /* For Solaris */
49 #endif
51 #ifndef _ALL_SOURCE
52 #define _ALL_SOURCE 1
53 /* For AIX */
54 #endif
56 #ifndef _OSF_SOURCE
57 #define _OSF_SOURCE 1
58 /* For Tru64 */
59 #endif
61 #include <limits.h>
62 #include <errno.h>
64 #if defined(__vxworks)
65 #include <vxWorks.h>
66 #include <ioLib.h>
67 #include <hostLib.h>
68 #define SHUT_RD 0
69 #define SHUT_WR 1
70 #define SHUT_RDWR 2
72 #elif defined (WINNT)
73 #define FD_SETSIZE 1024
74 #include <windows.h>
76 #ifdef __MINGW32__
77 #include <winsock2.h>
78 #include <ws2tcpip.h>
80 #undef EACCES
81 #define EACCES WSAEACCES
82 #undef EADDRINUSE
83 #define EADDRINUSE WSAEADDRINUSE
84 #undef EADDRNOTAVAIL
85 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
86 #undef EAFNOSUPPORT
87 #define EAFNOSUPPORT WSAEAFNOSUPPORT
88 #undef EALREADY
89 #define EALREADY WSAEALREADY
90 #undef EBADF
91 #define EBADF WSAEBADF
92 #undef ECONNABORTED
93 #define ECONNABORTED WSAECONNABORTED
94 #undef ECONNREFUSED
95 #define ECONNREFUSED WSAECONNREFUSED
96 #undef ECONNRESET
97 #define ECONNRESET WSAECONNRESET
98 #undef EDESTADDRREQ
99 #define EDESTADDRREQ WSAEDESTADDRREQ
100 #undef EFAULT
101 #define EFAULT WSAEFAULT
102 #undef EHOSTDOWN
103 #define EHOSTDOWN WSAEHOSTDOWN
104 #undef EHOSTUNREACH
105 #define EHOSTUNREACH WSAEHOSTUNREACH
106 #undef EINPROGRESS
107 #define EINPROGRESS WSAEINPROGRESS
108 #undef EINTR
109 #define EINTR WSAEINTR
110 #undef EINVAL
111 #define EINVAL WSAEINVAL
112 #undef EIO
113 #define EIO WSAEDISCON
114 #undef EISCONN
115 #define EISCONN WSAEISCONN
116 #undef ELOOP
117 #define ELOOP WSAELOOP
118 #undef EMFILE
119 #define EMFILE WSAEMFILE
120 #undef EMSGSIZE
121 #define EMSGSIZE WSAEMSGSIZE
122 #undef ENAMETOOLONG
123 #define ENAMETOOLONG WSAENAMETOOLONG
124 #undef ENETDOWN
125 #define ENETDOWN WSAENETDOWN
126 #undef ENETRESET
127 #define ENETRESET WSAENETRESET
128 #undef ENETUNREACH
129 #define ENETUNREACH WSAENETUNREACH
130 #undef ENOBUFS
131 #define ENOBUFS WSAENOBUFS
132 #undef ENOPROTOOPT
133 #define ENOPROTOOPT WSAENOPROTOOPT
134 #undef ENOTCONN
135 #define ENOTCONN WSAENOTCONN
136 #undef ENOTSOCK
137 #define ENOTSOCK WSAENOTSOCK
138 #undef EOPNOTSUPP
139 #define EOPNOTSUPP WSAEOPNOTSUPP
140 #undef EPFNOSUPPORT
141 #define EPFNOSUPPORT WSAEPFNOSUPPORT
142 #undef EPROTONOSUPPORT
143 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
144 #undef EPROTOTYPE
145 #define EPROTOTYPE WSAEPROTOTYPE
146 #undef ESHUTDOWN
147 #define ESHUTDOWN WSAESHUTDOWN
148 #undef ESOCKTNOSUPPORT
149 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
150 #undef ETIMEDOUT
151 #define ETIMEDOUT WSAETIMEDOUT
152 #undef ETOOMANYREFS
153 #define ETOOMANYREFS WSAETOOMANYREFS
154 #undef EWOULDBLOCK
155 #define EWOULDBLOCK WSAEWOULDBLOCK
157 #define SHUT_RD SD_RECEIVE
158 #define SHUT_WR SD_SEND
159 #define SHUT_RDWR SD_BOTH
161 #endif
163 #elif defined(VMS)
164 #define FD_SETSIZE 4096
165 #ifndef IN_RTS
166 /* These DEC C headers are not available when building with GCC */
167 #include <in.h>
168 #include <tcp.h>
169 #include <ioctl.h>
170 #include <netdb.h>
171 #endif
173 #endif
175 #if defined (__vxworks) && ! defined (__RTP__)
176 #include <sys/times.h>
177 #else
178 #include <sys/time.h>
179 #endif
182 * RTEMS has these .h files but not until you have built and installed
183 * RTEMS. When building a C/C++ toolset, you also build the newlib C library.
184 * So the build procedure for an RTEMS GNAT toolset requires that
185 * you build a C/C++ toolset, then build and install RTEMS with
186 * --enable-multilib, and finally build the Ada part of the toolset.
188 #if !(defined (VMS) || defined (__MINGW32__))
189 #include <sys/socket.h>
190 #include <netinet/in.h>
191 #include <netinet/tcp.h>
192 #include <sys/ioctl.h>
193 #include <netdb.h>
194 #endif
197 * Handling of gethostbyname, gethostbyaddr, getservbyname and getservbyport
198 * =========================================================================
200 * The default implementation of GNAT.Sockets.Thin requires that these
201 * operations be either thread safe, or that a reentrant version getXXXbyYYY_r
202 * be provided. In both cases, socket.c provides a __gnat_safe_getXXXbyYYY
203 * function with the same signature as getXXXbyYYY_r. If the operating
204 * system version of getXXXbyYYY is thread safe, the provided auxiliary
205 * buffer argument is unused and ignored.
207 * Target specific versions of GNAT.Sockets.Thin for platforms that can't
208 * fulfill these requirements must provide their own protection mechanism
209 * in Safe_GetXXXbyYYY, and if they require GNAT.Sockets to provide a buffer
210 * to this effect, then we need to set Need_Netdb_Buffer here (case of
211 * VxWorks and VMS).
214 #if defined (_AIX) || defined (__FreeBSD__) || defined (__hpux__) || defined (__osf__) || defined (_WIN32) || defined (__APPLE__)
215 # define HAVE_THREAD_SAFE_GETxxxBYyyy 1
216 #elif defined (sgi) || defined (linux) || defined (__GLIBC__) || (defined (sun) && defined (__SVR4) && !defined (__vxworks)) || defined(__rtems__)
217 # define HAVE_GETxxxBYyyy_R 1
218 #endif
220 #if defined (HAVE_GETxxxBYyyy_R) || !defined (HAVE_THREAD_SAFE_GETxxxBYyyy)
221 # define Need_Netdb_Buffer 1
222 #else
223 # define Need_Netdb_Buffer 0
224 #endif
226 #if defined (__FreeBSD__) || defined (__vxworks) || defined(__rtems__)
227 # define Has_Sockaddr_Len 1
228 #else
229 # define Has_Sockaddr_Len 0
230 #endif
232 #if !(defined (__vxworks) || defined (_WIN32) || defined (__hpux__) || defined (VMS))
233 # define HAVE_INET_PTON
234 #endif
236 #endif /* defined(__nucleus__) */