* sh.h (REG_CLASS_FROM_LETTER): Change to:
[official-gcc.git] / gcc / ada / 3wsocthi.ads
blob63c8a5ea71574738617f34590d9d174f63d2e0aa
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 Ada Core Technologies, 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 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
30 -- --
31 ------------------------------------------------------------------------------
33 -- This version is for NT.
35 with Interfaces.C.Pointers;
36 with Interfaces.C.Strings;
38 with GNAT.Sockets.Constants;
40 with System;
42 package GNAT.Sockets.Thin is
44 -- ??? far more comments required ???
46 package C renames Interfaces.C;
48 use type C.int;
49 -- So that we can declare the Failure constant below.
51 Success : constant C.int := 0;
52 Failure : constant C.int := -1;
54 function Socket_Errno return Integer;
55 -- Returns last socket error number.
57 function Socket_Error_Message (Errno : Integer) return String;
58 -- Returns the error message string for the error number Errno. If
59 -- Errno is not known it returns "Unknown system error".
61 type Socket_Fd_Array is array (C.unsigned range 1 .. 64) of C.int;
62 pragma Convention (C, Socket_Fd_Array);
64 type Fd_Set is record
65 fd_count : C.unsigned;
66 fd_array : Socket_Fd_Array;
67 end record;
68 pragma Convention (C, Fd_Set);
70 Null_Fd_Set : constant Fd_Set := (0, (others => 0));
72 type Fd_Set_Access is access all Fd_Set;
73 pragma Convention (C, Fd_Set_Access);
75 type Timeval_Unit is new C.long;
76 pragma Convention (C, Timeval_Unit);
78 type Timeval is record
79 Tv_Sec : Timeval_Unit;
80 Tv_Usec : Timeval_Unit;
81 end record;
82 pragma Convention (C, Timeval);
84 type Timeval_Access is access all Timeval;
85 pragma Convention (C, Timeval_Access);
87 Immediat : constant Timeval := (0, 0);
89 type Int_Access is access all C.int;
90 pragma Convention (C, Int_Access);
91 -- Access to C integers
93 type Chars_Ptr_Array is array (C.size_t range <>) of
94 aliased C.Strings.chars_ptr;
96 package Chars_Ptr_Pointers is
97 new C.Pointers (C.size_t, C.Strings.chars_ptr, Chars_Ptr_Array,
98 C.Strings.Null_Ptr);
99 -- Arrays of C (char *)
101 type In_Addr is record
102 S_B1, S_B2, S_B3, S_B4 : C.unsigned_char;
103 end record;
104 pragma Convention (C, In_Addr);
105 -- Internet address
107 type In_Addr_Access is access all In_Addr;
108 pragma Convention (C, In_Addr_Access);
109 -- Access to internet address
111 Inaddr_Any : aliased constant In_Addr := (others => 0);
112 -- Any internet address (all the interfaces)
114 type In_Addr_Access_Array is array (C.size_t range <>)
115 of aliased In_Addr_Access;
116 pragma Convention (C, In_Addr_Access_Array);
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
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
128 type Sockaddr_Access is access all Sockaddr;
129 pragma Convention (C, Sockaddr_Access);
130 -- Access to socket address
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
141 type Sockaddr_In_Access is access all Sockaddr_In;
142 pragma Convention (C, Sockaddr_In_Access);
143 -- Access to internet socket address
145 type Hostent is record
146 H_Name : C.Strings.chars_ptr;
147 H_Aliases : Chars_Ptr_Pointers.Pointer;
148 H_Addrtype : C.short;
149 H_Length : C.short;
150 H_Addr_List : In_Addr_Access_Pointers.Pointer;
151 end record;
152 pragma Convention (C, Hostent);
153 -- Host entry
155 type Hostent_Access is access all Hostent;
156 pragma Convention (C, Hostent_Access);
157 -- Access to host entry
159 type Two_Int is array (0 .. 1) of C.int;
160 pragma Convention (C, Two_Int);
161 -- Used with pipe()
163 function C_Accept
164 (S : C.int;
165 Addr : System.Address;
166 Addrlen : access C.int)
167 return C.int;
169 function C_Bind
170 (S : C.int;
171 Name : System.Address;
172 Namelen : C.int)
173 return C.int;
175 function C_Close
176 (Fd : C.int)
177 return C.int;
179 function C_Connect
180 (S : C.int;
181 Name : System.Address;
182 Namelen : C.int)
183 return C.int;
185 function C_Gethostbyaddr
186 (Addr : System.Address;
187 Length : C.int;
188 Typ : C.int)
189 return Hostent_Access;
191 function C_Gethostbyname
192 (Name : C.char_array)
193 return Hostent_Access;
195 function C_Gethostname
196 (Name : System.Address;
197 Namelen : C.int)
198 return C.int;
200 function C_Getpeername
201 (S : C.int;
202 Name : System.Address;
203 Namelen : access C.int)
204 return C.int;
206 function C_Getsockname
207 (S : C.int;
208 Name : System.Address;
209 Namelen : access C.int)
210 return C.int;
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;
220 function C_Inet_Addr
221 (Cp : C.Strings.chars_ptr)
222 return C.int;
224 function C_Ioctl
225 (S : C.int;
226 Req : C.int;
227 Arg : Int_Access)
228 return C.int;
230 function C_Listen
231 (S, Backlog : C.int)
232 return C.int;
234 function C_Read
235 (Fildes : C.int;
236 Buf : System.Address;
237 Nbyte : C.int)
238 return C.int;
240 function C_Recv
241 (S : C.int;
242 Buf : System.Address;
243 Len : C.int;
244 Flags : C.int)
245 return C.int;
247 function C_Recvfrom
248 (S : C.int;
249 Buf : System.Address;
250 Len : C.int;
251 Flags : C.int;
252 From : Sockaddr_In_Access;
253 Fromlen : access C.int)
254 return C.int;
256 function C_Select
257 (Nfds : C.int;
258 Readfds : Fd_Set_Access;
259 Writefds : Fd_Set_Access;
260 Exceptfds : Fd_Set_Access;
261 Timeout : Timeval_Access)
262 return C.int;
264 function C_Send
265 (S : C.int;
266 Buf : System.Address;
267 Len : C.int;
268 Flags : C.int)
269 return C.int;
271 function C_Sendto
272 (S : C.int;
273 Msg : System.Address;
274 Len : C.int;
275 Flags : C.int;
276 To : Sockaddr_In_Access;
277 Tolen : C.int)
278 return C.int;
280 function C_Setsockopt
281 (S : C.int;
282 Level : C.int;
283 Optname : C.int;
284 Optval : System.Address;
285 Optlen : C.int)
286 return C.int;
288 function C_Shutdown
289 (S : C.int;
290 How : C.int)
291 return C.int;
293 function C_Socket
294 (Domain : C.int;
295 Typ : C.int;
296 Protocol : C.int)
297 return C.int;
299 function C_Strerror
300 (Errnum : C.int)
301 return C.Strings.chars_ptr;
303 function C_System
304 (Command : System.Address)
305 return C.int;
307 function C_Write
308 (Fildes : C.int;
309 Buf : System.Address;
310 Nbyte : C.int)
311 return C.int;
313 function WSAStartup
314 (WS_Version : Interfaces.C.int;
315 WSADataAddress : System.Address)
316 return Interfaces.C.int;
318 procedure WSACleanup;
320 procedure Clear (Item : in out Fd_Set; Socket : in C.int);
321 procedure Empty (Item : in out Fd_Set);
322 function Is_Empty (Item : Fd_Set) return Boolean;
323 function Is_Set (Item : Fd_Set; Socket : C.int) return Boolean;
324 function Max (Item : Fd_Set) return C.int;
325 procedure Set (Item : in out Fd_Set; Socket : in C.int);
327 procedure Finalize;
328 procedure Initialize (Process_Blocking_IO : Boolean := False);
330 private
332 pragma Import (Stdcall, C_Accept, "accept");
333 pragma Import (Stdcall, C_Bind, "bind");
334 pragma Import (Stdcall, C_Close, "closesocket");
335 pragma Import (Stdcall, C_Connect, "connect");
336 pragma Import (Stdcall, C_Gethostbyaddr, "gethostbyaddr");
337 pragma Import (Stdcall, C_Gethostbyname, "gethostbyname");
338 pragma Import (Stdcall, C_Gethostname, "gethostname");
339 pragma Import (Stdcall, C_Getpeername, "getpeername");
340 pragma Import (Stdcall, C_Getsockname, "getsockname");
341 pragma Import (Stdcall, C_Getsockopt, "getsockopt");
342 pragma Import (Stdcall, C_Inet_Addr, "inet_addr");
343 pragma Import (Stdcall, C_Ioctl, "ioctlsocket");
344 pragma Import (Stdcall, C_Listen, "listen");
345 pragma Import (C, C_Read, "_read");
346 pragma Import (Stdcall, C_Recv, "recv");
347 pragma Import (Stdcall, C_Recvfrom, "recvfrom");
348 pragma Import (Stdcall, C_Select, "select");
349 pragma Import (Stdcall, C_Send, "send");
350 pragma Import (Stdcall, C_Sendto, "sendto");
351 pragma Import (Stdcall, C_Setsockopt, "setsockopt");
352 pragma Import (Stdcall, C_Shutdown, "shutdown");
353 pragma Import (Stdcall, C_Socket, "socket");
354 pragma Import (C, C_Strerror, "strerror");
355 pragma Import (C, C_System, "_system");
356 pragma Import (C, C_Write, "_write");
357 pragma Import (Stdcall, Socket_Errno, "WSAGetLastError");
358 pragma Import (Stdcall, WSAStartup, "WSAStartup");
359 pragma Import (Stdcall, WSACleanup, "WSACleanup");
361 end GNAT.Sockets.Thin;