OSDN Git Service

2010-12-09 Steven G. Kargl <kargl@gcc.gnu.org>
[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-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  ****************************************************************************/
31
32 #if defined(__nucleus__) || defined(VTHREADS)
33
34 #warning Sockets not supported on these platforms
35 #undef HAVE_SOCKETS
36
37 #else
38
39 #define HAVE_SOCKETS
40
41 #ifndef _XOPEN_SOURCE_EXTENDED
42 #define _XOPEN_SOURCE_EXTENDED 1
43 /* For HP-UX */
44 #endif
45
46 #ifndef BSD_COMP
47 #define BSD_COMP 1
48 /* For Solaris */
49 #endif
50
51 #ifndef _ALL_SOURCE
52 #define _ALL_SOURCE 1
53 /* For AIX */
54 #endif
55
56 #ifndef _OSF_SOURCE
57 #define _OSF_SOURCE 1
58 /* For Tru64 */
59 #endif
60
61 #include <limits.h>
62 #include <errno.h>
63
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
71
72 #elif defined (WINNT)
73 #define FD_SETSIZE 1024
74
75 #ifdef __MINGW32__
76 #include <winsock2.h>
77 #include <ws2tcpip.h>
78
79 #undef  EACCES
80 #define EACCES          WSAEACCES
81 #undef  EADDRINUSE
82 #define EADDRINUSE      WSAEADDRINUSE
83 #undef  EADDRNOTAVAIL
84 #define EADDRNOTAVAIL   WSAEADDRNOTAVAIL
85 #undef  EAFNOSUPPORT
86 #define EAFNOSUPPORT    WSAEAFNOSUPPORT
87 #undef  EALREADY
88 #define EALREADY        WSAEALREADY
89 #undef  EBADF
90 #define EBADF           WSAEBADF
91 #undef  ECONNABORTED
92 #define ECONNABORTED    WSAECONNABORTED
93 #undef  ECONNREFUSED
94 #define ECONNREFUSED    WSAECONNREFUSED
95 #undef  ECONNRESET
96 #define ECONNRESET      WSAECONNRESET
97 #undef  EDESTADDRREQ
98 #define EDESTADDRREQ    WSAEDESTADDRREQ
99 #undef  EFAULT
100 #define EFAULT          WSAEFAULT
101 #undef  EHOSTDOWN
102 #define EHOSTDOWN       WSAEHOSTDOWN
103 #undef  EHOSTUNREACH
104 #define EHOSTUNREACH    WSAEHOSTUNREACH
105 #undef  EINPROGRESS
106 #define EINPROGRESS     WSAEINPROGRESS
107 #undef  EINTR
108 #define EINTR           WSAEINTR
109 #undef  EINVAL
110 #define EINVAL          WSAEINVAL
111 #undef  EIO
112 #define EIO             WSAEDISCON
113 #undef  EISCONN
114 #define EISCONN         WSAEISCONN
115 #undef  ELOOP
116 #define ELOOP           WSAELOOP
117 #undef  EMFILE
118 #define EMFILE          WSAEMFILE
119 #undef  EMSGSIZE
120 #define EMSGSIZE        WSAEMSGSIZE
121 #undef  ENAMETOOLONG
122 #define ENAMETOOLONG    WSAENAMETOOLONG
123 #undef  ENETDOWN
124 #define ENETDOWN        WSAENETDOWN
125 #undef  ENETRESET
126 #define ENETRESET       WSAENETRESET
127 #undef  ENETUNREACH
128 #define ENETUNREACH     WSAENETUNREACH
129 #undef  ENOBUFS
130 #define ENOBUFS         WSAENOBUFS
131 #undef  ENOPROTOOPT
132 #define ENOPROTOOPT     WSAENOPROTOOPT
133 #undef  ENOTCONN
134 #define ENOTCONN        WSAENOTCONN
135 #undef  ENOTSOCK
136 #define ENOTSOCK        WSAENOTSOCK
137 #undef  EOPNOTSUPP
138 #define EOPNOTSUPP      WSAEOPNOTSUPP
139 #undef  EPFNOSUPPORT
140 #define EPFNOSUPPORT    WSAEPFNOSUPPORT
141 #undef  EPROTONOSUPPORT
142 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
143 #undef  EPROTOTYPE
144 #define EPROTOTYPE      WSAEPROTOTYPE
145 #undef  ESHUTDOWN
146 #define ESHUTDOWN       WSAESHUTDOWN
147 #undef  ESOCKTNOSUPPORT
148 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
149 #undef  ETIMEDOUT
150 #define ETIMEDOUT       WSAETIMEDOUT
151 #undef  ETOOMANYREFS
152 #define ETOOMANYREFS    WSAETOOMANYREFS
153 #undef  EWOULDBLOCK
154 #define EWOULDBLOCK     WSAEWOULDBLOCK
155
156 #define SHUT_RD         SD_RECEIVE
157 #define SHUT_WR         SD_SEND
158 #define SHUT_RDWR       SD_BOTH
159
160 #endif
161
162 #include <windows.h>
163
164 #elif defined(VMS)
165 #define FD_SETSIZE 4096
166 #ifndef IN_RTS
167 /* These DEC C headers are not available when building with GCC */
168 #include <in.h>
169 #include <tcp.h>
170 #include <ioctl.h>
171 #include <netdb.h>
172 #endif
173
174 #endif
175
176 #if defined (__vxworks) && ! defined (__RTP__)
177 #include <sys/times.h>
178 #else
179 #include <sys/time.h>
180 #endif
181
182 /*
183  * RTEMS has these .h files but not until you have built and installed
184  * RTEMS. When building a C/C++ toolset, you also build the newlib C library.
185  * So the build procedure for an RTEMS GNAT toolset requires that
186  * you build a C/C++ toolset, then build and install RTEMS with 
187  * --enable-multilib, and finally build the Ada part of the toolset.
188  */
189 #if !(defined (VMS) || defined (__MINGW32__))
190 #include <sys/socket.h>
191 #include <netinet/in.h>
192 #include <netinet/tcp.h>
193 #include <sys/ioctl.h>
194 #include <netdb.h>
195 #endif
196
197 #if defined (_AIX) || defined (__FreeBSD__) || defined (__hpux__) || \
198     defined (__osf__) || defined (_WIN32) || defined (__APPLE__)
199 # define HAVE_THREAD_SAFE_GETxxxBYyyy 1
200
201 #elif defined (sgi) || defined (linux) || defined (__GLIBC__) || \
202      (defined (sun) && defined (__SVR4) && !defined (__vxworks)) || \
203       defined(__rtems__)
204 # define HAVE_GETxxxBYyyy_R 1
205 #endif
206
207 /*
208  * Properties of the unerlying NetDB library:
209  *   Need_Netdb_Buffer __gnat_getXXXbyYYY expects a caller-supplied buffer
210  *   Need_Netdb_Lock   __gnat_getXXXbyYYY expects the caller to ensure
211  *                     mutual exclusion
212  *
213  * See "Handling of gethostbyname, gethostbyaddr, getservbyname and
214  * getservbyport" in socket.c for details.
215  */
216
217 #if defined (HAVE_GETxxxBYyyy_R)
218 # define Need_Netdb_Buffer 1
219 # define Need_Netdb_Lock 0
220
221 #else
222 # define Need_Netdb_Buffer 0
223 # if !defined (HAVE_THREAD_SAFE_GETxxxBYyyy)
224 #  define Need_Netdb_Lock 1
225 # else
226 #  define Need_Netdb_Lock 0
227 # endif
228 #endif
229
230 #if defined (__FreeBSD__) || defined (__vxworks) || defined(__rtems__)
231 # define Has_Sockaddr_Len 1
232 #else
233 # define Has_Sockaddr_Len 0
234 #endif
235
236 #if !(defined (__vxworks) || defined (_WIN32) || defined (__hpux__) || defined (VMS))
237 # define HAVE_INET_PTON
238 #endif
239
240 #endif /* defined(__nucleus__) */