OSDN Git Service

* gcc-interface/Makefile.in (INCLUDES_FOR_SUBDIR): Add $(fsrcdir) by
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-socthi.ads
index 7a4d7e4..15747cf 100644 (file)
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---                                                                          --
---              Copyright (C) 2001 Ada Core Technologies, Inc.              --
+--                     Copyright (C) 2001-2010, AdaCore                     --
 --                                                                          --
 -- 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- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
--- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
--- MA 02111-1307, USA.                                                      --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
 --                                                                          --
--- As a special exception,  if other files  instantiate  generics from this --
--- unit, or you link  this unit with other files  to produce an executable, --
--- this  unit  does not  by itself cause  the resulting  executable  to  be --
--- covered  by the  GNU  General  Public  License.  This exception does not --
--- however invalidate  any other reasons why  the executable file  might be --
--- covered by the  GNU Public License.                                      --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
 --                                                                          --
--- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com).   --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Interfaces.C.Pointers;
+--  This package provides a target dependent thin interface to the sockets
+--  layer for use by the GNAT.Sockets package (g-socket.ads). This package
+--  should not be directly with'ed by an applications program.
+
+--  This is the default version
 
 with Interfaces.C.Strings;
-with GNAT.Sockets.Constants;
+
 with GNAT.OS_Lib;
+with GNAT.Sockets.Thin_Common;
 
 with System;
+with System.CRTL;
 
 package GNAT.Sockets.Thin is
 
-   --  ??? more comments needed ???
-
    --  This package is intended for hosts implementing BSD sockets with a
    --  standard interface. It will be used as a default for all the platforms
    --  that do not have a specific version of this file.
 
-   package C renames Interfaces.C;
+   use Thin_Common;
 
-   use type C.int;
-   --  This is so we can declare the Failure constant below
+   package C renames Interfaces.C;
 
-   Success : constant C.int :=  0;
-   Failure : constant C.int := -1;
+   use type System.CRTL.ssize_t;
 
    function Socket_Errno return Integer renames GNAT.OS_Lib.Errno;
