1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . S O C K E T S . T H I N --
11 -- Copyright (C) 2001 Ada Core Technologies, Inc. --
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. --
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. --
31 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
35 -- This version is for NT.
37 package body GNAT
.Sockets
.Thin
is
41 WSAData_Dummy
: array (1 .. 512) of C
.int
;
43 WS_Version
: constant := 16#
0101#
;
44 Initialized
: Boolean := False;
51 (Item
: in out Fd_Set
;
55 for J
in 1 .. Item
.fd_count
loop
56 if Item
.fd_array
(J
) = Socket
then
57 Item
.fd_array
(J
.. Item
.fd_count
- 1) :=
58 Item
.fd_array
(J
+ 1 .. Item
.fd_count
);
59 Item
.fd_count
:= Item
.fd_count
- 1;
69 procedure Empty
(Item
: in out Fd_Set
) is
90 function Is_Empty
(Item
: Fd_Set
) return Boolean is
92 return Item
.fd_count
= 0;
99 function Is_Set
(Item
: Fd_Set
; Socket
: C
.int
) return Boolean is
101 for J
in 1 .. Item
.fd_count
loop
102 if Item
.fd_array
(J
) = Socket
then
114 procedure Initialize
(Process_Blocking_IO
: Boolean := False) is
115 Return_Value
: Interfaces
.C
.int
;
118 if not Initialized
then
119 Return_Value
:= WSAStartup
(WS_Version
, WSAData_Dummy
'Address);
120 pragma Assert
(Interfaces
.C
."=" (Return_Value
, 0));
129 function Max
(Item
: Fd_Set
) return C
.int
is
133 for J
in 1 .. Item
.fd_count
loop
134 if Item
.fd_array
(J
) > L
then
135 L
:= Item
.fd_array
(J
);
146 procedure Set
(Item
: in out Fd_Set
; Socket
: in C
.int
) is
148 Item
.fd_count
:= Item
.fd_count
+ 1;
149 Item
.fd_array
(Item
.fd_count
) := Socket
;
152 --------------------------
153 -- Socket_Error_Message --
154 --------------------------
156 function Socket_Error_Message
(Errno
: Integer) return String is
157 use GNAT
.Sockets
.Constants
;
162 return "Interrupted system call";
165 return "Bad file number";
168 return "Permission denied";
171 return "Bad address";
174 return "Invalid argument";
177 return "Too many open files";
180 return "Operation would block";
183 return "Operation now in progress. This error is "
184 & "returned if any Windows Sockets API "
185 & "function is called while a blocking "
186 & "function is in progress";
189 return "Operation already in progress";
192 return "Socket operation on nonsocket";
195 return "Destination address required";
198 return "Message too long";
201 return "Protocol wrong type for socket";
204 return "Protocol not available";
206 when EPROTONOSUPPORT
=>
207 return "Protocol not supported";
209 when ESOCKTNOSUPPORT
=>
210 return "Socket type not supported";
213 return "Operation not supported on socket";
216 return "Protocol family not supported";
219 return "Address family not supported by protocol family";
222 return "Address already in use";
224 when EADDRNOTAVAIL
=>
225 return "Cannot assign requested address";
228 return "Network is down. This error may be "
229 & "reported at any time if the Windows "
230 & "Sockets implementation detects an "
231 & "underlying failure";
234 return "Network is unreachable";
237 return "Network dropped connection on reset";
240 return "Software caused connection abort";
243 return "Connection reset by peer";
246 return "No buffer space available";
249 return "Socket is already connected";
252 return "Socket is not connected";
255 return "Cannot send after socket shutdown";
258 return "Too many references: cannot splice";
261 return "Connection timed out";
264 return "Connection refused";
267 return "Too many levels of symbolic links";
270 return "File name too long";
273 return "Host is down";
276 return "No route to host";
279 return "Returned by WSAStartup(), indicating that "
280 & "the network subsystem is unusable";
282 when VERNOTSUPPORTED
=>
283 return "Returned by WSAStartup(), indicating that "
284 & "the Windows Sockets DLL cannot support this application";
286 when NOTINITIALISED
=>
287 return "Winsock not initialized. This message is "
288 & "returned by any function except WSAStartup(), "
289 & "indicating that a successful WSAStartup() has "
290 & "not yet been performed";
295 when HOST_NOT_FOUND
=>
296 return "Host not found. This message indicates "
297 & "that the key (name, address, and so on) was not found";
300 return "Nonauthoritative host not found. This error may "
301 & "suggest that the name service itself is not functioning";
304 return "Nonrecoverable error. This error may suggest that the "
305 & "name service itself is not functioning";
308 return "Valid name, no data record of requested type. "
309 & "This error indicates that the key (name, address, "
310 & "and so on) was not found.";
313 return "Unknown system error";
316 end Socket_Error_Message
;
318 end GNAT
.Sockets
.Thin
;