g-socket.ads, [...]: Add new sockets constant MSG_NOSIGNAL (Linux-specific).
authorThomas Quinot <quinot@act-europe.fr>
Mon, 4 Oct 2004 14:49:35 +0000 (16:49 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Mon, 4 Oct 2004 14:49:35 +0000 (16:49 +0200)
2004-10-04  Thomas Quinot  <quinot@act-europe.fr>

* g-socket.ads, g-socket.adb, g-socthi.adb, socket.c,
g-soccon-aix.ads, g-soccon-irix.ads, g-soccon-hpux.ads,
g-soccon-interix.ads, g-soccon-solaris.ads, g-soccon-vms.adb,
g-soccon-mingw.ads, g-soccon-vxworks.ads, g-soccon-freebsd.ads,
g-soccon.ads, g-soccon-unixware.ads, g-soccon-tru64.ads:  Add new
sockets constant MSG_NOSIGNAL (Linux-specific).
Add new sockets constant MSG_Forced_Flags, list of flags to be set on
all Send operations.
For Linux, set MSG_NOSIGNAL on all send operations to prevent them
from trigerring SIGPIPE.
Rename components to avoid clash with Ada 2005 possible reserved
word 'interface'.
(Check_Selector): When the select system call returns with an error
condition, propagate Socket_Error to the caller.

From-SVN: r88485

17 files changed:
gcc/ada/ChangeLog
gcc/ada/g-soccon-aix.ads
gcc/ada/g-soccon-freebsd.ads
gcc/ada/g-soccon-hpux.ads
gcc/ada/g-soccon-interix.ads
gcc/ada/g-soccon-irix.ads
gcc/ada/g-soccon-mingw.ads
gcc/ada/g-soccon-solaris.ads
gcc/ada/g-soccon-tru64.ads
gcc/ada/g-soccon-unixware.ads
gcc/ada/g-soccon-vms.adb
gcc/ada/g-soccon-vxworks.ads
gcc/ada/g-soccon.ads
gcc/ada/g-socket.adb
gcc/ada/g-socket.ads
gcc/ada/g-socthi.adb
gcc/ada/socket.c

index c03adf8204c2395cbe8850d0e0c92e1f96bafcf0..6620e371c47cec6f2284109e9bd502e15ccbce07 100644 (file)
@@ -1,3 +1,20 @@
+2004-10-04  Thomas Quinot  <quinot@act-europe.fr>
+
+       * g-socket.ads, g-socket.adb, g-socthi.adb, socket.c,
+       g-soccon-aix.ads, g-soccon-irix.ads, g-soccon-hpux.ads, 
+       g-soccon-interix.ads, g-soccon-solaris.ads, g-soccon-vms.adb, 
+       g-soccon-mingw.ads, g-soccon-vxworks.ads, g-soccon-freebsd.ads, 
+       g-soccon.ads, g-soccon-unixware.ads, g-soccon-tru64.ads:  Add new
+       sockets constant MSG_NOSIGNAL (Linux-specific).
+       Add new sockets constant MSG_Forced_Flags, list of flags to be set on
+       all Send operations.
+       For Linux, set MSG_NOSIGNAL on all send operations to prevent them
+       from trigerring SIGPIPE.
+       Rename components to avoid clash with Ada 2005 possible reserved
+       word 'interface'.
+       (Check_Selector): When the select system call returns with an error
+       condition, propagate Socket_Error to the caller.
+
 2004-10-01  Jan Hubicka  <jh@suse.cz>
 
        * misc.c (gnat_expand_body): Update call of tree_rest_of_compilation.
index 0f5fe9d4c6bbba8f40a0286513787b9a76e881fa..4361f0940e64b96da5f985cacee813a70ba241fc 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index cd19222e1a735c5f7d450fa4c239e44adcf0e743..ca1da41bbd52796932ba61d125467c12c3944fe7 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index cbca2bee7a57d026970fe6a29dd1e7b7b87c270d..56e0d5f594ea5591f31f94b6df8e435c712c49f9 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index 61903079b82f3fe8923d40dc111604a8028f61e3..aa6ab5b05562e33fb7c853c7f98b909553071e3b 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index f19f3cde5f60d6f1ea33499bcd110bd0e990a8b1..b1201f69aa72822adbe005d3f7953ddfb4a9d74f 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index b4bb31564dccb9adc4f971b726533100e03d475f..b963ca6474a7dc1bde77c193a1e3fb2c59362832 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=           -1; --  Send end of record
    MSG_WAITALL        : constant :=           -1; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index 1ad58838ca95a2071c3f449208887a7266d35a08..21dbac5d29a0dcb3992c584d8765df69216fbb46 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index ef3536e4bbc88c0e49b9a4b9452c9bfa552a3d32..a0927e2bcfe95514519524286509ddd834a4d42b 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index 9f7065f6ffe564a0b4baf58589d3d9893f1c40b8..d53931116d9d20edebadd1b19fc64f9773c96f1a 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index 76b2051e07c583758bf6e6237ac89d41796f4104..ebd394c54a3508c518ef8f0fd44cfd9db44d01d0 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index 27dcb0c7a9efd4ed3aef6e3ffac3140d4c4a00f2..0e4004f4481362afa129d450bdf2da5dcf6614a0 100644 (file)
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=            8; --  Send end of record
    MSG_WAITALL        : constant :=           64; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=           -1; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant :=            0;
 
    --------------------
    -- Socket options --
index abe651de512970251c278ee58478cc6fb102aa78..54c931a04b37ba41daad6de2cdbcde21287a93aa 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2003 Free Software Foundation, Inc.          --
+--          Copyright (C) 2000-2004 Free Software Foundation, Inc.          --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -137,6 +137,8 @@ package GNAT.Sockets.Constants is
    MSG_PEEK           : constant :=            2; --  Peek at incoming data
    MSG_EOR            : constant :=          128; --  Send end of record
    MSG_WAITALL        : constant :=          256; --  Wait for full reception
+   MSG_NOSIGNAL       : constant :=        16384; --  No SIGPIPE on send
+   MSG_Forced_Flags   : constant := MSG_NOSIGNAL;
 
    --------------------
    -- Socket options --
index b2d4f259cc30ed2fc5d51c5cda77f504d01c09f2..01f9d19bb936a4868f296837775d2341b8c13be2 100644 (file)
@@ -117,8 +117,7 @@ package body GNAT.Sockets is
 
    function Resolve_Error
      (Error_Value : Integer;
-      From_Errno  : Boolean := True)
-      return        Error_Type;
+      From_Errno  : Boolean := True) return Error_Type;
    --  Associate an enumeration value (error_type) to en error value
    --  (errno). From_Errno prevents from mixing h_errno with errno.
 
