Commit 41cbab34 by Vincent Celier Committed by Arnaud Charlet

2004-10-26 Vincent Celier <celier@gnat.com>

	    Thomas Quinot   <quinot@act-europe.fr>

	* g-socthi-vms.adb, g-socthi-mingw.adb, g-socthi-vxworks.ads:
	(C_Writev): Change MSG_Forced_Flags to Constants.MSG_Forced_Flags as
	there is no use of GNAT.Sockets.Constants.
	Remove remaining pragma Import for C_Write
	Remove C_Read and C_Write from internal implementation unit
	GNAT.Sockets.Thin, as their usage for sockets is non-portable (using
	the read and write functions from the system runtime library is fine
	on UNIX but won't work under Windows).

	* g-socket.adb: (Abort_Selector): Use C_Send instead of C_Write.
	(Check_Selector): Use C_Recv instead of C_Read.
	Selectors are the GNAT.Sockets abstraction to perform a select()
	call on a set of descriptors. To allow abortion of an ongoing
	select operation, some data is written to a dedicated socket that
	is always monitored.
	Under Windows, the write and read library functions cannot operate
	on sockets, so we need to use send and recv instead, which is portable
	across all supported platforms.

	* g-socthi.ads: Remove C_Read and C_Write from internal implementation
	unit GNAT.Sockets.Thin, as their usage for sockets is non-portable
	(using the read and write functions from the system runtime library is
	fine on UNIX but won't work under Windows).

From-SVN: r89638
parent 6bfad5e1
...@@ -226,14 +226,17 @@ package body GNAT.Sockets is ...@@ -226,14 +226,17 @@ package body GNAT.Sockets is
-------------------- --------------------
procedure Abort_Selector (Selector : Selector_Type) is procedure Abort_Selector (Selector : Selector_Type) is
Buf : aliased Character := ASCII.NUL; Buf : aliased Character := ASCII.NUL;
Discard : C.int; Res : C.int;
pragma Unreferenced (Discard);
begin begin
-- Send an empty array to unblock C select system call -- Send an empty array to unblock C select system call
Discard := C_Write (C.int (Selector.W_Sig_Socket), Buf'Address, 1); Res := C_Send (C.int (Selector.W_Sig_Socket), Buf'Address, 1,
Constants.MSG_Forced_Flags);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
end Abort_Selector; end Abort_Selector;
------------------- -------------------
...@@ -440,8 +443,13 @@ package body GNAT.Sockets is ...@@ -440,8 +443,13 @@ package body GNAT.Sockets is
declare declare
Buf : Character; Buf : Character;
begin begin
Res := C_Read (C.int (Selector.R_Sig_Socket), Buf'Address, 1); Res := C_Recv (C.int (Selector.R_Sig_Socket), Buf'Address, 1, 0);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
end if;
end; end;
Status := Aborted; Status := Aborted;
......
...@@ -318,7 +318,7 @@ package body GNAT.Sockets.Thin is ...@@ -318,7 +318,7 @@ package body GNAT.Sockets.Thin is
-- POSIX compatitibility, copy write fd set into exception fd -- POSIX compatitibility, copy write fd set into exception fd
-- set. Once select() returns, check any socket present in the -- set. Once select() returns, check any socket present in the
-- exception fd set and peek at incoming out-of-band data. If -- exception fd set and peek at incoming out-of-band data. If
-- the test is not successfull and if the socket is present in -- the test is not successful, and the socket is present in
-- the initial write fd set, then move the socket from the -- the initial write fd set, then move the socket from the
-- exception fd set to the write fd set. -- exception fd set to the write fd set.
......
...@@ -502,10 +502,11 @@ package body GNAT.Sockets.Thin is ...@@ -502,10 +502,11 @@ package body GNAT.Sockets.Thin is
begin begin
for J in Iovec'Range loop for J in Iovec'Range loop
Res := C_Read Res := C_Recv
(Fd, (Fd,
Iovec (J).Base.all'Address, Iovec (J).Base.all'Address,
Interfaces.C.int (Iovec (J).Length)); Interfaces.C.int (Iovec (J).Length),
0);
if Res < 0 then if Res < 0 then
return Res; return Res;
...@@ -534,10 +535,11 @@ package body GNAT.Sockets.Thin is ...@@ -534,10 +535,11 @@ package body GNAT.Sockets.Thin is
begin begin
for J in Iovec'Range loop for J in Iovec'Range loop
Res := C_Write Res := C_Send
(Fd, (Fd,
Iovec (J).Base.all'Address, Iovec (J).Base.all'Address,
Interfaces.C.int (Iovec (J).Length)); Interfaces.C.int (Iovec (J).Length),
Constants.MSG_Forced_Flags);
if Res < 0 then if Res < 0 then
return Res; return Res;
......
...@@ -275,12 +275,6 @@ package GNAT.Sockets.Thin is ...@@ -275,12 +275,6 @@ package GNAT.Sockets.Thin is
function C_Listen (S, Backlog : 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_Readv function C_Readv
(Fd : C.int; (Fd : C.int;
Iov : System.Address; Iov : System.Address;
...@@ -354,12 +348,6 @@ package GNAT.Sockets.Thin is ...@@ -354,12 +348,6 @@ package GNAT.Sockets.Thin is
(Command : System.Address) (Command : System.Address)
return C.int; return C.int;
function C_Write
(Fd : C.int;
Buf : System.Address;
Count : C.int)
return C.int;
function C_Writev function C_Writev
(Fd : C.int; (Fd : C.int;
Iov : System.Address; Iov : System.Address;
...@@ -425,14 +413,12 @@ private ...@@ -425,14 +413,12 @@ private
pragma Import (C, C_Getsockopt, "getsockopt"); pragma Import (C, C_Getsockopt, "getsockopt");
pragma Import (C, C_Inet_Addr, "inet_addr"); pragma Import (C, C_Inet_Addr, "inet_addr");
pragma Import (C, C_Listen, "listen"); pragma Import (C, C_Listen, "listen");
pragma Import (C, C_Read, "read");
pragma Import (C, C_Readv, "readv"); pragma Import (C, C_Readv, "readv");
pragma Import (C, C_Select, "select"); pragma Import (C, C_Select, "select");
pragma Import (C, C_Setsockopt, "setsockopt"); pragma Import (C, C_Setsockopt, "setsockopt");
pragma Import (C, C_Shutdown, "shutdown"); pragma Import (C, C_Shutdown, "shutdown");
pragma Import (C, C_Strerror, "strerror"); pragma Import (C, C_Strerror, "strerror");
pragma Import (C, C_System, "system"); pragma Import (C, C_System, "system");
pragma Import (C, C_Write, "write");
pragma Import (C, C_Writev, "writev"); pragma Import (C, C_Writev, "writev");
pragma Import (C, Free_Socket_Set, "__gnat_free_socket_set"); pragma Import (C, Free_Socket_Set, "__gnat_free_socket_set");
......
...@@ -262,11 +262,6 @@ package GNAT.Sockets.Thin is ...@@ -262,11 +262,6 @@ package GNAT.Sockets.Thin is
(S : C.int; (S : C.int;
Backlog : C.int) return C.int; Backlog : C.int) return C.int;
function C_Read
(Fd : C.int;
Buf : System.Address;
Count : C.int) return C.int;
function C_Readv function C_Readv
(Fd : C.int; (Fd : C.int;
Iov : System.Address; Iov : System.Address;
...@@ -329,11 +324,6 @@ package GNAT.Sockets.Thin is ...@@ -329,11 +324,6 @@ package GNAT.Sockets.Thin is
function C_System function C_System
(Command : System.Address) return C.int; (Command : System.Address) return C.int;
function C_Write
(Fd : C.int;
Buf : System.Address;
Count : C.int) return C.int;
function C_Writev function C_Writev
(Fd : C.int; (Fd : C.int;
Iov : System.Address; Iov : System.Address;
...@@ -400,14 +390,12 @@ private ...@@ -400,14 +390,12 @@ private
pragma Import (C, C_Getsockopt, "getsockopt"); pragma Import (C, C_Getsockopt, "getsockopt");
pragma Import (C, C_Inet_Addr, "inet_addr"); pragma Import (C, C_Inet_Addr, "inet_addr");
pragma Import (C, C_Listen, "listen"); pragma Import (C, C_Listen, "listen");
pragma Import (C, C_Read, "read");
pragma Import (C, C_Readv, "readv"); pragma Import (C, C_Readv, "readv");
pragma Import (C, C_Select, "select"); pragma Import (C, C_Select, "select");
pragma Import (C, C_Setsockopt, "setsockopt"); pragma Import (C, C_Setsockopt, "setsockopt");
pragma Import (C, C_Shutdown, "shutdown"); pragma Import (C, C_Shutdown, "shutdown");
pragma Import (C, C_Strerror, "strerror"); pragma Import (C, C_Strerror, "strerror");
pragma Import (C, C_System, "system"); pragma Import (C, C_System, "system");
pragma Import (C, C_Write, "write");
pragma Import (C, C_Writev, "writev"); pragma Import (C, C_Writev, "writev");
pragma Import (C, Free_Socket_Set, "__gnat_free_socket_set"); pragma Import (C, Free_Socket_Set, "__gnat_free_socket_set");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment