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 Windows select call
34 -- Microsoft Windows from Vista version has WSAPoll function in API which is
35 -- similar to POSIX poll call, but experiments show that the WSAPoll is much
36 -- slower than select at least in Windows version 10.0.18363.1016.
38 with GNAT
.Sockets
.Poll
.G_Wait
;
40 separate (GNAT
.Sockets
.Poll
)
43 (Fds
: in out Set
; Timeout
: Interfaces
.C
.int
; Result
: out Integer)
47 type FD_Array
is array (1 .. Fds
.Length
) of FD_Type
50 type FD_Set_Type
is record
53 end record with Convention
=> C
;
55 procedure Reset_Socket_Set
(Set
: in out FD_Set_Type
) with Inline
;
57 procedure Insert_Socket_In_Set
(Set
: in out FD_Set_Type
; FD
: FD_Type
)
60 function Is_Socket_In_Set
(Set
: FD_Set_Type
; FD
: FD_Type
) return C
.int
61 with Import
, Convention
=> C
,
62 External_Name
=> "__gnat_is_socket_in_set";
64 --------------------------
65 -- Insert_Socket_In_Set --
66 --------------------------
68 procedure Insert_Socket_In_Set
(Set
: in out FD_Set_Type
; FD
: FD_Type
) is
70 Set
.Count
:= Set
.Count
+ 1;
71 Set
.Set
(Integer (Set
.Count
)) := FD
;
72 end Insert_Socket_In_Set
;
74 ----------------------
75 -- Reset_Socket_Set --
76 ----------------------
78 procedure Reset_Socket_Set
(Set
: in out FD_Set_Type
) is
87 procedure Poll
is new G_Wait
88 (FD_Set_Type
, Reset_Socket_Set
, Insert_Socket_In_Set
, Is_Socket_In_Set
);
91 Poll
(Fds
, Timeout
, Result
);