@@ -127,23 +126,24 @@ package body GNAT.Sockets is
    --  Conversion functions
 
    function To_Int (F : Request_Flag_Type) return C.int;
+   --  Return the int value corresponding to the specified flags combination
+
+   function Set_Forced_Flags (F : C.int) return C.int;
+   --  Return F with the bits from Constants.MSG_Forced_Flags forced set
 
    function Short_To_Network
-     (S : C.unsigned_short)
-      return C.unsigned_short;
+     (S : C.unsigned_short) return C.unsigned_short;
    pragma Inline (Short_To_Network);
    --  Convert a port number into a network port number
 
    function Network_To_Short
-     (S : C.unsigned_short)
-      return C.unsigned_short
+     (S : C.unsigned_short) return C.unsigned_short
    renames Short_To_Network;
    --  Symetric operation
 
    function Image
      (Val :  Inet_Addr_VN_Type;
-      Hex :  Boolean := False)
-      return String;
+      Hex :  Boolean := False) return String;
    --  Output an array of inet address components either in
    --  hexadecimal or in decimal mode.
 
@@ -172,7 +172,7 @@ package body GNAT.Sockets is
    --  (note hstrerror seems to be obsolete).
 
    procedure Narrow (Item : in out Socket_Set_Type);
-   --  Update Last as it may be greater than the real last socket.
+   --  Update Last as it may be greater than the real last socket
 
    --  Types needed for Datagram_Socket_Stream_Type
 
@@ -267,9 +267,8 @@ package body GNAT.Sockets is
    ---------------
 
    function Addresses
-     (E    : Host_Entry_Type;
-      N    : Positive := 1)
-      return Inet_Addr_Type
+     (E : Host_Entry_Type;
+      N : Positive := 1) return Inet_Addr_Type
    is
    begin
       return E.Addresses (N);
@@ -289,9 +288,8 @@ package body GNAT.Sockets is
    -------------
 
    function Aliases
-     (E    : Host_Entry_Type;
-      N    : Positive := 1)
-      return String
+     (E : Host_Entry_Type;
+      N : Positive := 1) return String
    is
    begin
       return To_String (E.Aliases (N));
