----------------------------------------------------------------------------- -- -- -- ADASOCKETS COMPONENTS -- -- -- -- S O C K E T S . T H I N -- -- -- -- B o d y -- -- -- -- $ReleaseVersion:$ -- -- -- -- Copyright (C) 1998,1999 Samuel Tardieu -- -- Copyright (C) 2001 Maxim Reznik -- -- Copyright (C) 1999-2003 ENST http://www.enst.fr/ -- -- -- -- AdaSockets is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by -- -- the Free Software Foundation; either version 2, or (at your option) -- -- any later version. AdaSockets is distributed in the hope that it -- -- will be useful, but WITHOUT 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 AdaSockets; see file COPYING. If not, write to the Free -- -- Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- -- 02111-1307, USA. -- -- -- -- 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. -- -- -- -- The main repository for this software is located at: -- -- http://www.rfc1149.net/devel/adasockets -- -- -- -- If you have any question, please send a mail to -- -- Samuel Tardieu -- -- -- ----------------------------------------------------------------------------- -- Platform specific file for OpenVMS -- -- -- -- Based on Windows specific file written -- -- by Maxim Reznik -- ----------------------------------------------------------------------------- with Sockets.Constants; with System.Address_To_Access_Conversions; package body Sockets.Thin is use type System.Address; package Int_Conversion is new System.Address_To_Access_Conversions (C.int); ------------------ -- C_Socketpair -- ------------------ function C_Socketpair (Domain : C.int; Typ : C.int; Protocol : C.int; Filedes : System.Address) return C.int is use System.Storage_Elements; use type C.char_array; INVALID_SOCKET : constant := Failure; Listen_Socket : C.int; Sin : aliased Sockaddr_In; Sin_Len : aliased C.int := Sin'Size / 8; fd : Two_Int; fd_ptr : Int_Conversion.Object_Pointer; Result : C.int; begin if Domain /= Constants.Af_Inet or Typ /= Constants.Sock_Stream or Filedes = System.Null_Address then return Failure; end if; Listen_Socket := C_Socket (Domain, Typ, Protocol); if Listen_Socket = INVALID_SOCKET then return Failure; end if; Sin.Sin_Family := Constants.Af_Inet; Sin.Sin_Addr := Inaddr_Any; Sin.Sin_Port := 0; if C_Bind (Listen_Socket, Sin'Address, Sin'Size / 8) = Failure then Result := C_Close (Listen_Socket); return Failure; end if; if C_Listen (Listen_Socket, 1) = Failure then Result := C_Close (Listen_Socket); return Failure; end if; if C_Getsockname (Listen_Socket, Sin'Address, Sin_Len'Access) = Failure then Result := C_Close (Listen_Socket); return Failure; end if; Sin.Sin_Addr := (127, 0, 0, 1); fd (1) := C_Socket (Domain, Typ, Protocol); if fd (1) = INVALID_SOCKET then Result := C_Close (Listen_Socket); return Failure; end if; if C_Connect (fd (1), Sin'Address, Sin'Size / 8) = Failure then Result := C_Close (fd (1)); Result := C_Close (Listen_Socket); return Failure; end if; fd (0) := C_Accept (Listen_Socket, Sin'Address, Sin_Len'Access); if fd (0) = INVALID_SOCKET then Result := C_Close (fd (1)); Result := C_Close (Listen_Socket); return Failure; end if; fd_ptr := Int_Conversion.To_Pointer (Filedes); fd_ptr.all := fd (0); fd_ptr := Int_Conversion.To_Pointer (Filedes + (C.int'Size / 8)); fd_ptr.all := fd (1); return Success; end C_Socketpair; end Sockets.Thin;