-   --  Returns last socket error number.
-
-   function Socket_Error_Message (Errno : Integer) return String;
-   --  Returns the error message string for the error number Errno. If
-   --  Errno is not known it returns "Unknown system error".
-
-   type Fd_Set is mod 2 ** 32;
-   pragma Convention (C, Fd_Set);
-
-   Null_Fd_Set : constant Fd_Set := 0;
-
-   type Fd_Set_Access is access all Fd_Set;
-   pragma Convention (C, Fd_Set_Access);
-
-   type Timeval_Unit is new C.int;
-   pragma Convention (C, Timeval_Unit);
-
-   type Timeval is record
-      Tv_Sec  : Timeval_Unit;
-      Tv_Usec : Timeval_Unit;
-   end record;
-   pragma Convention (C, Timeval);
-
-   type Timeval_Access is access all Timeval;
-   pragma Convention (C, Timeval_Access);
-
-   Immediat : constant Timeval := (0, 0);
-
-   type Int_Access is access all C.int;
-   pragma Convention (C, Int_Access);
-   --  Access to C integers
-
-   type Chars_Ptr_Array is array (C.size_t range <>) of
-     aliased C.Strings.chars_ptr;
-
-   package Chars_Ptr_Pointers is
-      new C.Pointers (C.size_t, C.Strings.chars_ptr, Chars_Ptr_Array,
-                      C.Strings.Null_Ptr);
-   --  Arrays of C (char *)
-
-   type In_Addr is record
-      S_B1, S_B2, S_B3, S_B4 : C.unsigned_char;
-   end record;
-   pragma Convention (C, In_Addr);
-   --  Internet address
-
-   type In_Addr_Access is access all In_Addr;
-   pragma Convention (C, In_Addr_Access);
-   --  Access to internet address
-
-   Inaddr_Any : aliased constant In_Addr := (others => 0);
-   --  Any internet address (all the interfaces)
-
-   type In_Addr_Access_Array is array (C.size_t range <>)
-     of aliased In_Addr_Access;
-   pragma Convention (C, In_Addr_Access_Array);
-
-   package In_Addr_Access_Pointers is
-     new C.Pointers (C.size_t, In_Addr_Access, In_Addr_Access_Array, null);
-   --  Array of internet addresses
-
-   type Sockaddr is record
-      Sa_Family : C.unsigned_short;
-      Sa_Data   : C.char_array (1 .. 14);
-   end record;
-   pragma Convention (C, Sockaddr);
-   --  Socket address
-
-   type Sockaddr_Access is access all Sockaddr;
-   pragma Convention (C, Sockaddr_Access);
-   --  Access to socket address
-
-   type Sockaddr_In is record
-      Sin_Family : C.unsigned_short      := Constants.AF_INET;
-      Sin_Port   : C.unsigned_short      := 0;
-      Sin_Addr   : In_Addr               := Inaddr_Any;
-      Sin_Zero   : C.char_array (1 .. 8) := (others => C.char'Val (0));
-   end record;
-   pragma Convention (C, Sockaddr_In);
-   --  Internet socket address
-
-   type Sockaddr_In_Access is access all Sockaddr_In;
-   pragma Convention (C, Sockaddr_In_Access);
-   --  Access to internet socket address
-
-   type Hostent is record
-      H_Name      : C.Strings.chars_ptr;
-      H_Aliases   : Chars_Ptr_Pointers.Pointer;
-      H_Addrtype  : C.int;
-      H_Length    : C.int;
-      H_Addr_List : In_Addr_Access_Pointers.Pointer;
-   end record;
-   pragma Convention (C, Hostent);
-   --  Host entry
-
-   type Hostent_Access is access all Hostent;
-   pragma Convention (C, Hostent_Access);
-   --  Access to host entry
-
-   type Two_Int is array (0 .. 1) of C.int;
-   pragma Convention (C, Two_Int);
-   --  Used with pipe()
+   --  Returns last socket error number
+
+   function Socket_Error_Message (Errno : Integer) return C.Strings.chars_ptr;
+   --  Returns the error message string for the error number Errno. If Errno is
+   --  not known, returns "Unknown system error".
+
+   function Host_Errno return Integer;
+   pragma Import (C, Host_Errno, "__gnat_get_h_errno");
+   --  Returns last host error number
+
+   package Host_Error_Messages is
+
+      function Host_Error_Message
+        (H_Errno : Integer) return C.Strings.chars_ptr;
+      --  Returns the error message string for the host error number H_Errno.
+      --  If H_Errno is not known, returns "Unknown system error".
+
+   end Host_Error_Messages;
+
+   --------------------------------
+   -- Standard library functions --
+   --------------------------------
 
    function C_Accept
      (S       : C.int;
       Addr    : System.Address;
-      Addrlen : access C.int)
-      return    C.int;
+      Addrlen : not null access C.int) return C.int;
 
    function C_Bind
      (S       : C.int;
       Name    : System.Address;
-      Namelen : C.int)
-      return    C.int;
+      Namelen : C.int) return C.int;
 
    function C_Close
-     (Fd   : C.int)
-      return C.int;
+     (Fd : C.int) return C.int;
 
    function C_Connect
      (S       : C.int;
       Name    : System.Address;
-      Namelen : C.int)
-      return    C.int;
-
-   function C_Gethostbyaddr
-     (Addr : System.Address;
-      Len  : C.int;
-      Typ  : C.int)
-      return Hostent_Access;
-
-   function C_Gethostbyname
-     (Name : C.char_array)
-      return Hostent_Access;
+      Namelen : C.int) return C.int;
 
    function C_Gethostname
      (Name    : System.Address;
-      Namelen : C.int)
-      return    C.int;
+      Namelen : C.int) return C.int;
 
    function C_Getpeername
      (S       : C.int;
       Name    : System.Address;
-      Namelen : access C.int)
-      return    C.int;
+      Namelen : not null access C.int) return C.int;
 
    function C_Getsockname
      (S       : C.int;
       Name    : System.Address;
-      Namelen : access C.int)
-      return    C.int;
+      Namelen : not null access C.int) return C.int;
 
    function C_Getsockopt
      (S       : C.int;
       Level   : C.int;
       Optname : C.int;
       Optval  : System.Address;
-      Optlen  : access C.int)
-      return    C.int;
-
-   function C_Inet_Addr
-     (Cp   : C.Strings.chars_ptr)
-      return C.int;
+      Optlen  : not null access C.int) return C.int;
 