@@ -302,9 +300,8 @@ package body GNAT.Sockets is
    -------------
 
    function Aliases
-     (S    : Service_Entry_Type;
-      N    : Positive := 1)
-      return String
+     (S : Service_Entry_Type;
+      N : Positive := 1) return String
    is
    begin
       return To_String (S.Aliases (N));
@@ -431,6 +428,10 @@ package body GNAT.Sockets is
           ESet.Set,
           TPtr);
 
+      if Res = Failure then
+         Raise_Socket_Error (Socket_Errno);
+      end if;
+
       --  If Select was resumed because of read signalling socket,
       --  read this data and remove socket from set.
 
@@ -456,7 +457,7 @@ package body GNAT.Sockets is
       Narrow (WSet);
       Narrow (ESet);
 
-      --  Reset RSet as it should be if R_Sig_Socket was not added.
+      --  Reset RSet as it should be if R_Sig_Socket was not added
 
       if Is_Empty (RSet) then
          Empty (RSet);
@@ -470,7 +471,7 @@ package body GNAT.Sockets is
          Empty (ESet);
       end if;
 
-      --  Deliver RSet, WSet and ESet.
+      --  Deliver RSet, WSet and ESet
 
       Empty (R_Socket_Set);
       R_Socket_Set := RSet;
@@ -822,8 +823,7 @@ package body GNAT.Sockets is
 
    function Get_Host_By_Address
      (Address : Inet_Addr_Type;
-      Family  : Family_Type := Family_Inet)
-      return    Host_Entry_Type
+      Family  : Family_Type := Family_Inet) return Host_Entry_Type
    is
       pragma Unreferenced (Family);
 
@@ -865,7 +865,7 @@ package body GNAT.Sockets is
       Err : Integer;
 
    begin
-      --  Detect IP address name and redirect to Inet_Addr.
+      --  Detect IP address name and redirect to Inet_Addr
 
       if Is_IP_Address (Name) then
          return Get_Host_By_Address (Inet_Addr (Name));
@@ -920,8 +920,7 @@ package body GNAT.Sockets is
 
    function Get_Service_By_Name
      (Name     : String;
-      Protocol : String)
-      return     Service_Entry_Type
+      Protocol : String) return Service_Entry_Type
    is
       SN  : constant C.char_array := C.To_C (Name);
       SP  : constant C.char_array := C.To_C (Protocol);
@@ -957,8 +956,7 @@ package body GNAT.Sockets is
 
    function Get_Service_By_Port
      (Port     : Port_Type;
-      Protocol : String)
-      return     Service_Entry_Type
+      Protocol : String) return Service_Entry_Type
    is
       SP  : constant C.char_array := C.To_C (Protocol);
       Res : Servent_Access;
@@ -993,8 +991,7 @@ package body GNAT.Sockets is
    ---------------------
 
    function Get_Socket_Name
-     (Socket : Socket_Type)
-      return   Sock_Addr_Type
+     (Socket : Socket_Type) return Sock_Addr_Type
    is
       Sin  : aliased Sockaddr_In;
       Len  : aliased C.int := Sin'Size / 8;
@@ -1018,8 +1015,7 @@ package body GNAT.Sockets is
    function Get_Socket_Option
      (Socket : Socket_Type;
       Level  : Level_Type := Socket_Level;
-      Name   : Option_Name)
-      return   Option_Type
+      Name   : Option_Name) return Option_Type
    is
       use type C.unsigned_char;
 
@@ -1087,8 +1083,8 @@ package body GNAT.Sockets is
 
          when Add_Membership  |
               Drop_Membership =>
