summaryrefslogtreecommitdiff
path: root/gcc/ada/g-socket.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2009-07-22 15:13:23 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2009-07-22 15:13:23 +0000
commit40ed870090215fbedef46c2176763bf273f6e148 (patch)
tree65d7f0e739dcdf60e4b2300d57a90316c6f89435 /gcc/ada/g-socket.adb
parent6b64c28e44627c234ce9383b632c5f5a13364790 (diff)
downloadgcc-40ed870090215fbedef46c2176763bf273f6e148.tar.gz
2009-07-22 Ed Falis <falis@adacore.com>
* s-vxwext-kernel.adb, s-vxwext-kernel.ads: Replace use of taskStop with taskSuspend. 2009-07-22 Arnaud Charlet <charlet@adacore.com> * adadecode.c: Make this file compilable outside of GCC. 2009-07-22 Thomas Quinot <quinot@adacore.com> * g-socket.adb, g-socket.ads (Check_Selector): Make sure that (partially) default-initialized socket sets are handled properly by clearing their Set component. 2009-07-22 Bob Duff <duff@adacore.com> * gnat_ugn.texi: Clarify the -gnatVx (validity checking) switches. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149939 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/g-socket.adb')
-rw-r--r--gcc/ada/g-socket.adb47
1 files changed, 27 insertions, 20 deletions
diff --git a/gcc/ada/g-socket.adb b/gcc/ada/g-socket.adb
index 5685cb54aa6..c002054395c 100644
--- a/gcc/ada/g-socket.adb
+++ b/gcc/ada/g-socket.adb
@@ -56,10 +56,6 @@ package body GNAT.Sockets is
ENOERROR : constant := 0;
- Empty_Socket_Set : Socket_Set_Type;
- -- Variable set in Initialize, and then used internally to provide an
- -- initial value for Socket_Set_Type objects.
-
Netdb_Buffer_Size : constant := SOSC.Need_Netdb_Buffer * 1024;
-- The network database functions gethostbyname, gethostbyaddr,
-- getservbyname and getservbyport can either be guaranteed task safe by
@@ -264,6 +260,11 @@ package body GNAT.Sockets is
procedure Initialize (X : in out Sockets_Library_Controller);
procedure Finalize (X : in out Sockets_Library_Controller);
+ procedure Normalize_Empty_Socket_Set (S : in out Socket_Set_Type);
+ -- If S is the empty set (detected by Last = No_Socket), make sure its
+ -- fd_set component is actually cleared. Note that the case where it is
+ -- not can occur for an uninitialized Socket_Set_Type object.
+
---------
-- "+" --
---------
@@ -452,7 +453,7 @@ package body GNAT.Sockets is
Status : out Selector_Status;
Timeout : Selector_Duration := Forever)
is
- E_Socket_Set : Socket_Set_Type := Empty_Socket_Set;
+ E_Socket_Set : Socket_Set_Type;
begin
Check_Selector
(Selector, R_Socket_Set, W_Socket_Set, E_Socket_Set, Status, Timeout);
@@ -496,6 +497,12 @@ package body GNAT.Sockets is
C.int (W_Socket_Set.Last)),
C.int (E_Socket_Set.Last));
+ -- Zero out fd_set for empty Socket_Set_Type objects
+
+ Normalize_Empty_Socket_Set (R_Socket_Set);
+ Normalize_Empty_Socket_Set (W_Socket_Set);
+ Normalize_Empty_Socket_Set (E_Socket_Set);
+
Res :=
C_Select
(Last + 1,
@@ -705,7 +712,7 @@ package body GNAT.Sockets is
procedure Copy
(Source : Socket_Set_Type;
- Target : in out Socket_Set_Type)
+ Target : out Socket_Set_Type)
is
begin
Target := Source;
@@ -760,7 +767,7 @@ package body GNAT.Sockets is
-- Empty --
-----------
- procedure Empty (Item : in out Socket_Set_Type) is
+ procedure Empty (Item : out Socket_Set_Type) is
begin
Reset_Socket_Set (Item.Set'Access);
Item.Last := No_Socket;
@@ -1282,10 +1289,6 @@ package body GNAT.Sockets is
pragma Unreferenced (X);
begin
- -- Initialization operation for the GNAT.Sockets package
-
- Empty_Socket_Set.Last := No_Socket;
- Reset_Socket_Set (Empty_Socket_Set.Set'Access);
Thin.Initialize;
end Initialize;
@@ -1408,6 +1411,17 @@ package body GNAT.Sockets is
end if;
end Narrow;
+ --------------------------------
+ -- Normalize_Empty_Socket_Set --
+ --------------------------------
+
+ procedure Normalize_Empty_Socket_Set (S : in out Socket_Set_Type) is
+ begin
+ if S.Last = No_Socket then
+ Reset_Socket_Set (S.Set'Access);
+ end if;
+ end Normalize_Empty_Socket_Set;
+
-------------------
-- Official_Name --
-------------------
@@ -1445,7 +1459,6 @@ package body GNAT.Sockets is
R_Fd_Set : Socket_Set_Type;
W_Fd_Set : Socket_Set_Type;
- -- Socket sets, empty at elaboration
begin
-- Create selector if not provided by the user
@@ -1470,14 +1483,6 @@ package body GNAT.Sockets is
Check_Selector (S.all, R_Fd_Set, W_Fd_Set, Status, Timeout);
- -- Cleanup actions (required in all cases to avoid memory leaks)
-
- if For_Read then
- Empty (R_Fd_Set);
- else
- Empty (W_Fd_Set);
- end if;
-
if Selector = null then
Close_Selector (S.all);
end if;
@@ -1796,8 +1801,10 @@ package body GNAT.Sockets is
if Id = Socket_Error_Id then
return Resolve_Error (Val);
+
elsif Id = Host_Error_Id then
return Resolve_Error (Val, False);
+
else
return Cannot_Resolve_Error;
end if;