| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- G N A T . S O C K E T S . T H I N -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 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 |
-- This package provides a target dependent thin interface to the sockets |
| 33 |
-- layer for use by the GNAT.Sockets package (g-socket.ads). This package |
| 34 |
-- should not be directly with'ed by an applications program. |
| 35 |
|
| 36 |
-- This version is for NT |
| 37 |
|
| 38 |
with Interfaces.C; |
| 39 |
|
| 40 |
with GNAT.Sockets.Thin_Common; |
| 41 |
|
| 42 |
with System; |
| 43 |
with System.CRTL; |
| 44 |
|
| 45 |
package GNAT.Sockets.Thin is |
| 46 |
|
| 47 |
use Thin_Common; |
| 48 |
|
| 49 |
package C renames Interfaces.C; |
| 50 |
|
| 51 |
function Socket_Errno return Integer; |
| 52 |
-- Returns last socket error number |
| 53 |
|
| 54 |
procedure Set_Socket_Errno (Errno : Integer); |
| 55 |
-- Set last socket error number |
| 56 |
|
| 57 |
function Socket_Error_Message (Errno : Integer) return String; |
| 58 |
-- Returns the error message string for the error number Errno. If Errno is |
| 59 |
-- not known, returns "Unknown system error". |
| 60 |
|
| 61 |
function Host_Errno return Integer; |
| 62 |
pragma Import (C, Host_Errno, "__gnat_get_h_errno"); |
| 63 |
-- Returns last host error number |
| 64 |
|
| 65 |
package Host_Error_Messages is |
| 66 |
|
| 67 |
function Host_Error_Message (H_Errno : Integer) return String; |
| 68 |
-- Returns the error message string for the host error number H_Errno. |
| 69 |
-- If H_Errno is not known, returns "Unknown system error". |
| 70 |
|
| 71 |
end Host_Error_Messages; |
| 72 |
|
| 73 |
-------------------------------- |
| 74 |
-- Standard library functions -- |
| 75 |
-------------------------------- |
| 76 |
|
| 77 |
function C_Accept |
| 78 |
(S : C.int; |
| 79 |
Addr : System.Address; |
| 80 |
Addrlen : not null access C.int) return C.int; |
| 81 |
|
| 82 |
function C_Bind |
| 83 |
(S : C.int; |
| 84 |
Name : System.Address; |
| 85 |
Namelen : C.int) return C.int; |
| 86 |
|
| 87 |
function C_Close |
| 88 |
(Fd : C.int) return C.int; |
| 89 |
|
| 90 |
function C_Connect |
| 91 |
(S : C.int; |
| 92 |
Name : System.Address; |
| 93 |
Namelen : C.int) return C.int; |
| 94 |
|
| 95 |
function C_Gethostname |
| 96 |
(Name : System.Address; |
| 97 |
Namelen : C.int) return C.int; |
| 98 |
|
| 99 |
function C_Getpeername |
| 100 |
(S : C.int; |
| 101 |
Name : System.Address; |
| 102 |
Namelen : not null access C.int) return C.int; |
| 103 |
|
| 104 |
function C_Getsockname |
| 105 |
(S : C.int; |
| 106 |
Name : System.Address; |
| 107 |
Namelen : not null access C.int) return C.int; |
| 108 |
|
| 109 |
function C_Getsockopt |
| 110 |
(S : C.int; |
| 111 |
Level : C.int; |
| 112 |
Optname : C.int; |
| 113 |
Optval : System.Address; |
| 114 |
Optlen : not null access C.int) return C.int; |
| 115 |
|
| 116 |
function Socket_Ioctl |
| 117 |
(S : C.int; |
| 118 |
Req : SOSC.IOCTL_Req_T; |
| 119 |
Arg : access C.int) return C.int; |
| 120 |
|
| 121 |
function C_Listen |
| 122 |
(S : C.int; |
| 123 |
Backlog : C.int) return C.int; |
| 124 |
|
| 125 |
function C_Recv |
| 126 |
(S : C.int; |
| 127 |
Msg : System.Address; |
| 128 |
Len : C.int; |
| 129 |
Flags : C.int) return C.int; |
| 130 |
|
| 131 |
function C_Recvfrom |
| 132 |
(S : C.int; |
| 133 |
Msg : System.Address; |
| 134 |
Len : C.int; |
| 135 |
Flags : C.int; |
| 136 |
From : System.Address; |
| 137 |
Fromlen : not null access C.int) return C.int; |
| 138 |
|
| 139 |
function C_Recvmsg |
| 140 |
(S : C.int; |
| 141 |
Msg : System.Address; |
| 142 |
Flags : C.int) return System.CRTL.ssize_t; |
| 143 |
|
| 144 |
function C_Select |
| 145 |
(Nfds : C.int; |
| 146 |
Readfds : access Fd_Set; |
| 147 |
Writefds : access Fd_Set; |
| 148 |
Exceptfds : access Fd_Set; |
| 149 |
Timeout : Timeval_Access) return C.int; |
| 150 |
|
| 151 |
function C_Sendmsg |
| 152 |
(S : C.int; |
| 153 |
Msg : System.Address; |
| 154 |
Flags : C.int) return System.CRTL.ssize_t; |
| 155 |
|
| 156 |
function C_Sendto |
| 157 |
(S : C.int; |
| 158 |
Msg : System.Address; |
| 159 |
Len : C.int; |
| 160 |
Flags : C.int; |
| 161 |
To : System.Address; |
| 162 |
Tolen : C.int) return C.int; |
| 163 |
|
| 164 |
function C_Setsockopt |
| 165 |
(S : C.int; |
| 166 |
Level : C.int; |
| 167 |
Optname : C.int; |
| 168 |
Optval : System.Address; |
| 169 |
Optlen : C.int) return C.int; |
| 170 |
|
| 171 |
function C_Shutdown |
| 172 |
(S : C.int; |
| 173 |
How : C.int) return C.int; |
| 174 |
|
| 175 |
function C_Socket |
| 176 |
(Domain : C.int; |
| 177 |
Typ : C.int; |
| 178 |
Protocol : C.int) return C.int; |
| 179 |
|
| 180 |
Default_Socket_Pair_Family : constant := SOSC.AF_INET; |
| 181 |
-- Windows has not socketpair system call, and C_Socketpair below is |
| 182 |
-- implemented on loopback connected network sockets. |
| 183 |
|
| 184 |
function C_Socketpair |
| 185 |
(Domain : C.int; |
| 186 |
Typ : C.int; |
| 187 |
Protocol : C.int; |
| 188 |
Fds : not null access Fd_Pair) return C.int; |
| 189 |
-- Creates pair of connected sockets |
| 190 |
|
| 191 |
function C_System |
| 192 |
(Command : System.Address) return C.int; |
| 193 |
|
| 194 |
function WSAStartup |
| 195 |
(WS_Version : Interfaces.C.unsigned_short; |
| 196 |
WSADataAddress : System.Address) return Interfaces.C.int; |
| 197 |
|
| 198 |
------------------------------------------------------- |
| 199 |
-- Signalling file descriptors for selector abortion -- |
| 200 |
------------------------------------------------------- |
| 201 |
|
| 202 |
package Signalling_Fds is |
| 203 |
|
| 204 |
function Create (Fds : not null access Fd_Pair) return C.int; |
| 205 |
pragma Convention (C, Create); |
| 206 |
-- Create a pair of connected descriptors suitable for use with C_Select |
| 207 |
-- (used for signalling in Selector objects). |
| 208 |
|
| 209 |
function Read (Rsig : C.int) return C.int; |
| 210 |
pragma Convention (C, Read); |
| 211 |
-- Read one byte of data from rsig, the read end of a pair of signalling |
| 212 |
-- fds created by Create_Signalling_Fds. |
| 213 |
|
| 214 |
function Write (Wsig : C.int) return C.int; |
| 215 |
pragma Convention (C, Write); |
| 216 |
-- Write one byte of data to wsig, the write end of a pair of signalling |
| 217 |
-- fds created by Create_Signalling_Fds. |
| 218 |
|
| 219 |
procedure Close (Sig : C.int); |
| 220 |
pragma Convention (C, Close); |
| 221 |
-- Close one end of a pair of signalling fds (ignoring any error) |
| 222 |
|
| 223 |
end Signalling_Fds; |
| 224 |
|
| 225 |
procedure WSACleanup; |
| 226 |
|
| 227 |
procedure Initialize; |
| 228 |
procedure Finalize; |
| 229 |
|
| 230 |
private |
| 231 |
pragma Import (Stdcall, C_Accept, "accept"); |
| 232 |
pragma Import (Stdcall, C_Bind, "bind"); |
| 233 |
pragma Import (Stdcall, C_Close, "closesocket"); |
| 234 |
pragma Import (Stdcall, C_Gethostname, "gethostname"); |
| 235 |
pragma Import (Stdcall, C_Getpeername, "getpeername"); |
| 236 |
pragma Import (Stdcall, C_Getsockname, "getsockname"); |
| 237 |
pragma Import (Stdcall, C_Getsockopt, "getsockopt"); |
| 238 |
pragma Import (Stdcall, C_Listen, "listen"); |
| 239 |
pragma Import (Stdcall, C_Recv, "recv"); |
| 240 |
pragma Import (Stdcall, C_Recvfrom, "recvfrom"); |
| 241 |
pragma Import (Stdcall, C_Sendto, "sendto"); |
| 242 |
pragma Import (Stdcall, C_Setsockopt, "setsockopt"); |
| 243 |
pragma Import (Stdcall, C_Shutdown, "shutdown"); |
| 244 |
pragma Import (Stdcall, C_Socket, "socket"); |
| 245 |
pragma Import (C, C_System, "_system"); |
| 246 |
pragma Import (Stdcall, Socket_Errno, "WSAGetLastError"); |
| 247 |
pragma Import (Stdcall, Set_Socket_Errno, "WSASetLastError"); |
| 248 |
pragma Import (Stdcall, WSAStartup, "WSAStartup"); |
| 249 |
pragma Import (Stdcall, WSACleanup, "WSACleanup"); |
| 250 |
|
| 251 |
end GNAT.Sockets.Thin; |