1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . S O C K E T S . T H I N --
10 -- Copyright (C) 2001 Ada Core Technologies, Inc. --
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. --
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. --
30 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 ------------------------------------------------------------------------------
34 -- This version is for NT.
36 package body GNAT
.Sockets
.Thin
is
40 WSAData_Dummy
: array (1 .. 512) of C
.int
;
42 WS_Version
: constant := 16#
0101#
;
43 Initialized
: Boolean := False;
50 (Item
: in out Fd_Set
;
54 for J
in 1 .. Item
.fd_count
loop
55 if Item
.fd_array
(J
) = Socket
then
56 Item
.fd_array
(J
.. Item
.fd_count
- 1) :=
57 Item
.fd_array
(J
+ 1 .. Item
.fd_count
);
58 Item
.fd_count
:= Item
.fd_count
- 1;
68 procedure Empty
(Item
: in out Fd_Set
) is
89 function Is_Empty
(Item
: Fd_Set
) return Boolean is
91 return Item
.fd_count
= 0;
98 function Is_Set
(Item
: Fd_Set
; Socket
: C
.int
) return Boolean is
100 for J
in 1 .. Item
.fd_count
loop
101 if Item
.fd_array
(J
) = Socket
then
113 procedure Initialize
(Process_Blocking_IO
: Boolean := False) is
114 Return_Value
: Interfaces
.C
.int
;
117 if not Initialized
then
118 Return_Value
:= WSAStartup
(WS_Version
, WSAData_Dummy
'Address);
119 pragma Assert
(Interfaces
.C
."=" (Return_Value
, 0));
128 function Max
(Item
: Fd_Set
) return C
.int
is
132 for J
in 1 .. Item
.fd_count
loop
133 if Item
.fd_array
(J
) > L
then
134 L
:= Item
.fd_array
(J
);
145 procedure Set
(Item
: in out Fd_Set
; Socket
: in C
.int
) is
147 Item
.fd_count
:= Item
.fd_count
+ 1;
148 Item
.fd_array
(Item
.fd_count
) := Socket
;
151 --------------------------
152 -- Socket_Error_Message --
153 --------------------------
155 function Socket_Error_Message
(Errno
: Integer) return String is
156 use GNAT
.Sockets
.Constants
;
161 return "Interrupted system call";
164 return "Bad file number";
167 return "Permission denied";
170 return "Bad address";
173 return "Invalid argument";
176 return "Too many open files";
179 return "Operation would block";
182 return "Operation now in progress. This error is "
183 & "returned if any Windows Sockets API "
184 & "function is called while a blocking "
185 & "function is in progress";
188 return "Operation already in progress";
191 return "Socket operation on nonsocket";
194 return "Destination address required";
197 return "Message too long";
200 return "Protocol wrong type for socket";
203 return "Protocol not available";
205 when EPROTONOSUPPORT
=>
206 return "Protocol not supported";
208 when ESOCKTNOSUPPORT
=>
209 return "Socket type not supported";
212 return "Operation not supported on socket";
215 return "Protocol family not supported";
218 return "Address family not supported by protocol family";
221 return "Address already in use";
223 when EADDRNOTAVAIL
=>
224 return "Cannot assign requested address";
227 return "Network is down. This error may be "
228 & "reported at any time if the Windows "
229 & "Sockets implementation detects an "
230 & "underlying failure";
233 return "Network is unreachable";
236 return "Network dropped connection on reset";
239 return "Software caused connection abort";
242 return "Connection reset by peer";
245 return "No buffer space available";
248 return "Socket is already connected";
251 return "Socket is not connected";
254 return "Cannot send after socket shutdown";
257 return "Too many references: cannot splice";
260 return "Connection timed out";
263 return "Connection refused";
266 return "Too many levels of symbolic links";
269 return "File name too long";
272 return "Host is down";
275 return "No route to host";
278 return "Returned by WSAStartup(), indicating that "
279 & "the network subsystem is unusable";
281 when VERNOTSUPPORTED
=>
282 return "Returned by WSAStartup(), indicating that "
283 & "the Windows Sockets DLL cannot support this application";
285 when NOTINITIALISED
=>
286 return "Winsock not initialized. This message is "
287 & "returned by any function except WSAStartup(), "
288 & "indicating that a successful WSAStartup() has "
289 & "not yet been performed";
294 when HOST_NOT_FOUND
=>
295 return "Host not found. This message indicates "
296 & "that the key (name, address, and so on) was not found";
299 return "Nonauthoritative host not found. This error may "
300 & "suggest that the name service itself is not functioning";
303 return "Nonrecoverable error. This error may suggest that the "
304 & "name service itself is not functioning";
307 return "Valid name, no data record of requested type. "
308 & "This error indicates that the key (name, address, "
309 & "and so on) was not found.";
312 return "Unknown system error";
315 end Socket_Error_Message
;
317 end GNAT
.Sockets
.Thin
;