diff options
author | Thomas Quinot <quinot@adacore.com> | 2005-06-16 10:41:50 +0200 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2005-06-16 10:41:50 +0200 |
commit | 564383da33e0a312edb3fc57ce5eddef8b5ab119 (patch) | |
tree | 9a3decf2d8760e995c4cab0cca0f7835b0284741 /gcc/ada/g-socket.ads | |
parent | e5a97c132907d389b09a5f0d8f6ff94314d4c390 (diff) | |
download | gcc-564383da33e0a312edb3fc57ce5eddef8b5ab119.zip gcc-564383da33e0a312edb3fc57ce5eddef8b5ab119.tar.gz gcc-564383da33e0a312edb3fc57ce5eddef8b5ab119.tar.bz2 |
re PR ada/6717 (Race condition in GNAT.Sockets.Create_Selector)
2005-06-14 Thomas Quinot <quinot@adacore.com>
PR ada/6717
* g-socket.ads, g-socket.adb (Inet_Addr): Special case the all-ones
broadcast address.
(Create_Selector): Bind listening socket used to create the signalling
socket pair to 127.0.0.1 to limit the scope for 'theft' of connection.
Set listen backlog to 1 to ensure that we detect socket theft by a
failure of our own connect(2) call.
(Check_Selector): Improve documentation of the selector mechanism.
(Broadcast_Inet_Addr): New constant.
From-SVN: r101043
Diffstat (limited to 'gcc/ada/g-socket.ads')
-rw-r--r-- | gcc/ada/g-socket.ads | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/gcc/ada/g-socket.ads b/gcc/ada/g-socket.ads index c613d20..9945b2f 100644 --- a/gcc/ada/g-socket.ads +++ b/gcc/ada/g-socket.ads @@ -433,8 +433,9 @@ package GNAT.Sockets is -- treated like a wildcard enabling all addresses. No_Inet_Addr provides a -- special value to denote uninitialized inet addresses. - Any_Inet_Addr : constant Inet_Addr_Type; - No_Inet_Addr : constant Inet_Addr_Type; + Any_Inet_Addr : constant Inet_Addr_Type; + No_Inet_Addr : constant Inet_Addr_Type; + Broadcast_Inet_Addr : constant Inet_Addr_Type; type Sock_Addr_Type (Family : Family_Type := Family_Inet) is record Addr : Inet_Addr_Type (Family); @@ -912,15 +913,16 @@ package GNAT.Sockets is procedure Set (Item : in out Socket_Set_Type; Socket : Socket_Type); -- Insert Socket into Item - -- C select() waits for a number of file descriptors to change status. - -- Usually, three independent sets of descriptors are watched (read, write - -- and exception). A timeout gives an upper bound on the amount of time - -- elapsed before select returns. This function blocks until an event - -- occurs. On some platforms, C select can block the full process. + -- The select(2) system call waits for events to occur on any of a set of + -- file descriptors. Usually, three independent sets of descriptors are + -- watched (read, write and exception). A timeout gives an upper bound + -- on the amount of time elapsed before select returns. This function + -- blocks until an event occurs. On some platforms, the select(2) system + -- can block the full process (not just the calling thread). -- -- Check_Selector provides the very same behaviour. The only difference is -- that it does not watch for exception events. Note that on some - -- platforms it is kept process blocking in purpose. The timeout parameter + -- platforms it is kept process blocking on purpose. The timeout parameter -- allows the user to have the behaviour he wants. Abort_Selector allows -- to abort safely a Check_Selector that is blocked forever. A special -- file descriptor is opened by Create_Selector and included in each call @@ -958,16 +960,19 @@ package GNAT.Sockets is Status : out Selector_Status; Timeout : Selector_Duration := Forever); -- Return when one Socket in R_Socket_Set has some data to be read or if - -- one Socket in W_Socket_Set is ready to receive some data. In these + -- one Socket in W_Socket_Set is ready to transmit some data. In these -- cases Status is set to Completed and sockets that are ready are set in -- R_Socket_Set or W_Socket_Set. Status is set to Expired if no socket was -- ready after a Timeout expiration. Status is set to Aborted if an abort -- signal has been received while checking socket status. As this -- procedure returns when Timeout occurs, it is a design choice to keep -- this procedure process blocking. Note that a Timeout of 0.0 returns - -- immediately. Also note that two different objects must be passed as - -- R_Socket_Set and W_Socket_Set (even if they contain the same set of - -- Sockets), or some event will be lost. + -- immediately. Also note that two different Socket_Set_Type objects must + -- be passed as R_Socket_Set and W_Socket_Set (even if they denote the + -- same set of Sockets), or some event will be lost. + -- Socket_Error is raised when the select(2) system call returns an + -- error condition, or when a read error occurs on the signalling socket + -- used for the implementation of Abort_Selector. procedure Check_Selector (Selector : in out Selector_Type; @@ -1027,10 +1032,14 @@ private Any_Port : constant Port_Type := 0; No_Port : constant Port_Type := 0; - Any_Inet_Addr : constant Inet_Addr_Type := (Family_Inet, (others => 0)); - No_Inet_Addr : constant Inet_Addr_Type := (Family_Inet, (others => 0)); + Any_Inet_Addr : constant Inet_Addr_Type := + (Family_Inet, (others => 0)); + No_Inet_Addr : constant Inet_Addr_Type := + (Family_Inet, (others => 0)); + Broadcast_Inet_Addr : constant Inet_Addr_Type := + (Family_Inet, (others => 255)); - No_Sock_Addr : constant Sock_Addr_Type := (Family_Inet, No_Inet_Addr, 0); + No_Sock_Addr : constant Sock_Addr_Type := (Family_Inet, No_Inet_Addr, 0); Max_Name_Length : constant := 64; -- The constant MAXHOSTNAMELEN is usually set to 64 |