-            Opt.Multiaddr := To_Inet_Addr (To_In_Addr (V8 (V8'First)));
-            Opt.Interface := To_Inet_Addr (To_In_Addr (V8 (V8'Last)));
+            Opt.Multicast_Address := To_Inet_Addr (To_In_Addr (V8 (V8'First)));
+            Opt.Local_Interface   := To_Inet_Addr (To_In_Addr (V8 (V8'Last)));
 
          when Multicast_TTL   =>
             Opt.Time_To_Live := Integer (V1);
@@ -1124,9 +1120,8 @@ package body GNAT.Sockets is
    -----------
 
    function Image
-     (Val  : Inet_Addr_VN_Type;
-      Hex  : Boolean := False)
-      return String
+     (Val : Inet_Addr_VN_Type;
+      Hex : Boolean := False) return String
    is
       --  The largest Inet_Addr_Comp_Type image occurs with IPv4. It
       --  has at most a length of 3 plus one '.' character.
@@ -1141,6 +1136,10 @@ package body GNAT.Sockets is
       procedure Img16 (V : Inet_Addr_Comp_Type);
       --  Append to Buffer image of V in hexadecimal format
 
+      -----------
+      -- Img10 --
+      -----------
+
       procedure Img10 (V : Inet_Addr_Comp_Type) is
          Img : constant String := V'Img;
          Len : constant Natural := Img'Length - 1;
@@ -1150,6 +1149,10 @@ package body GNAT.Sockets is
          Length := Length + Len;
       end Img10;
 
+      -----------
+      -- Img16 --
+      -----------
+
       procedure Img16 (V : Inet_Addr_Comp_Type) is
       begin
          Buffer (Length)     := Hex_To_Char (Natural (V / 16) + 1);
@@ -1201,7 +1204,6 @@ package body GNAT.Sockets is
 
    function Image (Value : Sock_Addr_Type) return String is
       Port : constant String := Value.Port'Img;
-
    begin
       return Image (Value.Addr) & ':' & Port (2 .. Port'Last);
    end Image;
@@ -1282,8 +1284,7 @@ package body GNAT.Sockets is
 
    function Is_Set
      (Item   : Socket_Set_Type;
-      Socket : Socket_Type)
-      return   Boolean
+      Socket : Socket_Type) return Boolean
    is
    begin
       return Item.Last /= No_Socket
@@ -1299,10 +1300,8 @@ package body GNAT.Sockets is
      (Socket : Socket_Type;
       Length : Positive := 15)
    is
-      Res : C.int;
-
+      Res : constant C.int := C_Listen (C.int (Socket), C.int (Length));
    begin
-      Res := C_Listen (C.int (Socket), C.int (Length));
       if Res = Failure then
          Raise_Socket_Error (Socket_Errno);
       end if;
@@ -1314,7 +1313,6 @@ package body GNAT.Sockets is
 
    procedure Narrow (Item : in out Socket_Set_Type) is
       Last : aliased C.int := C.int (Item.Last);
-
    begin
       if Item.Set /= No_Socket_Set then
          Last_Socket_In_Set (Item.Set, Last'Unchecked_Access);
@@ -1364,12 +1362,16 @@ package body GNAT.Sockets is
 
    procedure Raise_Host_Error (Error : Integer) is
 
-      function Error_Message return String;
+      function Host_Error_Message return String;
       --  We do not use a C function like strerror because hstrerror
       --  that would correspond seems to be obsolete. Return
       --  appropriate string for error value.
 
-      function Error_Message return String is
+      ------------------------
+      -- Host_Error_Message --
+      ------------------------
+
+      function Host_Error_Message return String is
       begin
          case Error is
             when Constants.HOST_NOT_FOUND => return "Host not found";
@@ -1378,12 +1380,12 @@ package body GNAT.Sockets is
             when Constants.NO_DATA        => return "No address";
             when others                   => return "Unknown error";
          end case;
-      end Error_Message;
+      end Host_Error_Message;
 
    --  Start of processing for Raise_Host_Error
 
    begin
-      Ada.Exceptions.Raise_Exception (Host_Error'Identity, Error_Message);
+      Ada.Exceptions.Raise_Exception (Host_Error'Identity, Host_Error_Message);
    end Raise_Host_Error;
 
    ------------------------
@@ -1394,6 +1396,11 @@ package body GNAT.Sockets is
       use type C.Strings.chars_ptr;
 
       function Image (E : Integer) return String;
+
+      -----------
+      -- Image --
+      -----------
+
       function Image (E : Integer) return String is
          Msg : String := E'Img & "] ";
       begin
@@ -1401,6 +1408,8 @@ package body GNAT.Sockets is
          return Msg;
       end Image;
 
+   --  Start of processing for Raise_Socket_Error
+
    begin
       Ada.Exceptions.Raise_Exception
         (Socket_Error'Identity,
@@ -1507,9 +1516,9 @@ package body GNAT.Sockets is
    is
       use type Ada.Streams.Stream_Element_Offset;
 
-      Res  : C.int;
-      Sin  : aliased Sockaddr_In;
-      Len  : aliased C.int := Sin'Size / 8;
+      Res : C.int;
+      Sin : aliased Sockaddr_In;
+      Len : aliased C.int := Sin'Size / 8;
 
    begin
       Res :=
@@ -1537,8 +1546,7 @@ package body GNAT.Sockets is
 
    function Resolve_Error
      (Error_Value : Integer;
-      From_Errno  : Boolean := True)
-      return        Error_Type
+      From_Errno  : Boolean := True) return Error_Type
    is
       use GNAT.Sockets.Constants;
 
@@ -1608,8 +1616,7 @@ package body GNAT.Sockets is
    -----------------------
 
    function Resolve_Exception
-     (Occurrence : Exception_Occurrence)
-      return       Error_Type
+     (Occurrence : Exception_Occurrence) return Error_Type
    is
       Id    : constant Exception_Id := Exception_Identity (Occurrence);
       Msg   : constant String       := Exception_Message (Occurrence);
@@ -1640,10 +1647,8 @@ 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;
@@ -1694,7 +1699,7 @@ package body GNAT.Sockets is
           (C.int (Socket),
            Item (Item'First)'Address,
            Item'Length,
-           To_Int (Flags));
+           Set_Forced_Flags (To_Int (Flags)));
 
       if Res = Failure then
          Raise_Socket_Error (Socket_Errno);
@@ -1732,7 +1737,7 @@ package body GNAT.Sockets is
         (C.int (Socket),
          Item (Item'First)'Address,
          Item'Length,
-         To_Int (Flags),
+         Set_Forced_Flags (To_Int (Flags)),
          Sin'Unchecked_Access,
          Len);
 
@@ -1753,6 +1758,7 @@ package body GNAT.Sockets is
       Count  : out Ada.Streams.Stream_Element_Count)
    is
       Res : C.int;
+
    begin
       Res :=
         C_Writev
@@ -1784,6 +1790,20 @@ package body GNAT.Sockets is
       Insert_Socket_In_Set (Item.Set, C.int (Socket));
    end Set;
 
+   ----------------------
+   -- Set_Forced_Flags --
+   ----------------------
+
+   function Set_Forced_Flags (F : C.int) return C.int is
+      use type C.unsigned;
+      function To_unsigned is
+        new Ada.Unchecked_Conversion (C.int, C.unsigned);
+      function To_int is
+        new Ada.Unchecked_Conversion (C.unsigned, C.int);
+   begin
+      return To_int (To_unsigned (F) or Constants.MSG_Forced_Flags);
+   end Set_Forced_Flags;
+
    -----------------------
    -- Set_Socket_Option --
    -----------------------
@@ -1829,8 +1849,8 @@ package body GNAT.Sockets is
 
          when Add_Membership  |
               Drop_Membership =>
-            V8 (V8'First) := To_Int (To_In_Addr (Option.Multiaddr));
-            V8 (V8'Last)  := To_Int (To_In_Addr (Option.Interface));
+            V8 (V8'First) := To_Int (To_In_Addr (Option.Multicast_Address));
+            V8 (V8'Last)  := To_Int (To_In_Addr (Option.Local_Interface));
             Len := V8'Size / 8;
             Add := V8'Address;
 
@@ -1908,8 +1928,7 @@ package body GNAT.Sockets is
 
    function Stream
      (Socket  : Socket_Type;
-      Send_To : Sock_Addr_Type)
-      return    Stream_Access
+      Send_To : Sock_Addr_Type) return Stream_Access
    is
       S : Datagram_Socket_Stream_Access;
 
@@ -1966,10 +1985,10 @@ package body GNAT.Sockets is
       --  H_Length is not used because it is currently only set to 4.
       --  H_Addrtype is always AF_INET
 
-      Result    : Host_Entry_Type
-        (Aliases_Length   => Aliases'Length - 1,
-         Addresses_Length => Addresses'Length - 1);
-      --  The last element is a null pointer.
+      Result : Host_Entry_Type
+                 (Aliases_Length   => Aliases'Length - 1,
+                  Addresses_Length => Addresses'Length - 1);
+      --  The last element is a null pointer
 
       Source : C.size_t;
       Target : Natural;
@@ -2019,17 +2038,14 @@ package body GNAT.Sockets is
    ------------------
 
    function To_Inet_Addr
-     (Addr : In_Addr)
-      return Inet_Addr_Type
+     (Addr : In_Addr) return Inet_Addr_Type
    is
       Result : Inet_Addr_Type;
-
    begin
       Result.Sin_V4 (1) := Inet_Addr_Comp_Type (Addr.S_B1);
       Result.Sin_V4 (2) := Inet_Addr_Comp_Type (Addr.S_B2);
       Result.Sin_V4 (3) := Inet_Addr_Comp_Type (Addr.S_B3);
       Result.Sin_V4 (4) := Inet_Addr_Comp_Type (Addr.S_B4);
-
       return Result;
    end To_Inet_Addr;
 
@@ -2088,7 +2104,7 @@ package body GNAT.Sockets is
 
       Result   : Service_Entry_Type
         (Aliases_Length   => Aliases'Length - 1);
-      --  The last element is a null pointer.
+      --  The last element is a null pointer
 
       Source : C.size_t;
       Target : Natural;
@@ -2138,6 +2154,7 @@ package body GNAT.Sockets is
          MS := 0;
 
       --  Normal case where we do round down
+
       else
          S  := Timeval_Unit (Val - 0.5);
          MS := Timeval_Unit (1_000_000 * (Val - Selector_Duration (S)));
index 27841d8c9d2cd9ca4f039283b00bc4ccdbfaec5a..c2c447992ac0a4bc21ea2bc2464f7bfe81559a05 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---              Copyright (C) 2001-2003 Ada Core Technologies, Inc.         --
+--              Copyright (C) 2001-2004 Ada Core Technologies, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -399,35 +399,32 @@ package GNAT.Sockets is
    No_Socket : constant Socket_Type;
 
    Socket_Error : exception;
-   --  There is only one exception in this package to deal with an
-   --  error during a socket routine. Once raised, its message
-   --  contains a string describing the error code.
+   --  There is only one exception in this package to deal with an error during
+   --  a socket routine. Once raised, its message contains a string describing
+   --  the error code.
 
    function Image (Socket : Socket_Type) return String;
    --  Return a printable string for Socket
 
    function To_C (Socket : Socket_Type) return Integer;
-   --  Return a file descriptor to be used by external subprograms
-   --  especially the C functions that are not yet interfaced in this
-   --  package.
+   --  Return a file descriptor to be used by external subprograms. This is
+   --  useful for C functions that are not yet interfaced in this package.
 
    type Family_Type is (Family_Inet, Family_Inet6);
-   --  Address family (or protocol family) identifies the
-   --  communication domain and groups protocols with similar address
-   --  formats. IPv6 will soon be supported.
+   --  Address family (or protocol family) identifies the communication domain
+   --  and groups protocols with similar address formats. IPv6 will soon be
+   --  supported.
 
    type Mode_Type is (Socket_Stream, Socket_Datagram);
-   --  Stream sockets provide connection-oriented byte
-   --  streams. Datagram sockets support unreliable connectionless
-   --  message based communication.
+   --  Stream sockets provide connection-oriented byte streams. Datagram
+   --  sockets support unreliable connectionless message based communication.
 
    type Shutmode_Type is (Shut_Read, Shut_Write, Shut_Read_Write);
-   --  When a process closes a socket, the policy is to retain any
-   --  data queued until either a delivery or a timeout expiration (in
-   --  this case, the data are discarded). A finer control is
-   --  available through shutdown. With Shut_Read, no more data can be
-   --  received from the socket. With_Write, no more data can be
-   --  transmitted. Neither transmission nor reception can be
+   --  When a process closes a socket, the policy is to retain any data queued
+   --  until either a delivery or a timeout expiration (in this case, the data
+   --  are discarded). A finer control is available through shutdown. With
+   --  Shut_Read, no more data can be received from the socket. With_Write, no
+   --  more data can be transmitted. Neither transmission nor reception can be
    --  performed with Shut_Read_Write.
 
    type Port_Type is new Natural;
@@ -440,8 +437,8 @@ package GNAT.Sockets is
 
    type Inet_Addr_Type (Family : Family_Type := Family_Inet) is private;
    --  An Internet address depends on an address family (IPv4 contains
-   --  4 octets and Ipv6 contains 16 octets). Any_Inet_Address is a
-   --  special value treated like a wildcard enabling all addresses.
+   --  4 octets and Ipv6 contains 16 octets). Any_Inet_Addr is a special
+   --  value treated like a wildcard enabling all addresses.
    --  No_Inet_Addr provides a special value to denote uninitialized
    --  inet addresses.
 
@@ -488,15 +485,13 @@ package GNAT.Sockets is
    --  Return number of addresses in host entry
 
    function Aliases
-     (E    : Host_Entry_Type;
-      N    : Positive := 1)
-      return String;
+     (E : Host_Entry_Type;
+      N : Positive := 1) return String;
    --  Return N'th aliases in host entry. The first index is 1.
 
    function Addresses
-     (E    : Host_Entry_Type;
-      N    : Positive := 1)
-      return Inet_Addr_Type;
+     (E : Host_Entry_Type;
+      N : Positive := 1) return Inet_Addr_Type;
    --  Return N'th addresses in host entry. The first index is 1.
 
    Host_Error : exception;
@@ -506,25 +501,22 @@ package GNAT.Sockets is
 
    function Get_Host_By_Address
      (Address : Inet_Addr_Type;
-      Family  : Family_Type := Family_Inet)
-      return    Host_Entry_Type;
+      Family  : Family_Type := Family_Inet) return Host_Entry_Type;
    --  Return host entry structure for the given inet address
 
    function Get_Host_By_Name
-     (Name : String)
-      return Host_Entry_Type;
+     (Name : String) return Host_Entry_Type;
    --  Return host entry structure for the given host name. Here name
    --  is either a host name, or an IP address.
 
    function Host_Name return String;
    --  Return the name of the current host
 
+   type Service_Entry_Type (Aliases_Length : Natural) is private;
    --  Service entries provide complete information on a given
    --  service: the official name, an array of alternative names or
    --  aliases and the port number.
 
-   type Service_Entry_Type (Aliases_Length : Natural) is private;
-
    function Official_Name (S : Service_Entry_Type) return String;
    --  Return official name in service entry
 
@@ -538,31 +530,29 @@ package GNAT.Sockets is
    --  Return number of aliases in service entry
 
    function Aliases
-     (S    : Service_Entry_Type;
-      N    : Positive := 1)
-      return String;
+     (S : Service_Entry_Type;
+      N : Positive := 1) return String;
    --  Return N'th aliases in service entry. The first index is 1.
 
    function Get_Service_By_Name
      (Name     : String;
-      Protocol : String)
-      return     Service_Entry_Type;
+      Protocol : String) return Service_Entry_Type;
    --  Return service entry structure for the given service name
 
    function Get_Service_By_Port
      (Port     : Port_Type;
-      Protocol : String)
-      return     Service_Entry_Type;
+      Protocol : String) return Service_Entry_Type;
    --  Return service entry structure for the given service port number
 
    Service_Error : exception;
+   --  Comment required ???
 
    --  Errors are described by an enumeration type. There is only one
    --  exception Socket_Error in this package to deal with an error
    --  during a socket routine. Once raised, its message contains the
    --  error code between brackets and a string describing the error code.
 
-   --  The name of the enumeration constant documents the error condition.
+   --  The name of the enumeration constant documents the error condition
 
    type Error_Type is
      (Success,
@@ -665,8 +655,8 @@ package GNAT.Sockets is
 
          when Add_Membership  |
               Drop_Membership =>
-            Multiaddr : Inet_Addr_Type;
-            Interface : Inet_Addr_Type;
+            Multicast_Address : Inet_Addr_Type;
+            Local_Interface   : Inet_Addr_Type;
 
          when Multicast_TTL   =>
             Time_To_Live : Natural;
@@ -786,8 +776,7 @@ package GNAT.Sockets is
    function Get_Socket_Option
      (Socket : Socket_Type;
       Level  : Level_Type := Socket_Level;
-      Name   : Option_Name)
-      return   Option_Type;
+      Name   : Option_Name) return Option_Type;
    --  Get the options associated with a socket. Raises Socket_Error
    --  on error.
 
@@ -830,8 +819,7 @@ package GNAT.Sockets is
    --  elements Vector. Count is set to the count of received stream elements.
 
    function Resolve_Exception
-     (Occurrence : Ada.Exceptions.Exception_Occurrence)
-      return       Error_Type;
+     (Occurrence : Ada.Exceptions.Exception_Occurrence) return Error_Type;
    --  When Socket_Error or Host_Error are raised, the exception
    --  message contains the error code between brackets and a string
    --  describing the error code. Resolve_Error extracts the error
@@ -884,24 +872,20 @@ package GNAT.Sockets is
    --  Same interface as Ada.Streams.Stream_IO
 
    function Stream
-     (Socket : Socket_Type)
-      return   Stream_Access;
+     (Socket : Socket_Type) return Stream_Access;
    --  Create a stream associated with a stream-based socket that is
    --  already connected.
 
    function Stream
      (Socket  : Socket_Type;
-      Send_To : Sock_Addr_Type)
-      return    Stream_Access;
+      Send_To : Sock_Addr_Type) return Stream_Access;
    --  Create a stream associated with a datagram-based socket that is
    --  already bound. Send_To is the socket address to which messages are
    --  being sent.
 
    function Get_Address
-     (Stream : Stream_Access)
-      return   Sock_Addr_Type;
-   --  Return the socket address from which the last message was
-   --  received.
+     (Stream : Stream_Access) return Sock_Addr_Type;
+   --  Return the socket address from which the last message was received.
 
    procedure Free is new Ada.Unchecked_Deallocation
      (Ada.Streams.Root_Stream_Type'Class, Stream_Access);
@@ -930,17 +914,15 @@ package GNAT.Sockets is
    --  No_Socket when the set is empty.
 
    function Is_Empty
-     (Item  : Socket_Set_Type)
-      return  Boolean;
-   --  Return True if Item is empty
+     (Item : Socket_Set_Type) return Boolean;
+   --  Return True iff Item is empty
 
    function Is_Set
      (Item   : Socket_Set_Type;
-      Socket : Socket_Type)
-      return   Boolean;
-   --  Return True if Socket is present in Item
+      Socket : Socket_Type) return Boolean;
+   --  Return True iff Socket is present in Item
 
-   procedure Set   (Item : in out Socket_Set_Type; Socket : Socket_Type);
+   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
index 9600cda64285dbd76228f6f43d87b4b80e789b4f..26c5e627491640922951f9c5a1c6003802649ee8 100644 (file)
@@ -61,10 +61,13 @@ package body GNAT.Sockets.Thin is
    --  two attempts on a blocking operation.
 
    Thread_Blocking_IO : Boolean := True;
+   --  Comment required for this ???
 
    Unknown_System_Error : constant C.Strings.chars_ptr :=
                             C.Strings.New_String ("Unknown system error");
 
+   --  Comments required for following functions ???
+
    function Syscall_Accept
      (S       : C.int;
       Addr    : System.Address;
@@ -121,6 +124,9 @@ package body GNAT.Sockets.Thin is
       Protocol : C.int) return C.int;
    pragma Import (C, Syscall_Socket, "socket");
 
+   procedure Disable_SIGPIPE (S : C.int);
+   pragma Import (C, Disable_SIGPIPE, "__gnat_disable_sigpipe");
+
    function  Non_Blocking_Socket (S : C.int) return Boolean;
    procedure Set_Non_Blocking_Socket (S : C.int; V : Boolean);
 
@@ -160,6 +166,7 @@ package body GNAT.Sockets.Thin is
          Discard := Syscall_Ioctl (R, Constants.FIONBIO, Val'Unchecked_Access);
       end if;
 
+      Disable_SIGPIPE (R);
       return R;
    end C_Accept;
 
@@ -377,7 +384,7 @@ package body GNAT.Sockets.Thin is
          Discard := Syscall_Ioctl (R, Constants.FIONBIO, Val'Unchecked_Access);
          Set_Non_Blocking_Socket (R, False);
       end if;
-
+      Disable_SIGPIPE (R);
       return R;
    end C_Socket;
 
index 89b8163fada68e02e282eb2acc2e9a40477e523f..6f5067fcabecf69848b4960e55fe887152c55000 100644 (file)
 #include "system.h"
 #endif
 
+#if !(defined (VMS) || defined (__MINGW32__))
+# include <sys/socket.h>
+#endif
+
 #include "raise.h"
 
+extern void __gnat_disable_sigpipe (int fd);
 extern void __gnat_free_socket_set (fd_set *);
 extern void __gnat_last_socket_in_set (fd_set *, int *);
 extern void __gnat_get_socket_from_set (fd_set *, int *, int *);
@@ -74,6 +79,16 @@ extern int __gnat_is_socket_in_set (fd_set *, int);
 extern fd_set *__gnat_new_socket_set (fd_set *);
 extern void __gnat_remove_socket_from_set (fd_set *, int);
 \f
+/* Disable the sending of SIGPIPE for writes on a broken stream */
+void
+__gnat_disable_sigpipe (int fd)
+{
+#ifdef SO_NOSIGPIPE
+  int val = 1;
+  (void) setsockopt (fd, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof val);
+#endif
+}
+
 /* Free socket set. */
 
 void