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