-   function C_Ioctl
-     (S    : C.int;
-      Req  : C.int;
-      Arg  : Int_Access)
-      return C.int;
+   function Socket_Ioctl
+     (S   : C.int;
+      Req : C.int;
+      Arg : access C.int) return C.int;
 
-   function C_Listen (S, Backlog : C.int) return C.int;
-
-   function C_Read
-     (Fd    : C.int;
-      Buf   : System.Address;
-      Count : C.int)
-      return  C.int;
+   function C_Listen
+     (S       : C.int;
+      Backlog : C.int) return C.int;
 
    function C_Recv
      (S     : C.int;
       Msg   : System.Address;
       Len   : C.int;
-      Flags : C.int)
-      return  C.int;
+      Flags : C.int) return C.int;
 
    function C_Recvfrom
      (S       : C.int;
       Msg     : System.Address;
       Len     : C.int;
       Flags   : C.int;
-      From    : Sockaddr_In_Access;
-      Fromlen : access C.int)
-      return    C.int;
+      From    : System.Address;
+      Fromlen : not null access C.int) return C.int;
+
+   function C_Recvmsg
+     (S     : C.int;
+      Msg   : System.Address;
+      Flags : C.int) return System.CRTL.ssize_t;
 
    function C_Select
      (Nfds      : C.int;
-      Readfds   : Fd_Set_Access;
-      Writefds  : Fd_Set_Access;
-      Exceptfds : Fd_Set_Access;
-      Timeout   : Timeval_Access)
-      return      C.int;
+      Readfds   : access Fd_Set;
+      Writefds  : access Fd_Set;
+      Exceptfds : access Fd_Set;
+      Timeout   : Timeval_Access) return C.int;
 
-   function C_Send
+   function C_Sendmsg
      (S     : C.int;
       Msg   : System.Address;
-      Len   : C.int;
-      Flags : C.int)
-      return  C.int;
+      Flags : C.int) return System.CRTL.ssize_t;
 
    function C_Sendto
      (S     : C.int;
       Msg   : System.Address;
       Len   : C.int;
       Flags : C.int;
-      To    : Sockaddr_In_Access;
-      Tolen : C.int)
-      return  C.int;
+      To    : System.Address;
+      Tolen : C.int) return C.int;
 
    function C_Setsockopt
      (S       : C.int;
       Level   : C.int;
       Optname : C.int;
       Optval  : System.Address;
-      Optlen  : C.int)
-      return    C.int;
+      Optlen  : C.int) return C.int;
 
    function C_Shutdown
-     (S    : C.int;
-      How  : C.int)
-      return C.int;
+     (S   : C.int;
+      How : C.int) return C.int;
 
    function C_Socket
      (Domain   : C.int;
       Typ      : C.int;
-      Protocol : C.int)
-      return     C.int;
-
-   function C_Strerror
-     (Errnum : C.int)
-      return   C.Strings.chars_ptr;
+      Protocol : C.int) return C.int;
 
    function C_System
