1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . S O C K E T S --
11 -- Copyright (C) 2001-2002 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 package provides an interface to the sockets communication facility
36 -- provided on many operating systems. Currently this is implemented on all
37 -- native GNAT ports except for VMS. It is not yet implemented on the Lynx
40 -- Another restriction is that there is no multicast support under Windows
41 -- or under any system on which the multicast support is not available or
47 package GNAT.Sockets is
49 -- Sockets are designed to provide a consistent communication facility
50 -- between applications. This package provides an Ada-like intrerface
51 -- similar to that proposed as part of the BSD socket layer. This is a
52 -- system independent thick binding.
54 -- Here is a typical example of what you can do:
56 -- with GNAT.Sockets; use GNAT.Sockets;
59 -- with Ada.Exceptions; use Ada.Exceptions;
61 -- procedure PingPong is
63 -- Group : constant String := "239.255.128.128";
64 -- -- Multicast groupe: administratively scoped IP address
72 -- Address : Sock_Addr_Type;
73 -- Server : Socket_Type;
74 -- Socket : Socket_Type;
75 -- Channel : Stream_Access;
80 -- -- Get an Internet address of a host (here the local host name).
81 -- -- Note that a host can have several addresses. Here we get
82 -- -- the first one which is supposed to be the official one.
84 -- Address.Addr := Addresses (Get_Host_By_Name (Host_Name), 1);
86 -- -- Get a socket address that is an Internet address and a port
88 -- Address.Port := 5432;
90 -- -- The first step is to create a socket. Once created, this
91 -- -- socket must be associated to with an address. Usually only
92 -- -- a server (Pong here) needs to bind an address explicitly.
93 -- -- Most of the time clients can skip this step because the
94 -- -- socket routines will bind an arbitrary address to an unbound
97 -- Create_Socket (Server);
99 -- -- Allow reuse of local addresses.
104 -- (Reuse_Address, True));
106 -- Bind_Socket (Server, Address);
108 -- -- A server marks a socket as willing to receive connect events.
110 -- Listen_Socket (Server);
112 -- -- Once a server calls Listen_Socket, incoming connects events
113 -- -- can be accepted. The returned Socket is a new socket that
114 -- -- represents the server side of the connection. Server remains
115 -- -- available to receive further connections.
117 -- Accept_Socket (Server, Socket, Address);
119 -- -- Return a stream associated to the connected socket.
121 -- Channel := Stream (Socket);
123 -- -- Force Pong to block
127 -- -- Receive and print message from client Ping.
130 -- Message : String := String'Input (Channel);
133 -- Ada.Text_IO.Put_Line (Message);
135 -- -- Send same message to server Pong.
137 -- String'Output (Channel, Message);
140 -- Close_Socket (Server);
141 -- Close_Socket (Socket);
143 -- -- Part of the multicast example
145 -- -- Create a datagram socket to send connectionless, unreliable
146 -- -- messages of a fixed maximum length.
148 -- Create_Socket (Socket, Family_Inet, Socket_Datagram);
150 -- -- Allow reuse of local addresses.
155 -- (Reuse_Address, True));
157 -- -- Join a multicast group.
161 -- IP_Protocol_For_IP_Level,
162 -- (Add_Membership, Inet_Addr (Group), Any_Inet_Addr));
164 -- -- Controls the live time of the datagram to avoid it being
165 -- -- looped forever due to routing errors. Routers decrement
166 -- -- the TTL of every datagram as it traverses from one network
167 -- -- to another and when its value reaches 0 the packet is
168 -- -- dropped. Default is 1.
172 -- IP_Protocol_For_IP_Level,
173 -- (Multicast_TTL, 1));
175 -- -- Want the data you send to be looped back to your host.
179 -- IP_Protocol_For_IP_Level,
180 -- (Multicast_Loop, True));
182 -- -- If this socket is intended to receive messages, bind it to a
183 -- -- given socket address.
185 -- Address.Addr := Any_Inet_Addr;
186 -- Address.Port := 55505;
188 -- Bind_Socket (Socket, Address);
190 -- -- If this socket is intended to send messages, provide the
191 -- -- receiver socket address.
193 -- Address.Addr := Inet_Addr (Group);
194 -- Address.Port := 55506;
196 -- Channel := Stream (Socket, Address);
198 -- -- Receive and print message from client Ping.
201 -- Message : String := String'Input (Channel);
205 -- -- Get the address of the sender.
207 -- Address := Get_Address (Channel);
208 -- Ada.Text_IO.Put_Line (Message & " from " & Image (Address));
210 -- -- Send same message to server Pong.
212 -- String'Output (Channel, Message);
215 -- Close_Socket (Socket);
219 -- exception when E : others =>
220 -- Ada.Text_IO.Put_Line
221 -- (Exception_Name (E) & ": " & Exception_Message (E));
230 -- Address : Sock_Addr_Type;
231 -- Socket : Socket_Type;
232 -- Channel : Stream_Access;
237 -- -- See comments in Ping section for the first steps.
239 -- Address.Addr := Addresses (Get_Host_By_Name (Host_Name), 1);
240 -- Address.Port := 5432;
241 -- Create_Socket (Socket);
246 -- (Reuse_Address, True));
248 -- -- Force Pong to block
252 -- -- If the client's socket is not bound, Connect_Socket will
253 -- -- bind to an unused address. The client uses Connect_Socket to
254 -- -- create a logical connection between the client's socket and
255 -- -- a server's socket returned by Accept_Socket.
257 -- Connect_Socket (Socket, Address);
259 -- Channel := Stream (Socket);
261 -- -- Send message to server Pong.
263 -- String'Output (Channel, "Hello world");
265 -- -- Force Ping to block
269 -- -- Receive and print message from server Pong.
271 -- Ada.Text_IO.Put_Line (String'Input (Channel));
272 -- Close_Socket (Socket);
274 -- -- Part of multicast example. Code similar to Pong's one.
276 -- Create_Socket (Socket, Family_Inet, Socket_Datagram);
281 -- (Reuse_Address, True));
285 -- IP_Protocol_For_IP_Level,
286 -- (Add_Membership, Inet_Addr (Group), Any_Inet_Addr));
290 -- IP_Protocol_For_IP_Level,
291 -- (Multicast_TTL, 1));
295 -- IP_Protocol_For_IP_Level,
296 -- (Multicast_Loop, True));
298 -- Address.Addr := Any_Inet_Addr;
299 -- Address.Port := 55506;
301 -- Bind_Socket (Socket, Address);
303 -- Address.Addr := Inet_Addr (Group);
304 -- Address.Port := 55505;
306 -- Channel := Stream (Socket, Address);
308 -- -- Send message to server Pong.
310 -- String'Output (Channel, "Hello world");
312 -- -- Receive and print message from server Pong.
315 -- Message : String := String'Input (Channel);
318 -- Address := Get_Address (Channel);
319 -- Ada.Text_IO.Put_Line (Message & " from " & Image (Address));
322 -- Close_Socket (Socket);
326 -- exception when E : others =>
327 -- Ada.Text_IO.Put_Line
328 -- (Exception_Name (E) & ": " & Exception_Message (E));
332 -- -- Indicate whether the thread library provides process
333 -- -- blocking IO. Basically, if you are not using FSU threads
334 -- -- the default is ok.
336 -- Initialize (Process_Blocking_IO => False);
344 procedure Initialize (Process_Blocking_IO : Boolean := False);
345 -- Initialize must be called before using any socket routines. If
346 -- the thread library provides process blocking IO - basically
347 -- with FSU threads - GNAT.Sockets should be initialized with a
348 -- value of True to simulate thread blocking IO. Further calls to
349 -- Initialize will be ignored.
352 -- After Finalize is called it is not possible to use any routines
353 -- exported in by this package. This procedure is idempotent.
355 type Socket_Type is private;
356 -- Sockets are used to implement a reliable bi-directional
357 -- point-to-point, stream-based connections between
358 -- hosts. No_Socket provides a special value to denote
359 -- uninitialized sockets.
361 No_Socket : constant Socket_Type;
363 Socket_Error : exception;
364 -- There is only one exception in this package to deal with an
365 -- error during a socket routine. Once raised, its message
366 -- contains a string describing the error code.
368 function Image (Socket : Socket_Type) return String;
369 -- Return a printable string for Socket
371 function To_C (Socket : Socket_Type) return Integer;
372 -- Return a file descriptor to be used by external subprograms
373 -- especially the C functions that are not yet interfaced in this
376 type Family_Type is (Family_Inet, Family_Inet6);
377 -- Address family (or protocol family) identifies the
378 -- communication domain and groups protocols with similar address
379 -- formats. IPv6 will soon be supported.
381 type Mode_Type is (Socket_Stream, Socket_Datagram);
382 -- Stream sockets provide connection-oriented byte
383 -- streams. Datagram sockets support unreliable connectionless
384 -- message based communication.
386 type Shutmode_Type is (Shut_Read, Shut_Write, Shut_Read_Write);
387 -- When a process closes a socket, the policy is to retain any
388 -- data queued until either a delivery or a timeout expiration (in
389 -- this case, the data are discarded). A finer control is
390 -- available through shutdown. With Shut_Read, no more data can be
391 -- received from the socket. With_Write, no more data can be
392 -- transmitted. Neither transmission nor reception can be
393 -- performed with Shut_Read_Write.
395 type Port_Type is new Natural;
396 -- Classical port definition. No_Port provides a special value to
397 -- denote uninitialized port. Any_Port provides a special value
398 -- enabling all ports.
400 Any_Port : constant Port_Type;
401 No_Port : constant Port_Type;
403 type Inet_Addr_Type (Family : Family_Type := Family_Inet) is private;
404 -- An Internet address depends on an address family (IPv4 contains
405 -- 4 octets and Ipv6 contains 16 octets). Any_Inet_Address is a
406 -- special value treated like a wildcard enabling all addresses.
407 -- No_Inet_Addr provides a special value to denote uninitialized
410 Any_Inet_Addr : constant Inet_Addr_Type;
411 No_Inet_Addr : constant Inet_Addr_Type;
413 type Sock_Addr_Type (Family : Family_Type := Family_Inet) is record
414 Addr : Inet_Addr_Type (Family);
417 -- Socket addresses fully define a socket connection with a
418 -- protocol family, an Internet address and a port. No_Sock_Addr
419 -- provides a special value for uninitialized socket addresses.
421 No_Sock_Addr : constant Sock_Addr_Type;
423 function Image (Value : Inet_Addr_Type) return String;
424 -- Return an image of an Internet address. IPv4 notation consists
425 -- in 4 octets in decimal format separated by dots. IPv6 notation
426 -- consists in 16 octets in hexadecimal format separated by
427 -- colons (and possibly dots).
429 function Image (Value : Sock_Addr_Type) return String;
430 -- Return inet address image and port image separated by a colon.
432 function Inet_Addr (Image : String) return Inet_Addr_Type;
433 -- Convert address image from numbers-and-dots notation into an
436 -- Host entries provide a complete information on a given host:
437 -- the official name, an array of alternative names or aliases and
438 -- array of network addresses.
441 (Aliases_Length, Addresses_Length : Natural) is private;
443 function Official_Name (E : Host_Entry_Type) return String;
444 -- Return official name in host entry
446 function Aliases_Length (E : Host_Entry_Type) return Natural;
447 -- Return number of aliases in host entry
449 function Addresses_Length (E : Host_Entry_Type) return Natural;
450 -- Return number of addresses in host entry
453 (E : Host_Entry_Type;
456 -- Return N'th aliases in host entry. The first index is 1.
459 (E : Host_Entry_Type;
461 return Inet_Addr_Type;
462 -- Return N'th addresses in host entry. The first index is 1.
464 Host_Error : exception;
465 -- Exception raised by the two following procedures. Once raised,
466 -- its message contains a string describing the error code. This
467 -- exception is raised when an host entry can not be retrieved.
469 function Get_Host_By_Address
470 (Address : Inet_Addr_Type;
471 Family : Family_Type := Family_Inet)
472 return Host_Entry_Type;
473 -- Return host entry structure for the given inet address
475 function Get_Host_By_Name
477 return Host_Entry_Type;
478 -- Return host entry structure for the given host name
480 function Host_Name return String;
481 -- Return the name of the current host
483 -- Errors are described by an enumeration type. There is only one
484 -- exception Socket_Error in this package to deal with an error
485 -- during a socket routine. Once raised, its message contains the
486 -- error code between brackets and a string describing the error code.
488 -- The name of the enumeration constant documents the error condition.
492 Address_Already_In_Use,
493 Cannot_Assign_Requested_Address,
494 Address_Family_Not_Supported_By_Protocol,
495 Operation_Already_In_Progress,
499 Operation_Now_In_Progress,
500 Interrupted_System_Call,
503 Transport_Endpoint_Already_Connected,
505 Network_Is_Unreachable,
506 No_Buffer_Space_Available,
507 Protocol_Not_Available,
508 Transport_Endpoint_Not_Connected,
509 Operation_Not_Supported,
510 Protocol_Not_Supported,
511 Socket_Type_Not_Supported,
512 Connection_Timed_Out,
513 Resource_Temporarily_Unavailable,
515 Host_Name_Lookup_Failure,
516 No_Address_Associated_With_Name,
517 Unknown_Server_Error,
518 Cannot_Resolve_Error);
520 -- Get_Socket_Options and Set_Socket_Options manipulate options
521 -- associated with a socket. Options may exist at multiple
522 -- protocol levels in the communication stack. Socket_Level is the
523 -- uppermost socket level.
527 IP_Protocol_For_IP_Level,
528 IP_Protocol_For_UDP_Level,
529 IP_Protocol_For_TCP_Level);
531 -- There are several options available to manipulate sockets. Each
532 -- option has a name and several values available. Most of the
533 -- time, the value is a boolean to enable or disable this option.
535 type Option_Name is (
536 Keep_Alive, -- Enable sending of keep-alive messages
537 Reuse_Address, -- Allow bind to reuse local address
538 Broadcast, -- Enable datagram sockets to recv/send broadcast packets
539 Send_Buffer, -- Set/get the maximum socket send buffer in bytes
540 Receive_Buffer, -- Set/get the maximum socket recv buffer in bytes
541 Linger, -- Shutdown wait for msg to be sent or timeout occur
542 Error, -- Get and clear the pending socket error
543 No_Delay, -- Do not delay send to coalesce packets (TCP_NODELAY)
544 Add_Membership, -- Join a multicast group
545 Drop_Membership, -- Leave a multicast group
546 Multicast_TTL, -- Indicates the time-to-live of sent multicast packets
547 Multicast_Loop); -- Sent multicast packets are looped to the local socket
549 type Option_Type (Name : Option_Name := Keep_Alive) is record
573 when Add_Membership |
575 Multiaddr : Inet_Addr_Type;
576 Interface : Inet_Addr_Type;
578 when Multicast_TTL =>
579 Time_To_Live : Natural;
584 -- There are several controls available to manipulate
585 -- sockets. Each option has a name and several values available.
586 -- These controls differ from the socket options in that they are
587 -- not specific to sockets but are available for any device.
589 type Request_Name is (
590 Non_Blocking_IO, -- Cause a caller not to wait on blocking operations.
591 N_Bytes_To_Read); -- Return the number of bytes available to read
593 type Request_Type (Name : Request_Name := Non_Blocking_IO) is record
595 when Non_Blocking_IO =>
598 when N_Bytes_To_Read =>
604 procedure Create_Socket
605 (Socket : out Socket_Type;
606 Family : Family_Type := Family_Inet;
607 Mode : Mode_Type := Socket_Stream);
608 -- Create an endpoint for communication. Raise Socket_Error on error.
610 procedure Accept_Socket
611 (Server : Socket_Type;
612 Socket : out Socket_Type;
613 Address : out Sock_Addr_Type);
614 -- Extract the first connection request on the queue of pending
615 -- connections, creates a new connected socket with mostly the
616 -- same properties as Server, and allocates a new socket. The
617 -- returned Address is filled in with the address of the
618 -- connection. Raise Socket_Error on error.
620 procedure Bind_Socket
621 (Socket : Socket_Type;
622 Address : Sock_Addr_Type);
623 -- Once a socket is created, assign a local address to it. Raise
624 -- Socket_Error on error.
626 procedure Close_Socket (Socket : Socket_Type);
627 -- Close a socket and more specifically a non-connected socket.
629 procedure Connect_Socket
630 (Socket : Socket_Type;
631 Server : in out Sock_Addr_Type);
632 -- Make a connection to another socket which has the address of
633 -- Server. Raise Socket_Error on error.
635 procedure Control_Socket
636 (Socket : Socket_Type;
637 Request : in out Request_Type);
638 -- Obtain or set parameter values that control the socket. This
639 -- control differs from the socket options in that they are not
640 -- specific to sockets but are avaiable for any device.
642 function Get_Peer_Name (Socket : Socket_Type) return Sock_Addr_Type;
643 -- Return the peer or remote socket address of a socket. Raise
644 -- Socket_Error on error.
646 function Get_Socket_Name (Socket : Socket_Type) return Sock_Addr_Type;
647 -- Return the local or current socket address of a socket. Raise
648 -- Socket_Error on error.
650 function Get_Socket_Option
651 (Socket : Socket_Type;
652 Level : Level_Type := Socket_Level;
655 -- Get the options associated with a socket. Raise Socket_Error on
658 procedure Listen_Socket
659 (Socket : Socket_Type;
660 Length : Positive := 15);
661 -- To accept connections, a socket is first created with
662 -- Create_Socket, a willingness to accept incoming connections and
663 -- a queue Length for incoming connections are specified. Raise
664 -- Socket_Error on error.
666 procedure Receive_Socket
667 (Socket : Socket_Type;
668 Item : out Ada.Streams.Stream_Element_Array;
669 Last : out Ada.Streams.Stream_Element_Offset);
670 -- Receive message from Socket. Last is the index value such that
671 -- Item (Last) is the last character assigned. Note that Last is
672 -- set to Item'First - 1 when the socket has been closed by
673 -- peer. This is not an error and no exception is raised. Raise
674 -- Socket_Error on error.
676 procedure Receive_Socket
677 (Socket : Socket_Type;
678 Item : out Ada.Streams.Stream_Element_Array;
679 Last : out Ada.Streams.Stream_Element_Offset;
680 From : out Sock_Addr_Type);
681 -- Receive message from Socket. If Socket is not
682 -- connection-oriented, the source address From of the message is
683 -- filled in. Last is the index value such that Item (Last) is the
684 -- last character assigned. Raise Socket_Error on error.
686 function Resolve_Exception
687 (Occurrence : Ada.Exceptions.Exception_Occurrence)
689 -- When Socket_Error or Host_Error are raised, the exception
690 -- message contains the error code between brackets and a string
691 -- describing the error code. Resolve_Error extracts the error
692 -- code from an exception message and translate it into an
693 -- enumeration value.
695 procedure Send_Socket
696 (Socket : Socket_Type;
697 Item : Ada.Streams.Stream_Element_Array;
698 Last : out Ada.Streams.Stream_Element_Offset);
699 -- Transmit a message to another socket. Note that Last is set to
700 -- Item'First when socket has been closed by peer. This is not an
701 -- error and no exception is raised. Raise Socket_Error on error;
703 procedure Send_Socket
704 (Socket : Socket_Type;
705 Item : Ada.Streams.Stream_Element_Array;
706 Last : out Ada.Streams.Stream_Element_Offset;
707 To : Sock_Addr_Type);
708 -- Transmit a message to another socket. The address is given by
709 -- To. Raise Socket_Error on error;
711 procedure Set_Socket_Option
712 (Socket : Socket_Type;
713 Level : Level_Type := Socket_Level;
714 Option : Option_Type);
715 -- Manipulate socket options. Raise Socket_Error on error.
717 procedure Shutdown_Socket
718 (Socket : Socket_Type;
719 How : Shutmode_Type := Shut_Read_Write);
720 -- Shutdown a connected socket. If How is Shut_Read, further
721 -- receives will be disallowed. If How is Shut_Write, further
722 -- sends will be disallowed. If how is Shut_Read_Write, further
723 -- sends and receives will be disallowed.
725 type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
726 -- Same interface as Ada.Streams.Stream_IO
729 (Socket : Socket_Type)
730 return Stream_Access;
731 -- Associate a stream with a stream-based socket that is already
735 (Socket : Socket_Type;
736 Send_To : Sock_Addr_Type)
737 return Stream_Access;
738 -- Associate a stream with a datagram-based socket that is already
739 -- bound. Send_To is the socket address to which messages are
743 (Stream : Stream_Access)
744 return Sock_Addr_Type;
745 -- Return the socket address from which the last message was
748 type Socket_Set_Type is private;
749 -- This type allows to manipulate sets of sockets. It allows to
750 -- wait for events on multiple endpoints at one time. This is an
751 -- access type on a system dependent structure. To avoid memory
752 -- leaks it is highly recommended to clean the access value with
755 procedure Clear (Item : in out Socket_Set_Type; Socket : Socket_Type);
756 -- Remove Socket from Item
758 procedure Set (Item : in out Socket_Set_Type; Socket : Socket_Type);
759 -- Insert Socket into Item
761 procedure Empty (Item : in out Socket_Set_Type);
762 -- Remove all Sockets from Item and deallocate internal data
765 (Item : Socket_Set_Type)
767 -- Return True if Item is empty
770 (Item : Socket_Set_Type;
771 Socket : Socket_Type)
773 -- Return True if Socket is present in Item
775 -- C select() waits for a number of file descriptors to change
776 -- status. Usually, three independent sets of descriptors are
777 -- watched (read, write and exception). A timeout gives an upper
778 -- bound on the amount of time elapsed before select returns.
779 -- This function blocks until an event occurs. On some platforms,
780 -- C select can block the full process.
782 -- Check_Selector provides the very same behaviour. The only
783 -- difference is that it does not watch for exception events. Note
784 -- that on some platforms it is kept process blocking in purpose.
785 -- The timeout parameter allows the user to have the behaviour he
786 -- wants. Abort_Selector allows to abort safely a Check_Selector
787 -- that is blocked forever. A special file descriptor is opened by
788 -- Create_Selector and included in each call to
789 -- Check_Selector. Abort_Selector causes an event to occur on this
790 -- descriptor in order to unblock Check_Selector. The user must
791 -- call Close_Selector to discard this special file. A reason to
792 -- abort a select operation is typically to add a socket in one of
793 -- the socket sets when the timeout is set to forever.
795 Forever : constant Duration;
797 type Selector_Type is limited private;
798 type Selector_Access is access all Selector_Type;
800 procedure Create_Selector (Selector : out Selector_Type);
801 -- Create a new selector
803 procedure Close_Selector (Selector : in out Selector_Type);
804 -- Close Selector and all internal descriptors associated
806 type Selector_Status is (Completed, Expired, Aborted);
808 procedure Check_Selector
809 (Selector : in out Selector_Type;
810 R_Socket_Set : in out Socket_Set_Type;
811 W_Socket_Set : in out Socket_Set_Type;
812 Status : out Selector_Status;
813 Timeout : Duration := Forever);
814 -- Return when one Socket in R_Socket_Set has some data to be read
815 -- or if one Socket in W_Socket_Set is ready to receive some
816 -- data. In these cases Status is set to Completed and sockets
817 -- that are ready are set in R_Socket_Set or W_Socket_Set. Status
818 -- is set to Expired if no socket was ready after a Timeout
819 -- expiration. Status is set to Aborted if an abort signal has been
820 -- received while checking socket status. As this procedure
821 -- returns when Timeout occurs, it is a design choice to keep this
822 -- procedure process blocking. Note that a Timeout of 0.0 returns
825 procedure Abort_Selector (Selector : Selector_Type);
826 -- Send an abort signal to the selector.
830 type Socket_Type is new Integer;
831 No_Socket : constant Socket_Type := -1;
833 Forever : constant Duration := Duration'Last;
835 type Selector_Type is limited record
836 R_Sig_Socket : Socket_Type;
837 W_Sig_Socket : Socket_Type;
838 In_Progress : Boolean := False;
840 -- The two signalling sockets are used to abort a select
843 type Socket_Set_Record;
844 type Socket_Set_Type is access all Socket_Set_Record;
846 subtype Inet_Addr_Comp_Type is Natural range 0 .. 255;
847 -- Octet for Internet address
849 type Inet_Addr_VN_Type is array (Natural range <>) of Inet_Addr_Comp_Type;
851 subtype Inet_Addr_V4_Type is Inet_Addr_VN_Type (1 .. 4);
852 subtype Inet_Addr_V6_Type is Inet_Addr_VN_Type (1 .. 16);
854 type Inet_Addr_Type (Family : Family_Type := Family_Inet) is record
857 Sin_V4 : Inet_Addr_V4_Type := (others => 0);
860 Sin_V6 : Inet_Addr_V6_Type := (others => 0);
864 Any_Port : constant Port_Type := 0;
865 No_Port : constant Port_Type := 0;
867 Any_Inet_Addr : constant Inet_Addr_Type := (Family_Inet, (others => 0));
868 No_Inet_Addr : constant Inet_Addr_Type := (Family_Inet, (others => 0));
870 No_Sock_Addr : constant Sock_Addr_Type := (Family_Inet, No_Inet_Addr, 0);
872 Max_Host_Name_Length : constant := 64;
873 -- The constant MAXHOSTNAMELEN is usually set to 64
875 subtype Host_Name_Index is Natural range 1 .. Max_Host_Name_Length;
878 (Length : Host_Name_Index := Max_Host_Name_Length)
880 Name : String (1 .. Length);
882 -- We need fixed strings to avoid access types in host entry type
884 type Host_Name_Array is array (Natural range <>) of Host_Name_Type;
885 type Inet_Addr_Array is array (Natural range <>) of Inet_Addr_Type;
887 type Host_Entry_Type (Aliases_Length, Addresses_Length : Natural) is record
888 Official : Host_Name_Type;
889 Aliases : Host_Name_Array (1 .. Aliases_Length);
890 Addresses : Inet_Addr_Array (1 .. Addresses_Length);