| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- G N A T . S O C K E T S . T H I N . S I G N A L L I N G _ F D S -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2001-2025, AdaCore -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. -- |
| 17 |
-- -- |
| 18 |
-- As a special exception under Section 7 of GPL version 3, you are granted -- |
| 19 |
-- additional permissions described in the GCC Runtime Library Exception, -- |
| 20 |
-- version 3.1, as published by the Free Software Foundation. -- |
| 21 |
-- -- |
| 22 |
-- You should have received a copy of the GNU General Public License and -- |
| 23 |
-- a copy of the GCC Runtime Library Exception along with this program; -- |
| 24 |
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- |
| 25 |
-- <http://www.gnu.org/licenses/>. -- |
| 26 |
-- -- |
| 27 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 28 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 29 |
-- -- |
| 30 |
------------------------------------------------------------------------------ |
| 31 |
|
| 32 |
-- Portable sockets-based implementation of GNAT.Sockets.Thin.Signalling_Fds |
| 33 |
-- used for platforms that do not support UNIX pipes. |
| 34 |
|
| 35 |
-- Note: this code used to be in GNAT.Sockets, but has been moved to a |
| 36 |
-- platform-specific file. It is now used only for non-UNIX platforms. |
| 37 |
|
| 38 |
separate (GNAT.Sockets.Thin) |
| 39 |
package body Signalling_Fds is |
| 40 |
|
| 41 |
----------- |
| 42 |
-- Close -- |
| 43 |
----------- |
| 44 |
|
| 45 |
procedure Close (Sig : C.int) is |
| 46 |
Res : C.int; |
| 47 |
pragma Unreferenced (Res); |
| 48 |
-- Res is assigned but never read, because we purposefully ignore |
| 49 |
-- any error returned by the C_Close system call, as per the spec |
| 50 |
-- of this procedure. |
| 51 |
begin |
| 52 |
Res := C_Close (Sig); |
| 53 |
end Close; |
| 54 |
|
| 55 |
------------ |
| 56 |
-- Create -- |
| 57 |
------------ |
| 58 |
|
| 59 |
function Create (Fds : not null access Fd_Pair) return C.int is |
| 60 |
Res : constant C.int := |
| 61 |
C_Socketpair (SOSC.AF_INET, SOSC.SOCK_STREAM, 0, Fds); |
| 62 |
begin |
| 63 |
if Res /= Failure then |
| 64 |
-- Set TCP_NODELAY on Fds (Write_End), since we always want to send |
| 65 |
-- the data out immediately. |
| 66 |
|
| 67 |
Set_Socket_Option |
| 68 |
(Socket => Socket_Type (Fds (Write_End)), |
| 69 |
Level => IP_Protocol_For_TCP_Level, |
| 70 |
Option => (Name => No_Delay, Enabled => True)); |
| 71 |
end if; |
| 72 |
|
| 73 |
return Res; |
| 74 |
end Create; |
| 75 |
|
| 76 |
---------- |
| 77 |
-- Read -- |
| 78 |
---------- |
| 79 |
|
| 80 |
function Read (Rsig : C.int) return C.int is |
| 81 |
Buf : aliased Character; |
| 82 |
begin |
| 83 |
return C_Recv (Rsig, Buf'Address, 1, SOSC.MSG_Forced_Flags); |
| 84 |
end Read; |
| 85 |
|
| 86 |
----------- |
| 87 |
-- Write -- |
| 88 |
----------- |
| 89 |
|
| 90 |
function Write (Wsig : C.int) return C.int is |
| 91 |
Buf : aliased Character := ASCII.NUL; |
| 92 |
begin |
| 93 |
return C_Sendto |
| 94 |
(Wsig, Buf'Address, 1, |
| 95 |
Flags => SOSC.MSG_Forced_Flags, |
| 96 |
To => System.Null_Address, |
| 97 |
Tolen => 0); |
| 98 |
end Write; |
| 99 |
|
| 100 |
end Signalling_Fds; |