Daily bump.
[official-gcc.git] / gcc / ada / 3wsocthi.adb
blobebbe8413feb556024e5109cee208c4d78bc9a848
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 -- B o d y --
8 -- --
9 -- $Revision: 1.5 $
10 -- --
11 -- Copyright (C) 2001 Ada Core Technologies, Inc. --
12 -- --
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. --
23 -- --
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. --
30 -- --
31 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 -- --
33 ------------------------------------------------------------------------------
35 -- This version is for NT.
37 package body GNAT.Sockets.Thin is
39 use type C.unsigned;
41 WSAData_Dummy : array (1 .. 512) of C.int;
43 WS_Version : constant := 16#0101#;
44 Initialized : Boolean := False;
46 -----------
47 -- Clear --
48 -----------
50 procedure Clear
51 (Item : in out Fd_Set;
52 Socket : C.int)
54 begin
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;
60 exit;
61 end if;
62 end loop;
63 end Clear;
65 -----------
66 -- Empty --
67 -----------
69 procedure Empty (Item : in out Fd_Set) is
70 begin
71 Item := Null_Fd_Set;
72 end Empty;
74 --------------
75 -- Finalize --
76 --------------
78 procedure Finalize is
79 begin
80 if Initialized then
81 WSACleanup;
82 Initialized := False;
83 end if;
84 end Finalize;
86 --------------
87 -- Is_Empty --
88 --------------
90 function Is_Empty (Item : Fd_Set) return Boolean is
91 begin
92 return Item.fd_count = 0;
93 end Is_Empty;
95 ------------
96 -- Is_Set --
97 ------------
99 function Is_Set (Item : Fd_Set; Socket : C.int) return Boolean is
100 begin
101 for J in 1 .. Item.fd_count loop
102 if Item.fd_array (J) = Socket then
103 return True;
104 end if;
105 end loop;
107 return False;
108 end Is_Set;
110 ----------------
111 -- Initialize --
112 ----------------
114 procedure Initialize (Process_Blocking_IO : Boolean := False) is
115 Return_Value : Interfaces.C.int;
117 begin
118 if not Initialized then
119 Return_Value := WSAStartup (WS_Version, WSAData_Dummy'Address);
120 pragma Assert (Interfaces.C."=" (Return_Value, 0));
121 Initialized := True;
122 end if;
123 end Initialize;
125 ---------
126 -- Max --
127 ---------
129 function Max (Item : Fd_Set) return C.int is
130 L : C.int := 0;
132 begin
133 for J in 1 .. Item.fd_count loop
134 if Item.fd_array (J) > L then
135 L := Item.fd_array (J);
136 end if;
137 end loop;
139 return L;
140 end Max;
142 ---------
143 -- Set --
144 ---------
146 procedure Set (Item : in out Fd_Set; Socket : in C.int) is
147 begin
148 Item.fd_count := Item.fd_count + 1;
149 Item.fd_array (Item.fd_count) := Socket;
150 end Set;
152 --------------------------
153 -- Socket_Error_Message --
154 --------------------------
156 function Socket_Error_Message (Errno : Integer) return String is
157 use GNAT.Sockets.Constants;
159 begin
160 case Errno is
161 when EINTR =>
162 return "Interrupted system call";
164 when EBADF =>
165 return "Bad file number";
167 when EACCES =>
168 return "Permission denied";
170 when EFAULT =>
171 return "Bad address";
173 when EINVAL =>
174 return "Invalid argument";
176 when EMFILE =>
177 return "Too many open files";
179 when EWOULDBLOCK =>
180 return "Operation would block";
182 when EINPROGRESS =>
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";
188 when EALREADY =>
189 return "Operation already in progress";
191 when ENOTSOCK =>
192 return "Socket operation on nonsocket";
194 when EDESTADDRREQ =>
195 return "Destination address required";
197 when EMSGSIZE =>
198 return "Message too long";
200 when EPROTOTYPE =>
201 return "Protocol wrong type for socket";
203 when ENOPROTOOPT =>
204 return "Protocol not available";
206 when EPROTONOSUPPORT =>
207 return "Protocol not supported";
209 when ESOCKTNOSUPPORT =>
210 return "Socket type not supported";
212 when EOPNOTSUPP =>
213 return "Operation not supported on socket";
215 when EPFNOSUPPORT =>
216 return "Protocol family not supported";
218 when EAFNOSUPPORT =>
219 return "Address family not supported by protocol family";
221 when EADDRINUSE =>
222 return "Address already in use";
224 when EADDRNOTAVAIL =>
225 return "Cannot assign requested address";
227 when ENETDOWN =>
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";
233 when ENETUNREACH =>
234 return "Network is unreachable";
236 when ENETRESET =>
237 return "Network dropped connection on reset";
239 when ECONNABORTED =>
240 return "Software caused connection abort";
242 when ECONNRESET =>
243 return "Connection reset by peer";
245 when ENOBUFS =>
246 return "No buffer space available";
248 when EISCONN =>
249 return "Socket is already connected";
251 when ENOTCONN =>
252 return "Socket is not connected";
254 when ESHUTDOWN =>
255 return "Cannot send after socket shutdown";
257 when ETOOMANYREFS =>
258 return "Too many references: cannot splice";
260 when ETIMEDOUT =>
261 return "Connection timed out";
263 when ECONNREFUSED =>
264 return "Connection refused";
266 when ELOOP =>
267 return "Too many levels of symbolic links";
269 when ENAMETOOLONG =>
270 return "File name too long";
272 when EHOSTDOWN =>
273 return "Host is down";
275 when EHOSTUNREACH =>
276 return "No route to host";
278 when SYSNOTREADY =>
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";
292 when EDISCON =>
293 return "Disconnect";
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";
299 when TRY_AGAIN =>
300 return "Nonauthoritative host not found. This error may "
301 & "suggest that the name service itself is not functioning";
303 when NO_RECOVERY =>
304 return "Nonrecoverable error. This error may suggest that the "
305 & "name service itself is not functioning";
307 when NO_DATA =>
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.";
312 when others =>
313 return "Unknown system error";
315 end case;
316 end Socket_Error_Message;
318 end GNAT.Sockets.Thin;