summaryrefslogtreecommitdiff
path: root/gcc/ada/g-socket.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2009-09-17 10:58:39 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2009-09-17 10:58:39 +0000
commit06adcb1917b58134f15abefb11e49fd495f26971 (patch)
tree3d9d7c3ec8096deb2b799c9a49cf0de08d755268 /gcc/ada/g-socket.adb
parent6064d1cdef16f2eaee2bb8860e45f26ecaa67382 (diff)
downloadgcc-06adcb1917b58134f15abefb11e49fd495f26971.tar.gz
2009-09-17 Bob Duff <duff@adacore.com>
* g-socket.ads: Document the fact that Close_Selector has no effect on a closed selector. * g-socket.adb: Raise an exception when a Selector that should be open is closed. (Check_Selector): Declare RSig as a constant rather than a renames, less confusing. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@151798 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/g-socket.adb')
-rw-r--r--gcc/ada/g-socket.adb41
1 files changed, 40 insertions, 1 deletions
diff --git a/gcc/ada/g-socket.adb b/gcc/ada/g-socket.adb
index d32ebfc37a8..8afde3beec3 100644
--- a/gcc/ada/g-socket.adb
+++ b/gcc/ada/g-socket.adb
@@ -282,6 +282,12 @@ package body GNAT.Sockets is
Res : C.int;
begin
+ if Selector.R_Sig_Socket = No_Socket
+ or else Selector.W_Sig_Socket = No_Socket
+ then
+ raise Program_Error with "closed selector";
+ end if;
+
-- Send one byte to unblock select system call
Res := Signalling_Fds.Write (C.int (Selector.W_Sig_Socket));
@@ -330,6 +336,14 @@ package body GNAT.Sockets is
Status : out Selector_Status)
is
begin
+ if Selector /= null
+ and then (Selector.R_Sig_Socket = No_Socket
+ or else
+ Selector.W_Sig_Socket = No_Socket)
+ then
+ raise Program_Error with "closed selector";
+ end if;
+
-- Wait for socket to become available for reading
Wait_On_Socket
@@ -473,11 +487,17 @@ package body GNAT.Sockets is
is
Res : C.int;
Last : C.int;
- RSig : Socket_Type renames Selector.R_Sig_Socket;
+ RSig : constant Socket_Type := Selector.R_Sig_Socket;
TVal : aliased Timeval;
TPtr : Timeval_Access;
begin
+ if Selector.R_Sig_Socket = No_Socket
+ or else Selector.W_Sig_Socket = No_Socket
+ then
+ raise Program_Error with "closed selector";
+ end if;
+
Status := Completed;
-- No timeout or Forever is indicated by a null timeval pointer
@@ -563,6 +583,12 @@ package body GNAT.Sockets is
procedure Close_Selector (Selector : in out Selector_Type) is
begin
+ if Selector.R_Sig_Socket = No_Socket
+ or else Selector.W_Sig_Socket = No_Socket
+ then
+ return;
+ end if;
+
-- Close the signalling file descriptors used internally for the
-- implementation of Abort_Selector.
@@ -636,6 +662,13 @@ package body GNAT.Sockets is
-- Used to set Socket to non-blocking I/O
begin
+ if Selector /= null and then
+ (Selector.R_Sig_Socket = No_Socket
+ or else Selector.W_Sig_Socket = No_Socket)
+ then
+ raise Program_Error with "closed selector";
+ end if;
+
-- Set the socket to non-blocking I/O
Req := (Name => Non_Blocking_IO, Enabled => True);
@@ -727,6 +760,12 @@ package body GNAT.Sockets is
Res : C.int;
begin
+ if Selector.R_Sig_Socket /= No_Socket
+ or else Selector.W_Sig_Socket /= No_Socket
+ then
+ raise Program_Error with "selector already open";
+ end if;
+
-- We open two signalling file descriptors. One of them is used to send
-- data to the other, which is included in a C_Select socket set. The
-- communication is used to force a call to C_Select to complete, and