OSDN Git Service

2009-04-29 Gary Dismukes <dismukes@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-socthi.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                    G N A T . S O C K E T S . T H I N                     --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --                     Copyright (C) 2001-2009, AdaCore                     --
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 other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package provides a target dependent thin interface to the sockets
35 --  layer for use by the GNAT.Sockets package (g-socket.ads). This package
36 --  should not be directly with'ed by an applications program.
37
38 --  This is the default version
39
40 with Interfaces.C.Strings;
41
42 with GNAT.OS_Lib;
43 with GNAT.Sockets.Thin_Common;
44
45 with System;
46
47 package GNAT.Sockets.Thin is
48
49    --  This package is intended for hosts implementing BSD sockets with a
50    --  standard interface. It will be used as a default for all the platforms
51    --  that do not have a specific version of this file.
52
53    use Thin_Common;
54
55    package C renames Interfaces.C;
56
57    use type C.size_t;
58    type ssize_t is range -(2 ** (C.size_t'Size - 1))
59      .. +(2 ** (C.size_t'Size - 1) - 1);
60    --  Signed type of the same size as size_t
61
62    type Msghdr is record
63       Msg_Name       : System.Address;
64       Msg_Namelen    : C.unsigned;
65       Msg_Iov        : System.Address;
66       Msg_Iovlen     : C.size_t;
67       Msg_Control    : System.Address;
68       Msg_Controllen : C.size_t;
69       Msg_Flags      : C.int;
70    end record;
71    pragma Convention (C, Msghdr);
72
73    function Socket_Errno return Integer renames GNAT.OS_Lib.Errno;
74    --  Returns last socket error number
75
76    function Socket_Error_Message (Errno : Integer) return C.Strings.chars_ptr;
77    --  Returns the error message string for the error number Errno. If Errno is
78    --  not known, returns "Unknown system error".
79
80    function Host_Errno return Integer;
81    pragma Import (C, Host_Errno, "__gnat_get_h_errno");
82    --  Returns last host error number
83
84    package Host_Error_Messages is
85
86       function Host_Error_Message
87         (H_Errno : Integer) return C.Strings.chars_ptr;
88       --  Returns the error message string for the host error number H_Errno.
89       --  If H_Errno is not known, returns "Unknown system error".
90
91    end Host_Error_Messages;
92
93    --------------------------------
94    -- Standard library functions --
95    --------------------------------
96
97    function C_Accept
98      (S       : C.int;
99       Addr    : System.Address;
100       Addrlen : not null access C.int) return C.int;
101
102    function C_Bind
103      (S       : C.int;
104       Name    : System.Address;
105       Namelen : C.int) return C.int;
106
107    function C_Close
108      (Fd : C.int) return C.int;
109
110    function C_Connect
111      (S       : C.int;
112       Name    : System.Address;
113       Namelen : C.int) return C.int;
114
115    function C_Gethostname
116      (Name    : System.Address;
117       Namelen : C.int) return C.int;
118
119    function C_Getpeername
120      (S       : C.int;
121       Name    : System.Address;
122       Namelen : not null access C.int) return C.int;
123
124    function C_Getsockname
125      (S       : C.int;
126       Name    : System.Address;
127       Namelen : not null access C.int) return C.int;
128
129    function C_Getsockopt
130      (S       : C.int;
131       Level   : C.int;
132       Optname : C.int;
133       Optval  : System.Address;
134       Optlen  : not null access C.int) return C.int;
135
136    function C_Ioctl
137      (S    : C.int;
138       Req  : C.int;
139       Arg  : access C.int) return C.int;
140
141    function C_Listen
142      (S       : C.int;
143       Backlog : C.int) return C.int;
144
145    function C_Recv
146      (S     : C.int;
147       Msg   : System.Address;
148       Len   : C.int;
149       Flags : C.int) return C.int;
150
151    function C_Recvfrom
152      (S       : C.int;
153       Msg     : System.Address;
154       Len     : C.int;
155       Flags   : C.int;
156       From    : Sockaddr_In_Access;
157       Fromlen : not null access C.int) return C.int;
158
159    function C_Recvmsg
160      (S     : C.int;
161       Msg   : System.Address;
162       Flags : C.int) return ssize_t;
163
164    function C_Select
165      (Nfds      : C.int;
166       Readfds   : access Fd_Set;
167       Writefds  : access Fd_Set;
168       Exceptfds : access Fd_Set;
169       Timeout   : Timeval_Access) return C.int;
170
171    function C_Sendmsg
172      (S     : C.int;
173       Msg   : System.Address;
174       Flags : C.int) return ssize_t;
175
176    function C_Sendto
177      (S     : C.int;
178       Msg   : System.Address;
179       Len   : C.int;
180       Flags : C.int;
181       To    : Sockaddr_In_Access;
182       Tolen : C.int) return C.int;
183
184    function C_Setsockopt
185      (S       : C.int;
186       Level   : C.int;
187       Optname : C.int;
188       Optval  : System.Address;
189       Optlen  : C.int) return C.int;
190
191    function C_Shutdown
192      (S   : C.int;
193       How : C.int) return C.int;
194
195    function C_Socket
196      (Domain   : C.int;
197       Typ      : C.int;
198       Protocol : C.int) return C.int;
199
200    function C_Strerror
201      (Errnum : C.int) return C.Strings.chars_ptr;
202
203    function C_System
204      (Command : System.Address) return C.int;
205
206    -------------------------------------------------------
207    -- Signalling file descriptors for selector abortion --
208    -------------------------------------------------------
209
210    package Signalling_Fds is
211
212       function Create (Fds : not null access Fd_Pair) return C.int;
213       pragma Convention (C, Create);
214       --  Create a pair of connected descriptors suitable for use with C_Select
215       --  (used for signalling in Selector objects).
216
217       function Read (Rsig : C.int) return C.int;
218       pragma Convention (C, Read);
219       --  Read one byte of data from rsig, the read end of a pair of signalling
220       --  fds created by Create_Signalling_Fds.
221
222       function Write (Wsig : C.int) return C.int;
223       pragma Convention (C, Write);
224       --  Write one byte of data to wsig, the write end of a pair of signalling
225       --  fds created by Create_Signalling_Fds.
226
227       procedure Close (Sig : C.int);
228       pragma Convention (C, Close);
229       --  Close one end of a pair of signalling fds (ignoring any error)
230
231    end Signalling_Fds;
232
233    -------------------------------------------
234    -- Nonreentrant network databases access --
235    -------------------------------------------
236
237    --  The following are used only on systems that have nonreentrant
238    --  getXXXbyYYY functions, and do NOT have corresponding getXXXbyYYY_
239    --  functions. Currently, LynxOS is the only such system.
240
241    function Nonreentrant_Gethostbyname
242      (Name : C.char_array) return Hostent_Access;
243
244    function Nonreentrant_Gethostbyaddr
245      (Addr      : System.Address;
246       Addr_Len  : C.int;
247       Addr_Type : C.int) return Hostent_Access;
248
249    function Nonreentrant_Getservbyname
250      (Name  : C.char_array;
251       Proto : C.char_array) return Servent_Access;
252
253    function Nonreentrant_Getservbyport
254      (Port  : C.int;
255       Proto : C.char_array) return Servent_Access;
256
257    procedure Initialize;
258    procedure Finalize;
259
260 private
261    pragma Import (C, C_Bind, "bind");
262    pragma Import (C, C_Close, "close");
263    pragma Import (C, C_Gethostname, "gethostname");
264    pragma Import (C, C_Getpeername, "getpeername");
265    pragma Import (C, C_Getsockname, "getsockname");
266    pragma Import (C, C_Getsockopt, "getsockopt");
267    pragma Import (C, C_Listen, "listen");
268    pragma Import (C, C_Select, "select");
269    pragma Import (C, C_Setsockopt, "setsockopt");
270    pragma Import (C, C_Shutdown, "shutdown");
271    pragma Import (C, C_Strerror, "strerror");
272    pragma Import (C, C_System, "system");
273
274    pragma Import (C, Nonreentrant_Gethostbyname, "gethostbyname");
275    pragma Import (C, Nonreentrant_Gethostbyaddr, "gethostbyaddr");
276    pragma Import (C, Nonreentrant_Getservbyname, "getservbyname");
277    pragma Import (C, Nonreentrant_Getservbyport, "getservbyport");
278
279 end GNAT.Sockets.Thin;