OSDN Git Service

* 41intnam.ads, 42intnam.ads, 4aintnam.ads, 4cintnam.ads,
[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 --                            $Revision: 1.12 $
10 --                                                                          --
11 --              Copyright (C) 2001 Ada Core Technologies, Inc.              --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- As a special exception,  if other files  instantiate  generics from this --
25 -- unit, or you link  this unit with other files  to produce an executable, --
26 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
27 -- covered  by the  GNU  General  Public  License.  This exception does not --
28 -- however invalidate  any other reasons why  the executable file  might be --
29 -- covered by the  GNU Public License.                                      --
30 --                                                                          --
31 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com).   --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 with Interfaces.C.Pointers;
36
37 with Interfaces.C.Strings;
38 with GNAT.Sockets.Constants;
39 with GNAT.OS_Lib;
40
41 with System;
42
43 package GNAT.Sockets.Thin is
44
45    --  ??? more comments needed ???
46
47    --  This package is intended for hosts implementing BSD sockets with a
48    --  standard interface. It will be used as a default for all the platforms
49    --  that do not have a specific version of this file.
50
51    package C renames Interfaces.C;
52
53    use type C.int;
54    --  This is so we can declare the Failure constant below
55
56    Success : constant C.int :=  0;
57    Failure : constant C.int := -1;
58
59    function Socket_Errno return Integer renames GNAT.OS_Lib.Errno;
60    --  Returns last socket error number.
61
62    function Socket_Error_Message (Errno : Integer) return String;
63    --  Returns the error message string for the error number Errno. If
64    --  Errno is not known it returns "Unknown system error".
65
66    type Fd_Set is mod 2 ** 32;
67    pragma Convention (C, Fd_Set);
68
69    Null_Fd_Set : constant Fd_Set := 0;
70
71    type Fd_Set_Access is access all Fd_Set;
72    pragma Convention (C, Fd_Set_Access);
73
74    type Timeval_Unit is new C.int;
75    pragma Convention (C, Timeval_Unit);
76
77    type Timeval is record
78       Tv_Sec  : Timeval_Unit;
79       Tv_Usec : Timeval_Unit;
80    end record;
81    pragma Convention (C, Timeval);
82
83    type Timeval_Access is access all Timeval;
84    pragma Convention (C, Timeval_Access);
85
86    Immediat : constant Timeval := (0, 0);
87
88    type Int_Access is access all C.int;
89    pragma Convention (C, Int_Access);
90    --  Access to C integers
91
92    type Chars_Ptr_Array is array (C.size_t range <>) of
93      aliased C.Strings.chars_ptr;
94
95    package Chars_Ptr_Pointers is
96       new C.Pointers (C.size_t, C.Strings.chars_ptr, Chars_Ptr_Array,
97                       C.Strings.Null_Ptr);
98    --  Arrays of C (char *)
99
100    type In_Addr is record
101       S_B1, S_B2, S_B3, S_B4 : C.unsigned_char;
102    end record;
103    pragma Convention (C, In_Addr);
104    --  Internet address
105
106    type In_Addr_Access is access all In_Addr;
107    pragma Convention (C, In_Addr_Access);
108    --  Access to internet address
109
110    Inaddr_Any : aliased constant In_Addr := (others => 0);
111    --  Any internet address (all the interfaces)
112
113    type In_Addr_Access_Array is array (C.size_t range <>)
114      of aliased In_Addr_Access;
115    pragma Convention (C, In_Addr_Access_Array);
116
117    package In_Addr_Access_Pointers is
118      new C.Pointers (C.size_t, In_Addr_Access, In_Addr_Access_Array, null);
119    --  Array of internet addresses
120
121    type Sockaddr is record
122       Sa_Family : C.unsigned_short;
123       Sa_Data   : C.char_array (1 .. 14);
124    end record;
125    pragma Convention (C, Sockaddr);
126    --  Socket address
127
128    type Sockaddr_Access is access all Sockaddr;
129    pragma Convention (C, Sockaddr_Access);
130    --  Access to socket address
131
132    type Sockaddr_In is record
133       Sin_Family : C.unsigned_short      := Constants.AF_INET;
134       Sin_Port   : C.unsigned_short      := 0;
135       Sin_Addr   : In_Addr               := Inaddr_Any;
136       Sin_Zero   : C.char_array (1 .. 8) := (others => C.char'Val (0));
137    end record;
138    pragma Convention (C, Sockaddr_In);
139    --  Internet socket address
140
141    type Sockaddr_In_Access is access all Sockaddr_In;
142    pragma Convention (C, Sockaddr_In_Access);
143    --  Access to internet socket address
144
145    type Hostent is record
146       H_Name      : C.Strings.chars_ptr;
147       H_Aliases   : Chars_Ptr_Pointers.Pointer;
148       H_Addrtype  : C.int;
149       H_Length    : C.int;
150       H_Addr_List : In_Addr_Access_Pointers.Pointer;
151    end record;
152    pragma Convention (C, Hostent);
153    --  Host entry
154
155    type Hostent_Access is access all Hostent;
156    pragma Convention (C, Hostent_Access);
157    --  Access to host entry
158
159    type Two_Int is array (0 .. 1) of C.int;
160    pragma Convention (C, Two_Int);
161    --  Used with pipe()
162
163    function C_Accept
164      (S       : C.int;
165       Addr    : System.Address;
166       Addrlen : access C.int)
167       return    C.int;
168
169    function C_Bind
170      (S       : C.int;
171       Name    : System.Address;
172       Namelen : C.int)
173       return    C.int;
174
175    function C_Close
176      (Fd   : C.int)
177       return C.int;
178
179    function C_Connect
180      (S       : C.int;
181       Name    : System.Address;
182       Namelen : C.int)
183       return    C.int;
184
185    function C_Gethostbyaddr
186      (Addr : System.Address;
187       Len  : C.int;
188       Typ  : C.int)
189       return Hostent_Access;
190
191    function C_Gethostbyname
192      (Name : C.char_array)
193       return Hostent_Access;
194
195    function C_Gethostname
196      (Name    : System.Address;
197       Namelen : C.int)
198       return    C.int;
199
200    function C_Getpeername
201      (S       : C.int;
202       Name    : System.Address;
203       Namelen : access C.int)
204       return    C.int;
205
206    function C_Getsockname
207      (S       : C.int;
208       Name    : System.Address;
209       Namelen : access C.int)
210       return    C.int;
211
212    function C_Getsockopt
213      (S       : C.int;
214       Level   : C.int;
215       Optname : C.int;
216       Optval  : System.Address;
217       Optlen  : access C.int)
218       return    C.int;
219
220    function C_Inet_Addr
221      (Cp   : C.Strings.chars_ptr)
222       return C.int;
223
224    function C_Ioctl
225      (S    : C.int;
226       Req  : C.int;
227       Arg  : Int_Access)
228       return C.int;
229
230    function C_Listen (S, Backlog : C.int) return C.int;
231
232    function C_Read
233      (Fd    : C.int;
234       Buf   : System.Address;
235       Count : C.int)
236       return  C.int;
237
238    function C_Recv
239      (S     : C.int;
240       Msg   : System.Address;
241       Len   : C.int;
242       Flags : C.int)
243       return  C.int;
244
245    function C_Recvfrom
246      (S       : C.int;
247       Msg     : System.Address;
248       Len     : C.int;
249       Flags   : C.int;
250       From    : Sockaddr_In_Access;
251       Fromlen : access C.int)
252       return    C.int;
253
254    function C_Select
255      (Nfds      : C.int;
256       Readfds   : Fd_Set_Access;
257       Writefds  : Fd_Set_Access;
258       Exceptfds : Fd_Set_Access;
259       Timeout   : Timeval_Access)
260       return      C.int;
261
262    function C_Send
263      (S     : C.int;
264       Msg   : System.Address;
265       Len   : C.int;
266       Flags : C.int)
267       return  C.int;
268
269    function C_Sendto
270      (S     : C.int;
271       Msg   : System.Address;
272       Len   : C.int;
273       Flags : C.int;
274       To    : Sockaddr_In_Access;
275       Tolen : C.int)
276       return  C.int;
277
278    function C_Setsockopt
279      (S       : C.int;
280       Level   : C.int;
281       Optname : C.int;
282       Optval  : System.Address;
283       Optlen  : C.int)
284       return    C.int;
285
286    function C_Shutdown
287      (S    : C.int;
288       How  : C.int)
289       return C.int;
290
291    function C_Socket
292      (Domain   : C.int;
293       Typ      : C.int;
294       Protocol : C.int)
295       return     C.int;
296
297    function C_Strerror
298      (Errnum : C.int)
299       return   C.Strings.chars_ptr;
300
301    function C_System
302      (Command : System.Address)
303       return    C.int;
304
305    function C_Write
306      (Fd    : C.int;
307       Buf   : System.Address;
308       Count : C.int)
309       return  C.int;
310
311    --  Return highest numbered socket (what does this refer to???)
312
313    procedure Clear    (Item : in out Fd_Set; Socket : in C.int);
314    procedure Empty    (Item : in out Fd_Set);
315    function  Is_Empty (Item : Fd_Set) return Boolean;
316    function  Is_Set   (Item : Fd_Set; Socket : C.int) return Boolean;
317    function  Max      (Item : Fd_Set) return C.int;
318    procedure Set      (Item : in out Fd_Set; Socket : in C.int);
319
320    procedure Finalize;
321    procedure Initialize (Process_Blocking_IO : Boolean);
322
323 private
324
325    pragma Import (C, C_Bind, "bind");
326    pragma Import (C, C_Close, "close");
327    pragma Import (C, C_Gethostbyaddr, "gethostbyaddr");
328    pragma Import (C, C_Gethostbyname, "gethostbyname");
329    pragma Import (C, C_Gethostname, "gethostname");
330    pragma Import (C, C_Getpeername, "getpeername");
331    pragma Import (C, C_Getsockname, "getsockname");
332    pragma Import (C, C_Getsockopt, "getsockopt");
333    pragma Import (C, C_Inet_Addr, "inet_addr");
334    pragma Import (C, C_Listen, "listen");
335    pragma Import (C, C_Read, "read");
336    pragma Import (C, C_Select, "select");
337    pragma Import (C, C_Setsockopt, "setsockopt");
338    pragma Import (C, C_Shutdown, "shutdown");
339    pragma Import (C, C_Strerror, "strerror");
340    pragma Import (C, C_System, "system");
341    pragma Import (C, C_Write, "write");
342
343 end GNAT.Sockets.Thin;