OSDN Git Service

2009-04-07 Emmanuel Briot <briot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / gsocket.h
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-2008, 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 2,  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.  See the GNU General Public License *
17  * for  more details.  You should have  received  a copy of the GNU General *
18  * Public License  distributed with GNAT;  see file COPYING.  If not, write *
19  * to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, *
20  * Boston, MA 02110-1301, USA.                                              *
21  *                                                                          *
22  * As a  special  exception,  if you  link  this file  with other  files to *
23  * produce an executable,  this file does not by itself cause the resulting *
24  * executable to be covered by the GNU General Public License. This except- *
25  * ion does not  however invalidate  any other reasons  why the  executable *
26  * file might be covered by the  GNU Public License.                        *
27  *                                                                          *
28  * GNAT was originally developed  by the GNAT team at  New York University. *
29  * Extensive contributions were provided by Ada Core Technologies Inc.      *
30  *                                                                          *
31  ****************************************************************************/
32
33 #if defined(__nucleus__)
34
35 #warning Sockets not supported on this platform
36 #undef HAVE_SOCKETS
37
38 #else
39
40 #define HAVE_SOCKETS
41
42 #ifndef _XOPEN_SOURCE_EXTENDED
43 #define _XOPEN_SOURCE_EXTENDED 1
44 /* For HP-UX */
45 #endif
46
47 #ifndef BSD_COMP
48 #define BSD_COMP 1
49 /* For Solaris */
50 #endif
51
52 #ifndef _ALL_SOURCE
53 #define _ALL_SOURCE 1
54 /* For AIX */
55 #endif
56
57 #ifndef _OSF_SOURCE
58 #define _OSF_SOURCE 1
59 /* For Tru64 */
60 #endif
61
62 #include <limits.h>
63 #include <errno.h>
64
65 #if defined(__vxworks)
66 #include <vxWorks.h>
67 #include <ioLib.h>
68 #include <hostLib.h>
69 #ifndef __RTP__
70 #include <resolvLib.h>
71 #endif
72 #define SHUT_RD         0
73 #define SHUT_WR         1
74 #define SHUT_RDWR       2
75
76 #elif defined (WINNT)
77 #define FD_SETSIZE 1024
78 #include <windows.h>
79
80 #ifdef __MINGW32__
81 #include <winsock2.h>
82 #include <ws2tcpip.h>
83
84 #undef  EACCES
85 #define EACCES          WSAEACCES
86 #undef  EADDRINUSE
87 #define EADDRINUSE      WSAEADDRINUSE
88 #undef  EADDRNOTAVAIL
89 #define EADDRNOTAVAIL   WSAEADDRNOTAVAIL
90 #undef  EAFNOSUPPORT
91 #define EAFNOSUPPORT    WSAEAFNOSUPPORT
92 #undef  EALREADY
93 #define EALREADY        WSAEALREADY
94 #undef  EBADF
95 #define EBADF           WSAEBADF
96 #undef  ECONNABORTED
97 #define ECONNABORTED    WSAECONNABORTED
98 #undef  ECONNREFUSED
99 #define ECONNREFUSED    WSAECONNREFUSED
100 #undef  ECONNRESET
101 #define ECONNRESET      WSAECONNRESET
102 #undef  EDESTADDRREQ
103 #define EDESTADDRREQ    WSAEDESTADDRREQ
104 #undef  EFAULT
105 #define EFAULT          WSAEFAULT
106 #undef  EHOSTDOWN
107 #define EHOSTDOWN       WSAEHOSTDOWN
108 #undef  EHOSTUNREACH
109 #define EHOSTUNREACH    WSAEHOSTUNREACH
110 #undef  EINPROGRESS
111 #define EINPROGRESS     WSAEINPROGRESS
112 #undef  EINTR
113 #define EINTR           WSAEINTR
114 #undef  EINVAL
115 #define EINVAL          WSAEINVAL
116 #undef  EIO
117 #define EIO             WSAEDISCON
118 #undef  EISCONN
119 #define EISCONN         WSAEISCONN
120 #undef  ELOOP
121 #define ELOOP           WSAELOOP
122 #undef  EMFILE
123 #define EMFILE          WSAEMFILE
124 #undef  EMSGSIZE
125 #define EMSGSIZE        WSAEMSGSIZE
126 #undef  ENAMETOOLONG
127 #define ENAMETOOLONG    WSAENAMETOOLONG
128 #undef  ENETDOWN
129 #define ENETDOWN        WSAENETDOWN
130 #undef  ENETRESET
131 #define ENETRESET       WSAENETRESET
132 #undef  ENETUNREACH
133 #define ENETUNREACH     WSAENETUNREACH
134 #undef  ENOBUFS
135 #define ENOBUFS         WSAENOBUFS
136 #undef  ENOPROTOOPT
137 #define ENOPROTOOPT     WSAENOPROTOOPT
138 #undef  ENOTCONN
139 #define ENOTCONN        WSAENOTCONN
140 #undef  ENOTSOCK
141 #define ENOTSOCK        WSAENOTSOCK
142 #undef  EOPNOTSUPP
143 #define EOPNOTSUPP      WSAEOPNOTSUPP
144 #undef  EPFNOSUPPORT
145 #define EPFNOSUPPORT    WSAEPFNOSUPPORT
146 #undef  EPROTONOSUPPORT
147 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
148 #undef  EPROTOTYPE
149 #define EPROTOTYPE      WSAEPROTOTYPE
150 #undef  ESHUTDOWN
151 #define ESHUTDOWN       WSAESHUTDOWN
152 #undef  ESOCKTNOSUPPORT
153 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
154 #undef  ETIMEDOUT
155 #define ETIMEDOUT       WSAETIMEDOUT
156 #undef  ETOOMANYREFS
157 #define ETOOMANYREFS    WSAETOOMANYREFS
158 #undef  EWOULDBLOCK
159 #define EWOULDBLOCK     WSAEWOULDBLOCK
160
161 #define SHUT_RD         SD_RECEIVE
162 #define SHUT_WR         SD_SEND
163 #define SHUT_RDWR       SD_BOTH
164
165 #endif
166
167 #elif defined(VMS)
168 #define FD_SETSIZE 4096
169 #ifndef IN_RTS
170 /* These DEC C headers are not available when building with GCC */
171 #include <in.h>
172 #include <tcp.h>
173 #include <ioctl.h>
174 #include <netdb.h>
175 #endif
176
177 #endif
178
179 #ifdef __vxworks
180 #include <sys/times.h>
181 #else
182 #include <sys/time.h>
183 #endif
184
185 /*
186  * RTEMS has these .h files but not until you have built RTEMS.  When
187  * IN_RTS, you only have the .h files in the newlib C library.
188  * Because this file is also included from gen-soccon.c which is built
189  * to run on RTEMS (not IN_RTS), we must distinguish between IN_RTS
190  * and using this file to compile gen-soccon.
191  */
192 #if !(defined (VMS) || defined (__MINGW32__) || \
193       (defined(__rtems__) && defined(IN_RTS)))
194 #include <sys/socket.h>
195 #include <netinet/in.h>
196 #include <netinet/tcp.h>
197 #include <sys/ioctl.h>
198 #include <netdb.h>
199 #endif
200
201 /*
202  * Handling of gethostbyname, gethostbyaddr, getservbyname and getservbyport
203  * =========================================================================
204  *
205  * The default implementation of GNAT.Sockets.Thin requires that these
206  * operations be either thread safe, or that a reentrant version getXXXbyYYY_r
207  * be provided. In both cases, socket.c provides a __gnat_safe_getXXXbyYYY
208  * function with the same signature as getXXXbyYYY_r. If the operating
209  * system version of getXXXbyYYY is thread safe, the provided auxiliary
210  * buffer argument is unused and ignored.
211  *
212  * Target specific versions of GNAT.Sockets.Thin for platforms that can't
213  * fulfill these requirements must provide their own protection mechanism
214  * in Safe_GetXXXbyYYY, and if they require GNAT.Sockets to provide a buffer
215  * to this effect, then we need to set Need_Netdb_Buffer here (case of
216  * VxWorks and VMS).
217  */
218
219 #if defined (_AIX) || defined (__FreeBSD__) || defined (__hpux__) || defined (__osf__) || defined (_WIN32) || defined (__APPLE__)
220 # define HAVE_THREAD_SAFE_GETxxxBYyyy 1
221 #elif defined (sgi) || defined (linux) || defined (__GLIBC__) || (defined (sun) && defined (__SVR4) && !defined (__vxworks)) || defined(__rtems__)
222 # define HAVE_GETxxxBYyyy_R 1
223 #endif
224
225 #if defined (HAVE_GETxxxBYyyy_R) || !defined (HAVE_THREAD_SAFE_GETxxxBYyyy)
226 # define Need_Netdb_Buffer 1
227 #else
228 # define Need_Netdb_Buffer 0
229 #endif
230
231 #if defined (__FreeBSD__) || defined (__vxworks) || defined(__rtems__)
232 # define Has_Sockaddr_Len 1
233 #else
234 # define Has_Sockaddr_Len 0
235 #endif
236
237 #endif /* defined(__nucleus__) */