* gcc.c (getenv_spec_function): New function.
[official-gcc.git] / gcc / ada / g-socthi-vxworks.ads
blob6aee25d4ef4640a1aa6d2efce263e5611b15e5f7
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) 2002-2005, 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 ------------------------------------------------------------------------------
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.
38 -- This is the version for VxWorks
40 with Interfaces.C.Pointers;
42 with Ada.Unchecked_Conversion;
43 with Interfaces.C.Strings;
44 with GNAT.Sockets.Constants;
45 with GNAT.OS_Lib;
47 with System;
49 package GNAT.Sockets.Thin is
51 package C renames Interfaces.C;
53 use type C.int;
54 -- This is so we can declare the Failure constant below
56 Success : constant C.int := 0;
57 Failure : constant C.int := -1;
59 function Socket_Errno return Integer renames GNAT.OS_Lib.Errno;
60 -- Returns last socket error number
62 function Socket_Error_Message (Errno : Integer) return C.Strings.chars_ptr;
63 -- Returns the error message string for the error number Errno. If Errno is
64 -- not known it returns "Unknown system error".
66 function Host_Errno return Integer;
67 pragma Import (C, Host_Errno, "__gnat_get_h_errno");
68 -- Returns last host error number
70 subtype Fd_Set_Access is System.Address;
71 No_Fd_Set : constant Fd_Set_Access := System.Null_Address;
73 type time_t is
74 range -2 ** (8 * Constants.SIZEOF_tv_sec - 1)
75 .. 2 ** (8 * Constants.SIZEOF_tv_sec - 1) - 1;
76 for time_t'Size use 8 * Constants.SIZEOF_tv_sec;
77 pragma Convention (C, time_t);
79 type suseconds_t is
80 range -2 ** (8 * Constants.SIZEOF_tv_usec - 1)
81 .. 2 ** (8 * Constants.SIZEOF_tv_usec - 1) - 1;
82 for suseconds_t'Size use 8 * Constants.SIZEOF_tv_usec;
83 pragma Convention (C, suseconds_t);
85 type Timeval is record
86 Tv_Sec : time_t;
87 Tv_Usec : suseconds_t;
88 end record;
89 pragma Convention (C, Timeval);
91 type Timeval_Access is access all Timeval;
92 pragma Convention (C, Timeval_Access);
94 Immediat : constant Timeval := (0, 0);
96 type Int_Access is access all C.int;
97 pragma Convention (C, Int_Access);
98 -- Access to C integers
100 type Chars_Ptr_Array is array (C.size_t range <>) of
101 aliased C.Strings.chars_ptr;
103 package Chars_Ptr_Pointers is
104 new C.Pointers (C.size_t, C.Strings.chars_ptr, Chars_Ptr_Array,
105 C.Strings.Null_Ptr);
106 -- Arrays of C (char *)
108 type In_Addr is record
109 S_B1, S_B2, S_B3, S_B4 : C.unsigned_char;
110 end record;
111 pragma Convention (C, In_Addr);
112 -- Internet address
114 function To_In_Addr is new Ada.Unchecked_Conversion (C.int, In_Addr);
116 type In_Addr_Access is access all In_Addr;
117 pragma Convention (C, In_Addr_Access);
118 -- Access to internet address
120 Inaddr_Any : aliased constant In_Addr := (others => 0);
121 -- Any internet address (all the interfaces)
123 type In_Addr_Access_Array is array (C.size_t range <>)
124 of aliased In_Addr_Access;
125 pragma Convention (C, In_Addr_Access_Array);
127 package In_Addr_Access_Pointers is
128 new C.Pointers (C.size_t, In_Addr_Access, In_Addr_Access_Array, null);
129 -- Array of internet addresses
131 type Sockaddr is record
132 Sa_Length : C.unsigned_char;
133 Sa_Family : C.unsigned_char;
134 Sa_Data : C.char_array (1 .. 14);
135 end record;
136 pragma Convention (C, Sockaddr);
137 -- Socket address
139 type Sockaddr_Access is access all Sockaddr;
140 pragma Convention (C, Sockaddr_Access);
141 -- Access to socket address
143 type Sockaddr_In is record
144 Sin_Length : C.unsigned_char := 0;
145 Sin_Family : C.unsigned_char := Constants.AF_INET;
146 Sin_Port : C.unsigned_short := 0;
147 Sin_Addr : In_Addr := Inaddr_Any;
148 Sin_Zero : C.char_array (1 .. 8) := (others => C.char'Val (0));
149 end record;
150 pragma Convention (C, Sockaddr_In);
151 -- Internet socket address
153 type Sockaddr_In_Access is access all Sockaddr_In;
154 pragma Convention (C, Sockaddr_In_Access);
155 -- Access to internet socket address
157 procedure Set_Length
158 (Sin : Sockaddr_In_Access;
159 Len : C.int);
160 pragma Inline (Set_Length);
161 -- Set Sin.Sin_Length to Len
163 procedure Set_Family
164 (Sin : Sockaddr_In_Access;
165 Family : C.int);
166 pragma Inline (Set_Family);
167 -- Set Sin.Sin_Family to Family
169 procedure Set_Port
170 (Sin : Sockaddr_In_Access;
171 Port : C.unsigned_short);
172 pragma Inline (Set_Port);
173 -- Set Sin.Sin_Port to Port
175 procedure Set_Address
176 (Sin : Sockaddr_In_Access;
177 Address : In_Addr);
178 pragma Inline (Set_Address);
179 -- Set Sin.Sin_Addr to Address
181 type Hostent is record
182 H_Name : C.Strings.chars_ptr;
183 H_Aliases : Chars_Ptr_Pointers.Pointer;
184 H_Addrtype : C.int;
185 H_Length : C.int;
186 H_Addr_List : In_Addr_Access_Pointers.Pointer;
187 end record;
188 pragma Convention (C, Hostent);
189 -- Host entry
191 type Hostent_Access is access all Hostent;
192 pragma Convention (C, Hostent_Access);
193 -- Access to host entry
195 type Servent is record
196 S_Name : C.Strings.chars_ptr;
197 S_Aliases : Chars_Ptr_Pointers.Pointer;
198 S_Port : C.int;
199 S_Proto : C.Strings.chars_ptr;
200 end record;
201 pragma Convention (C, Servent);
202 -- Service entry
204 type Servent_Access is access all Servent;
205 pragma Convention (C, Servent_Access);
206 -- Access to service entry
208 type Two_Int is array (0 .. 1) of C.int;
209 pragma Convention (C, Two_Int);
210 -- Used with pipe()
212 function C_Accept
213 (S : C.int;
214 Addr : System.Address;
215 Addrlen : access C.int) return C.int;
217 function C_Bind
218 (S : C.int;
219 Name : System.Address;
220 Namelen : C.int) return C.int;
222 function C_Close
223 (Fd : C.int) return C.int;
225 function C_Connect
226 (S : C.int;
227 Name : System.Address;
228 Namelen : C.int) return C.int;
230 function C_Gethostbyaddr
231 (Addr : System.Address;
232 Len : C.int;
233 Typ : C.int) return Hostent_Access;
235 function C_Gethostbyname
236 (Name : C.char_array) return Hostent_Access;
238 function C_Gethostname
239 (Name : System.Address;
240 Namelen : C.int) return C.int;
242 function C_Getpeername
243 (S : C.int;
244 Name : System.Address;
245 Namelen : access C.int) return C.int;
247 function C_Getservbyname
248 (Name : C.char_array;
249 Proto : C.char_array) return Servent_Access;
251 function C_Getservbyport
252 (Port : C.int;
253 Proto : C.char_array) return Servent_Access;
255 function C_Getsockname
256 (S : C.int;
257 Name : System.Address;
258 Namelen : access C.int) return C.int;
260 function C_Getsockopt
261 (S : C.int;
262 Level : C.int;
263 Optname : C.int;
264 Optval : System.Address;
265 Optlen : access C.int) return C.int;
267 function C_Inet_Addr
268 (Cp : C.Strings.chars_ptr) return C.int;
270 function C_Ioctl
271 (S : C.int;
272 Req : C.int;
273 Arg : Int_Access) return C.int;
275 function C_Listen (S, Backlog : C.int) return C.int;
277 function C_Readv
278 (Fd : C.int;
279 Iov : System.Address;
280 Iovcnt : C.int) return C.int;
282 function C_Recv
283 (S : C.int;
284 Msg : System.Address;
285 Len : C.int;
286 Flags : C.int) return C.int;
288 function C_Recvfrom
289 (S : C.int;
290 Msg : System.Address;
291 Len : C.int;
292 Flags : C.int;
293 From : Sockaddr_In_Access;
294 Fromlen : access C.int) return C.int;
296 function C_Select
297 (Nfds : C.int;
298 Readfds : Fd_Set_Access;
299 Writefds : Fd_Set_Access;
300 Exceptfds : Fd_Set_Access;
301 Timeout : Timeval_Access) return C.int;
303 function C_Send
304 (S : C.int;
305 Msg : System.Address;
306 Len : C.int;
307 Flags : C.int) return C.int;
309 function C_Sendto
310 (S : C.int;
311 Msg : System.Address;
312 Len : C.int;
313 Flags : C.int;
314 To : Sockaddr_In_Access;
315 Tolen : C.int) return C.int;
317 function C_Setsockopt
318 (S : C.int;
319 Level : C.int;
320 Optname : C.int;
321 Optval : System.Address;
322 Optlen : C.int) return C.int;
324 function C_Shutdown
325 (S : C.int;
326 How : C.int) return C.int;
328 function C_Socket
329 (Domain : C.int;
330 Typ : C.int;
331 Protocol : C.int) return C.int;
333 function C_Strerror
334 (Errnum : C.int) return C.Strings.chars_ptr;
336 function C_System
337 (Command : System.Address) return C.int;
339 function C_Writev
340 (Fd : C.int;
341 Iov : System.Address;
342 Iovcnt : C.int) return C.int;
344 procedure Free_Socket_Set
345 (Set : Fd_Set_Access);
346 -- Free system-dependent socket set
348 procedure Get_Socket_From_Set
349 (Set : Fd_Set_Access;
350 Socket : Int_Access;
351 Last : Int_Access);
352 -- Get last socket in Socket and remove it from the socket
353 -- set. The parameter Last is a maximum value of the largest
354 -- socket. This hint is used to avoid scanning very large socket
355 -- sets. After a call to Get_Socket_From_Set, Last is set back to
356 -- the real largest socket in the socket set.
358 procedure Insert_Socket_In_Set
359 (Set : Fd_Set_Access;
360 Socket : C.int);
361 -- Insert socket in the socket set
363 function Is_Socket_In_Set
364 (Set : Fd_Set_Access;
365 Socket : C.int) return C.int;
366 -- Check whether Socket is in the socket set, return a non-zero
367 -- value if it is, zero if it is not.
369 procedure Last_Socket_In_Set
370 (Set : Fd_Set_Access;
371 Last : Int_Access);
372 -- Find the largest socket in the socket set. This is needed for
373 -- select(). When Last_Socket_In_Set is called, parameter Last is
374 -- a maximum value of the largest socket. This hint is used to
375 -- avoid scanning very large socket sets. After the call, Last is
376 -- set back to the real largest socket in the socket set.
378 function New_Socket_Set
379 (Set : Fd_Set_Access) return Fd_Set_Access;
380 -- Allocate a new socket set which is a system-dependent structure
381 -- and initialize by copying Set if it is non-null, by making it
382 -- empty otherwise.
384 procedure Remove_Socket_From_Set
385 (Set : Fd_Set_Access;
386 Socket : C.int);
387 -- Remove socket from the socket set
389 procedure Finalize;
390 procedure Initialize (Process_Blocking_IO : Boolean);
392 private
394 pragma Import (C, C_Bind, "bind");
395 pragma Import (C, C_Close, "close");
396 pragma Import (C, C_Gethostname, "gethostname");
397 pragma Import (C, C_Getpeername, "getpeername");
398 pragma Import (C, C_Getsockname, "getsockname");
399 pragma Import (C, C_Getsockopt, "getsockopt");
400 pragma Import (C, C_Inet_Addr, "inet_addr");
401 pragma Import (C, C_Listen, "listen");
402 pragma Import (C, C_Readv, "readv");
403 pragma Import (C, C_Select, "select");
404 pragma Import (C, C_Setsockopt, "setsockopt");
405 pragma Import (C, C_Shutdown, "shutdown");
406 pragma Import (C, C_Strerror, "strerror");
407 pragma Import (C, C_System, "system");
408 pragma Import (C, C_Writev, "writev");
410 pragma Import (C, Free_Socket_Set, "__gnat_free_socket_set");
411 pragma Import (C, Get_Socket_From_Set, "__gnat_get_socket_from_set");
412 pragma Import (C, Is_Socket_In_Set, "__gnat_is_socket_in_set");
413 pragma Import (C, Last_Socket_In_Set, "__gnat_last_socket_in_set");
414 pragma Import (C, New_Socket_Set, "__gnat_new_socket_set");
415 pragma Import (C, Insert_Socket_In_Set, "__gnat_insert_socket_in_set");
416 pragma Import (C, Remove_Socket_From_Set, "__gnat_remove_socket_from_set");
418 end GNAT.Sockets.Thin;