1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . S O C K E T S . P O L L . W A I T --
9 -- Copyright (C) 2020-2023, AdaCore --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- Wait implementation on top of posix select call
34 with GNAT
.Sockets
.Poll
.G_Wait
;
36 separate (GNAT
.Sockets
.Poll
)
39 (Fds
: in out Set
; Timeout
: Interfaces
.C
.int
; Result
: out Integer)
43 function Get_Max_FD
return FD_Type
;
44 -- Check is Max_FD is actual and correct it if necessary
46 type FD_Set_Type
is array (0 .. Get_Max_FD
/ C
.long
'Size) of C
.long
49 procedure Reset_Socket_Set
(Set
: in out FD_Set_Type
);
50 -- Use own FD_ZERO routine because FD_Set_Type size depend on Fds.Max_FD
52 procedure Insert_Socket_In_Set
(Set
: in out FD_Set_Type
; FD
: FD_Type
)
53 with Import
, Convention
=> C
,
54 External_Name
=> "__gnat_insert_socket_in_set";
56 function Is_Socket_In_Set
(Set
: FD_Set_Type
; FD
: FD_Type
) return C
.int
57 with Import
, Convention
=> C
,
58 External_Name
=> "__gnat_is_socket_in_set";
60 procedure Reset_Socket_Set
(Set
: in out FD_Set_Type
) is
65 procedure Poll
is new G_Wait
66 (FD_Set_Type
, Reset_Socket_Set
, Insert_Socket_In_Set
, Is_Socket_In_Set
);
72 function Get_Max_FD
return FD_Type
is
74 if not Fds
.Max_OK
then
75 Fds
.Max_FD
:= Fds
.Fds
(Fds
.Fds
'First).Socket
;
77 for J
in Fds
.Fds
'First + 1 .. Fds
.Length
loop
78 if Fds
.Max_FD
< Fds
.Fds
(J
).Socket
then
79 Fds
.Max_FD
:= Fds
.Fds
(J
).Socket
;
90 Poll
(Fds
, Timeout
, Result
);