-     (Command : System.Address)
-      return    C.int;
+     (Command : System.Address) return C.int;
+
+   -------------------------------------------------------
+   -- Signalling file descriptors for selector abortion --
+   -------------------------------------------------------
+
+   package Signalling_Fds is
+
+      function Create (Fds : not null access Fd_Pair) return C.int;
+      pragma Convention (C, Create);
+      --  Create a pair of connected descriptors suitable for use with C_Select
+      --  (used for signalling in Selector objects).
+
+      function Read (Rsig : C.int) return C.int;
+      pragma Convention (C, Read);
+      --  Read one byte of data from rsig, the read end of a pair of signalling
+      --  fds created by Create_Signalling_Fds.
 
-   function C_Write
-     (Fd    : C.int;
-      Buf   : System.Address;
-      Count : C.int)
-      return  C.int;
+      function Write (Wsig : C.int) return C.int;
+      pragma Convention (C, Write);
+      --  Write one byte of data to wsig, the write end of a pair of signalling
+      --  fds created by Create_Signalling_Fds.
 
-   --  Return highest numbered socket (what does this refer to???)
+      procedure Close (Sig : C.int);
+      pragma Convention (C, Close);
+      --  Close one end of a pair of signalling fds (ignoring any error)
 
-   procedure Clear    (Item : in out Fd_Set; Socket : in C.int);
-   procedure Empty    (Item : in out Fd_Set);
-   function  Is_Empty (Item : Fd_Set) return Boolean;
-   function  Is_Set   (Item : Fd_Set; Socket : C.int) return Boolean;
-   function  Max      (Item : Fd_Set) return C.int;
-   procedure Set      (Item : in out Fd_Set; Socket : in C.int);
+   end Signalling_Fds;
 
+   -------------------------------------------
+   -- Nonreentrant network databases access --
+   -------------------------------------------
+
+   --  The following are used only on systems that have nonreentrant
+   --  getXXXbyYYY functions, and do NOT have corresponding getXXXbyYYY_
+   --  functions. Currently, LynxOS is the only such system.
+
+   function Nonreentrant_Gethostbyname
+     (Name : C.char_array) return Hostent_Access;
+
+   function Nonreentrant_Gethostbyaddr
+     (Addr      : System.Address;
+      Addr_Len  : C.int;
+      Addr_Type : C.int) return Hostent_Access;
+
+   function Nonreentrant_Getservbyname
+     (Name  : C.char_array;
+      Proto : C.char_array) return Servent_Access;
+
+   function Nonreentrant_Getservbyport
+     (Port  : C.int;
+      Proto : C.char_array) return Servent_Access;
+
+   procedure Initialize;
    procedure Finalize;
-   procedure Initialize (Process_Blocking_IO : Boolean);
 
 private
-
    pragma Import (C, C_Bind, "bind");
    pragma Import (C, C_Close, "close");
-   pragma Import (C, C_Gethostbyaddr, "gethostbyaddr");
-   pragma Import (C, C_Gethostbyname, "gethostbyname");
    pragma Import (C, C_Gethostname, "gethostname");
    pragma Import (C, C_Getpeername, "getpeername");
    pragma Import (C, C_Getsockname, "getsockname");
    pragma Import (C, C_Getsockopt, "getsockopt");
-   pragma Import (C, C_Inet_Addr, "inet_addr");
    pragma Import (C, C_Listen, "listen");
-   pragma Import (C, C_Read, "read");
    pragma Import (C, C_Select, "select");
    pragma Import (C, C_Setsockopt, "setsockopt");
    pragma Import (C, C_Shutdown, "shutdown");
-   pragma Import (C, C_Strerror, "strerror");
    pragma Import (C, C_System, "system");
-   pragma Import (C, C_Write, "write");
+
+   pragma Import (C, Nonreentrant_Gethostbyname, "gethostbyname");
+   pragma Import (C, Nonreentrant_Gethostbyaddr, "gethostbyaddr");
+   pragma Import (C, Nonreentrant_Getservbyname, "getservbyname");
+   pragma Import (C, Nonreentrant_Getservbyport, "getservbyport");
 
 end GNAT.Sockets.Thin;