authorgravatar for kenta@lithdew.netlithdew <kenta@lithdew.net> 2021-05-08 22:44:39+09:00
committergravatar for kenta@lithdew.netlithdew <kenta@lithdew.net> 2021-05-10 19:22:31+09:00
logd7b601b35e16788000853903dabaa0b10081660e
tree58b020a6ca731f6a3e392fc8e1fee8cfc66488be
parent9c03b39d1ebb52a94f1e6ee6f92a19f54a0ee528

std/os, x/os/socket: windows support, socket helpers, getpeername()

Socket I/O methods such as read, readv, write, writev, send, recv, sendmsg, recvmsg have been generalized to read(buf, flags), write(buf, flags), readVectorized(vectors, flags), and writeVectorized(vectors, flags). There is still some work left to be done abstracting both readVectorized and writeVectorized properly across platforms, which is work to be done in a future PR. Support for setting the linger timeout of a socket, querying the remote address of a socket, setting whether or not keep-alive messages are to be sent through a connection-oriented socket periodically depending on host operating system settings has been added. `std.io.Reader` and `std.io.Writer` wrappers around `Socket` has been implemented, which wrap around Socket.read(buf, flags) and Socket.write(buf, flags). Both wrappers may be provided flags which are passed to Socket.read / Socket.write accordingly. Cross-platform support for `getpeername()` has been implemented. Windows support for the new `std.x.os.Socket` has been implemented. To accomplish this, a full refactor of `std.os.windows.ws2_32` has been done to supply any missing definitions and constants based on auto-generated Windows syscall bindings by @marler8997. `std.x.net.TCP.Listener.setQuickACK` has been moved to `std.x.net.TCP.Client.setQuickACK`. Windows support for resolving the scope ID of an interface name specified in an IPv6 address has been provided. `sockaddr_storage` definitions have been provided for Windows, Linux, and Darwin. `sockaddr_storage` is used to allocate space before any socket addresses are queried via. calls such as accept(), getsockname(), and getpeername(). Zig-friendly wrappers for GetQueuedCompletionStatusEx(), getpeername(), SetConsoleCtrlHandler(), SetFileCompletionNotificationModes() syscalls on Windows have been provided. Socket.setOption() was provided to set the value of a socket option in place of os.setsockopt. Socket.getOption() will be provided in a future PR. There is still further work to be done regarding querying socket option values on Windows, which is to be done in a subsequent PR.

16 files changed, 2592 insertions(+), 580 deletions(-)

lib/std/c.zig+1
...@@ -151,6 +151,7 @@ pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: soc...@@ -151,6 +151,7 @@ pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: soc
151pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;151pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;
152pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int;152pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int;
153pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;153pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
154pub extern "c" fn getpeername(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
154pub extern "c" fn connect(sockfd: fd_t, sock_addr: *const sockaddr, addrlen: socklen_t) c_int;155pub extern "c" fn connect(sockfd: fd_t, sock_addr: *const sockaddr, addrlen: socklen_t) c_int;
155pub extern "c" fn accept(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t) c_int;156pub extern "c" fn accept(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t) c_int;
156pub extern "c" fn accept4(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t, flags: c_uint) c_int;157pub extern "c" fn accept4(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t, flags: c_uint) c_int;
lib/std/os.zig+29
...@@ -3217,6 +3217,35 @@ pub fn getsockname(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock...@@ -3217,6 +3217,35 @@ pub fn getsockname(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
3217 }3217 }
3218}3218}
32193219
3220pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSockNameError!void {
3221 if (builtin.os.tag == .windows) {
3222 const rc = windows.getpeername(sock, addr, addrlen);
3223 if (rc == windows.ws2_32.SOCKET_ERROR) {
3224 switch (windows.ws2_32.WSAGetLastError()) {
3225 .WSANOTINITIALISED => unreachable,
3226 .WSAENETDOWN => return error.NetworkSubsystemFailed,
3227 .WSAEFAULT => unreachable, // addr or addrlen have invalid pointers or addrlen points to an incorrect value
3228 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
3229 .WSAEINVAL => return error.SocketNotBound,
3230 else => |err| return windows.unexpectedWSAError(err),
3231 }
3232 }
3233 return;
3234 } else {
3235 const rc = system.getpeername(sock, addr, addrlen);
3236 switch (errno(rc)) {
3237 0 => return,
3238 else => |err| return unexpectedErrno(err),
3239
3240 EBADF => unreachable, // always a race condition
3241 EFAULT => unreachable,
3242 EINVAL => unreachable, // invalid parameters
3243 ENOTSOCK => return error.FileDescriptorNotASocket,
3244 ENOBUFS => return error.SystemResources,
3245 }
3246 }
3247}
3248
3220pub const ConnectError = error{3249pub const ConnectError = error{
3221 /// For UNIX domain sockets, which are identified by pathname: Write permission is denied on the socket3250 /// For UNIX domain sockets, which are identified by pathname: Write permission is denied on the socket
3222 /// file, or search permission is denied for one of the directories in the path prefix.3251 /// file, or search permission is denied for one of the directories in the path prefix.
lib/std/os/bits/darwin.zig+7
...@@ -23,6 +23,13 @@ pub const sockaddr = extern struct {...@@ -23,6 +23,13 @@ pub const sockaddr = extern struct {
23 family: sa_family_t,23 family: sa_family_t,
24 data: [14]u8,24 data: [14]u8,
25};25};
26pub const sockaddr_storage = extern struct {
27 len: u8,
28 family: sa_family_t,
29 __pad1: [6]u8,
30 __align: i64,
31 __pad2: [112]u8,
32};
26pub const sockaddr_in = extern struct {33pub const sockaddr_in = extern struct {
27 len: u8 = @sizeOf(sockaddr_in),34 len: u8 = @sizeOf(sockaddr_in),
28 family: sa_family_t = AF_INET,35 family: sa_family_t = AF_INET,
lib/std/os/bits/linux.zig+7
...@@ -1149,6 +1149,13 @@ pub const sockaddr = extern struct {...@@ -1149,6 +1149,13 @@ pub const sockaddr = extern struct {
1149 data: [14]u8,1149 data: [14]u8,
1150};1150};
11511151
1152pub const sockaddr_storage = extern struct {
1153 family: sa_family_t,
1154 __pad1: [6]u8,
1155 __align: i64,
1156 __pad2: [112]u8,
1157};
1158
1152/// IPv4 socket address1159/// IPv4 socket address
1153pub const sockaddr_in = extern struct {1160pub const sockaddr_in = extern struct {
1154 family: sa_family_t = AF_INET,1161 family: sa_family_t = AF_INET,
lib/std/os/bits/windows.zig+2
...@@ -321,3 +321,5 @@ pub const O_NOATIME = 0o1000000;...@@ -321,3 +321,5 @@ pub const O_NOATIME = 0o1000000;
321pub const O_PATH = 0o10000000;321pub const O_PATH = 0o10000000;
322pub const O_TMPFILE = 0o20200000;322pub const O_TMPFILE = 0o20200000;
323pub const O_NDELAY = O_NONBLOCK;323pub const O_NDELAY = O_NONBLOCK;
324
325pub const IFNAMESIZE = 30;
lib/std/os/windows.zig+63
...@@ -389,6 +389,43 @@ pub fn GetQueuedCompletionStatus(...@@ -389,6 +389,43 @@ pub fn GetQueuedCompletionStatus(
389 return GetQueuedCompletionStatusResult.Normal;389 return GetQueuedCompletionStatusResult.Normal;
390}390}
391391
392pub const GetQueuedCompletionStatusError = error{
393 Aborted,
394 Cancelled,
395 EOF,
396 Timeout,
397} || std.os.UnexpectedError;
398
399pub fn GetQueuedCompletionStatusEx(
400 completion_port: HANDLE,
401 completion_port_entries: []OVERLAPPED_ENTRY,
402 timeout_ms: ?DWORD,
403 alertable: bool,
404) GetQueuedCompletionStatusError!u32 {
405 var num_entries_removed: u32 = 0;
406
407 const success = kernel32.GetQueuedCompletionStatusEx(
408 completion_port,
409 completion_port_entries.ptr,
410 @intCast(ULONG, completion_port_entries.len),
411 &num_entries_removed,
412 timeout_ms orelse INFINITE,
413 @boolToInt(alertable),
414 );
415
416 if (success == FALSE) {
417 return switch (kernel32.GetLastError()) {
418 .ABANDONED_WAIT_0 => error.Aborted,
419 .OPERATION_ABORTED => error.Cancelled,
420 .HANDLE_EOF => error.EOF,
421 .IMEOUT => error.Timeout,
422 else => |err| unexpectedError(err),
423 };
424 }
425
426 return num_entries_removed;
427}
428
392pub fn CloseHandle(hObject: HANDLE) void {429pub fn CloseHandle(hObject: HANDLE) void {
393 assert(ntdll.NtClose(hObject) == .SUCCESS);430 assert(ntdll.NtClose(hObject) == .SUCCESS);
394}431}
...@@ -1291,6 +1328,10 @@ pub fn getsockname(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.so...@@ -1291,6 +1328,10 @@ pub fn getsockname(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.so
1291 return ws2_32.getsockname(s, name, @ptrCast(*i32, namelen));1328 return ws2_32.getsockname(s, name, @ptrCast(*i32, namelen));
1292}1329}
12931330
1331pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.socklen_t) i32 {
1332 return ws2_32.getpeername(s, name, @ptrCast(*i32, namelen));
1333}
1334
1294pub fn sendmsg(1335pub fn sendmsg(
1295 s: ws2_32.SOCKET,1336 s: ws2_32.SOCKET,
1296 msg: *const ws2_32.WSAMSG,1337 msg: *const ws2_32.WSAMSG,
...@@ -1404,6 +1445,28 @@ pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetCon...@@ -1404,6 +1445,28 @@ pub fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) SetCon
1404 }1445 }
1405}1446}
14061447
1448pub fn SetConsoleCtrlHandler(handler_routine: ?HANDLER_ROUTINE, add: bool) !void {
1449 const success = kernel32.SetConsoleCtrlHandler(
1450 handler_routine,
1451 if (add) TRUE else FALSE,
1452 );
1453
1454 if (success == FALSE) {
1455 return switch (kernel32.GetLastError()) {
1456 else => |err| unexpectedError(err),
1457 };
1458 }
1459}
1460
1461pub fn SetFileCompletionNotificationModes(handle: HANDLE, flags: UCHAR) !void {
1462 const success = kernel32.SetFileCompletionNotificationModes(handle, flags);
1463 if (success == FALSE) {
1464 return switch (kernel32.GetLastError()) {
1465 else => |err| unexpectedError(err),
1466 };
1467 }
1468}
1469
1407pub const GetEnvironmentStringsError = error{OutOfMemory};1470pub const GetEnvironmentStringsError = error{OutOfMemory};
14081471
1409pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*:0]u16 {1472pub fn GetEnvironmentStringsW() GetEnvironmentStringsError![*:0]u16 {
lib/std/os/windows/bits.zig+11-4
...@@ -1619,10 +1619,6 @@ pub const MOUNTMGR_MOUNT_POINTS = extern struct {...@@ -1619,10 +1619,6 @@ pub const MOUNTMGR_MOUNT_POINTS = extern struct {
1619};1619};
1620pub const IOCTL_MOUNTMGR_QUERY_POINTS: ULONG = 0x6d0008;1620pub const IOCTL_MOUNTMGR_QUERY_POINTS: ULONG = 0x6d0008;
16211621
1622pub const SD_RECEIVE = 0;
1623pub const SD_SEND = 1;
1624pub const SD_BOTH = 2;
1625
1626pub const OBJECT_INFORMATION_CLASS = extern enum {1622pub const OBJECT_INFORMATION_CLASS = extern enum {
1627 ObjectBasicInformation = 0,1623 ObjectBasicInformation = 0,
1628 ObjectNameInformation = 1,1624 ObjectNameInformation = 1,
...@@ -1642,3 +1638,14 @@ pub const SRWLOCK = usize;...@@ -1642,3 +1638,14 @@ pub const SRWLOCK = usize;
1642pub const SRWLOCK_INIT: SRWLOCK = 0;1638pub const SRWLOCK_INIT: SRWLOCK = 0;
1643pub const CONDITION_VARIABLE = usize;1639pub const CONDITION_VARIABLE = usize;
1644pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = 0;1640pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = 0;
1641
1642pub const FILE_SKIP_COMPLETION_PORT_ON_SUCCESS = 0x1;
1643pub const FILE_SKIP_SET_EVENT_ON_HANDLE = 0x2;
1644
1645pub const CTRL_C_EVENT: DWORD = 0;
1646pub const CTRL_BREAK_EVENT: DWORD = 1;
1647pub const CTRL_CLOSE_EVENT: DWORD = 2;
1648pub const CTRL_LOGOFF_EVENT: DWORD = 5;
1649pub const CTRL_SHUTDOWN_EVENT: DWORD = 6;
1650
1651pub const HANDLER_ROUTINE = fn (dwCtrlType: DWORD) callconv(.C) BOOL;
lib/std/os/windows/kernel32.zig+18
...@@ -140,6 +140,14 @@ pub extern "kernel32" fn GetOverlappedResult(hFile: HANDLE, lpOverlapped: *OVERL...@@ -140,6 +140,14 @@ pub extern "kernel32" fn GetOverlappedResult(hFile: HANDLE, lpOverlapped: *OVERL
140140
141pub extern "kernel32" fn GetProcessHeap() callconv(WINAPI) ?HANDLE;141pub extern "kernel32" fn GetProcessHeap() callconv(WINAPI) ?HANDLE;
142pub extern "kernel32" fn GetQueuedCompletionStatus(CompletionPort: HANDLE, lpNumberOfBytesTransferred: LPDWORD, lpCompletionKey: *ULONG_PTR, lpOverlapped: *?*OVERLAPPED, dwMilliseconds: DWORD) callconv(WINAPI) BOOL;142pub extern "kernel32" fn GetQueuedCompletionStatus(CompletionPort: HANDLE, lpNumberOfBytesTransferred: LPDWORD, lpCompletionKey: *ULONG_PTR, lpOverlapped: *?*OVERLAPPED, dwMilliseconds: DWORD) callconv(WINAPI) BOOL;
143pub extern "kernel32" fn GetQueuedCompletionStatusEx(
144 CompletionPort: HANDLE,
145 lpCompletionPortEntries: [*]OVERLAPPED_ENTRY,
146 ulCount: ULONG,
147 ulNumEntriesRemoved: *ULONG,
148 dwMilliseconds: DWORD,
149 fAlertable: BOOL,
150) callconv(WINAPI) BOOL;
143151
144pub extern "kernel32" fn GetSystemInfo(lpSystemInfo: *SYSTEM_INFO) callconv(WINAPI) void;152pub extern "kernel32" fn GetSystemInfo(lpSystemInfo: *SYSTEM_INFO) callconv(WINAPI) void;
145pub extern "kernel32" fn GetSystemTimeAsFileTime(*FILETIME) callconv(WINAPI) void;153pub extern "kernel32" fn GetSystemTimeAsFileTime(*FILETIME) callconv(WINAPI) void;
...@@ -197,6 +205,16 @@ pub extern "kernel32" fn RemoveDirectoryW(lpPathName: [*:0]const u16) callconv(W...@@ -197,6 +205,16 @@ pub extern "kernel32" fn RemoveDirectoryW(lpPathName: [*:0]const u16) callconv(W
197205
198pub extern "kernel32" fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) callconv(WINAPI) BOOL;206pub extern "kernel32" fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) callconv(WINAPI) BOOL;
199207
208pub extern "kernel32" fn SetConsoleCtrlHandler(
209 HandlerRoutine: ?HANDLER_ROUTINE,
210 Add: BOOL,
211) callconv(WINAPI) BOOL;
212
213pub extern "kernel32" fn SetFileCompletionNotificationModes(
214 FileHandle: HANDLE,
215 Flags: UCHAR,
216) callconv(WINAPI) BOOL;
217
200pub extern "kernel32" fn SetFilePointerEx(218pub extern "kernel32" fn SetFilePointerEx(
201 in_fFile: HANDLE,219 in_fFile: HANDLE,
202 in_liDistanceToMove: LARGE_INTEGER,220 in_liDistanceToMove: LARGE_INTEGER,
lib/std/os/windows/ws2_32.zig+1614-242
...@@ -7,10 +7,879 @@ usingnamespace @import("bits.zig");...@@ -7,10 +7,879 @@ usingnamespace @import("bits.zig");
77
8pub const SOCKET = *opaque {};8pub const SOCKET = *opaque {};
9pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0));9pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0));
10pub const SOCKET_ERROR = -1;
1110
12pub const WSADESCRIPTION_LEN = 256;11pub const GROUP = u32;
13pub const WSASYS_STATUS_LEN = 128;12pub const ADDRESS_FAMILY = u16;
13pub const WSAEVENT = HANDLE;
14
15// Microsoft use the signed c_int for this, but it should never be negative
16pub const socklen_t = u32;
17
18pub const LM_HB_Extension = @as(i32, 128);
19pub const LM_HB1_PnP = @as(i32, 1);
20pub const LM_HB1_PDA_Palmtop = @as(i32, 2);
21pub const LM_HB1_Computer = @as(i32, 4);
22pub const LM_HB1_Printer = @as(i32, 8);
23pub const LM_HB1_Modem = @as(i32, 16);
24pub const LM_HB1_Fax = @as(i32, 32);
25pub const LM_HB1_LANAccess = @as(i32, 64);
26pub const LM_HB2_Telephony = @as(i32, 1);
27pub const LM_HB2_FileServer = @as(i32, 2);
28pub const ATMPROTO_AALUSER = @as(u32, 0);
29pub const ATMPROTO_AAL1 = @as(u32, 1);
30pub const ATMPROTO_AAL2 = @as(u32, 2);
31pub const ATMPROTO_AAL34 = @as(u32, 3);
32pub const ATMPROTO_AAL5 = @as(u32, 5);
33pub const SAP_FIELD_ABSENT = @as(u32, 4294967294);
34pub const SAP_FIELD_ANY = @as(u32, 4294967295);
35pub const SAP_FIELD_ANY_AESA_SEL = @as(u32, 4294967290);
36pub const SAP_FIELD_ANY_AESA_REST = @as(u32, 4294967291);
37pub const ATM_E164 = @as(u32, 1);
38pub const ATM_NSAP = @as(u32, 2);
39pub const ATM_AESA = @as(u32, 2);
40pub const ATM_ADDR_SIZE = @as(u32, 20);
41pub const BLLI_L2_ISO_1745 = @as(u32, 1);
42pub const BLLI_L2_Q921 = @as(u32, 2);
43pub const BLLI_L2_X25L = @as(u32, 6);
44pub const BLLI_L2_X25M = @as(u32, 7);
45pub const BLLI_L2_ELAPB = @as(u32, 8);
46pub const BLLI_L2_HDLC_ARM = @as(u32, 9);
47pub const BLLI_L2_HDLC_NRM = @as(u32, 10);
48pub const BLLI_L2_HDLC_ABM = @as(u32, 11);
49pub const BLLI_L2_LLC = @as(u32, 12);
50pub const BLLI_L2_X75 = @as(u32, 13);
51pub const BLLI_L2_Q922 = @as(u32, 14);
52pub const BLLI_L2_USER_SPECIFIED = @as(u32, 16);
53pub const BLLI_L2_ISO_7776 = @as(u32, 17);
54pub const BLLI_L3_X25 = @as(u32, 6);
55pub const BLLI_L3_ISO_8208 = @as(u32, 7);
56pub const BLLI_L3_X223 = @as(u32, 8);
57pub const BLLI_L3_SIO_8473 = @as(u32, 9);
58pub const BLLI_L3_T70 = @as(u32, 10);
59pub const BLLI_L3_ISO_TR9577 = @as(u32, 11);
60pub const BLLI_L3_USER_SPECIFIED = @as(u32, 16);
61pub const BLLI_L3_IPI_SNAP = @as(u32, 128);
62pub const BLLI_L3_IPI_IP = @as(u32, 204);
63pub const BHLI_ISO = @as(u32, 0);
64pub const BHLI_UserSpecific = @as(u32, 1);
65pub const BHLI_HighLayerProfile = @as(u32, 2);
66pub const BHLI_VendorSpecificAppId = @as(u32, 3);
67pub const AAL5_MODE_MESSAGE = @as(u32, 1);
68pub const AAL5_MODE_STREAMING = @as(u32, 2);
69pub const AAL5_SSCS_NULL = @as(u32, 0);
70pub const AAL5_SSCS_SSCOP_ASSURED = @as(u32, 1);
71pub const AAL5_SSCS_SSCOP_NON_ASSURED = @as(u32, 2);
72pub const AAL5_SSCS_FRAME_RELAY = @as(u32, 4);
73pub const BCOB_A = @as(u32, 1);
74pub const BCOB_C = @as(u32, 3);
75pub const BCOB_X = @as(u32, 16);
76pub const TT_NOIND = @as(u32, 0);
77pub const TT_CBR = @as(u32, 4);
78pub const TT_VBR = @as(u32, 8);
79pub const TR_NOIND = @as(u32, 0);
80pub const TR_END_TO_END = @as(u32, 1);
81pub const TR_NO_END_TO_END = @as(u32, 2);
82pub const CLIP_NOT = @as(u32, 0);
83pub const CLIP_SUS = @as(u32, 32);
84pub const UP_P2P = @as(u32, 0);
85pub const UP_P2MP = @as(u32, 1);
86pub const BLLI_L2_MODE_NORMAL = @as(u32, 64);
87pub const BLLI_L2_MODE_EXT = @as(u32, 128);
88pub const BLLI_L3_MODE_NORMAL = @as(u32, 64);
89pub const BLLI_L3_MODE_EXT = @as(u32, 128);
90pub const BLLI_L3_PACKET_16 = @as(u32, 4);
91pub const BLLI_L3_PACKET_32 = @as(u32, 5);
92pub const BLLI_L3_PACKET_64 = @as(u32, 6);
93pub const BLLI_L3_PACKET_128 = @as(u32, 7);
94pub const BLLI_L3_PACKET_256 = @as(u32, 8);
95pub const BLLI_L3_PACKET_512 = @as(u32, 9);
96pub const BLLI_L3_PACKET_1024 = @as(u32, 10);
97pub const BLLI_L3_PACKET_2048 = @as(u32, 11);
98pub const BLLI_L3_PACKET_4096 = @as(u32, 12);
99pub const PI_ALLOWED = @as(u32, 0);
100pub const PI_RESTRICTED = @as(u32, 64);
101pub const PI_NUMBER_NOT_AVAILABLE = @as(u32, 128);
102pub const SI_USER_NOT_SCREENED = @as(u32, 0);
103pub const SI_USER_PASSED = @as(u32, 1);
104pub const SI_USER_FAILED = @as(u32, 2);
105pub const SI_NETWORK = @as(u32, 3);
106pub const CAUSE_LOC_USER = @as(u32, 0);
107pub const CAUSE_LOC_PRIVATE_LOCAL = @as(u32, 1);
108pub const CAUSE_LOC_PUBLIC_LOCAL = @as(u32, 2);
109pub const CAUSE_LOC_TRANSIT_NETWORK = @as(u32, 3);
110pub const CAUSE_LOC_PUBLIC_REMOTE = @as(u32, 4);
111pub const CAUSE_LOC_PRIVATE_REMOTE = @as(u32, 5);
112pub const CAUSE_LOC_INTERNATIONAL_NETWORK = @as(u32, 7);
113pub const CAUSE_LOC_BEYOND_INTERWORKING = @as(u32, 10);
114pub const CAUSE_UNALLOCATED_NUMBER = @as(u32, 1);
115pub const CAUSE_NO_ROUTE_TO_TRANSIT_NETWORK = @as(u32, 2);
116pub const CAUSE_NO_ROUTE_TO_DESTINATION = @as(u32, 3);
117pub const CAUSE_VPI_VCI_UNACCEPTABLE = @as(u32, 10);
118pub const CAUSE_NORMAL_CALL_CLEARING = @as(u32, 16);
119pub const CAUSE_USER_BUSY = @as(u32, 17);
120pub const CAUSE_NO_USER_RESPONDING = @as(u32, 18);
121pub const CAUSE_CALL_REJECTED = @as(u32, 21);
122pub const CAUSE_NUMBER_CHANGED = @as(u32, 22);
123pub const CAUSE_USER_REJECTS_CLIR = @as(u32, 23);
124pub const CAUSE_DESTINATION_OUT_OF_ORDER = @as(u32, 27);
125pub const CAUSE_INVALID_NUMBER_FORMAT = @as(u32, 28);
126pub const CAUSE_STATUS_ENQUIRY_RESPONSE = @as(u32, 30);
127pub const CAUSE_NORMAL_UNSPECIFIED = @as(u32, 31);
128pub const CAUSE_VPI_VCI_UNAVAILABLE = @as(u32, 35);
129pub const CAUSE_NETWORK_OUT_OF_ORDER = @as(u32, 38);
130pub const CAUSE_TEMPORARY_FAILURE = @as(u32, 41);
131pub const CAUSE_ACCESS_INFORMAION_DISCARDED = @as(u32, 43);
132pub const CAUSE_NO_VPI_VCI_AVAILABLE = @as(u32, 45);
133pub const CAUSE_RESOURCE_UNAVAILABLE = @as(u32, 47);
134pub const CAUSE_QOS_UNAVAILABLE = @as(u32, 49);
135pub const CAUSE_USER_CELL_RATE_UNAVAILABLE = @as(u32, 51);
136pub const CAUSE_BEARER_CAPABILITY_UNAUTHORIZED = @as(u32, 57);
137pub const CAUSE_BEARER_CAPABILITY_UNAVAILABLE = @as(u32, 58);
138pub const CAUSE_OPTION_UNAVAILABLE = @as(u32, 63);
139pub const CAUSE_BEARER_CAPABILITY_UNIMPLEMENTED = @as(u32, 65);
140pub const CAUSE_UNSUPPORTED_TRAFFIC_PARAMETERS = @as(u32, 73);
141pub const CAUSE_INVALID_CALL_REFERENCE = @as(u32, 81);
142pub const CAUSE_CHANNEL_NONEXISTENT = @as(u32, 82);
143pub const CAUSE_INCOMPATIBLE_DESTINATION = @as(u32, 88);
144pub const CAUSE_INVALID_ENDPOINT_REFERENCE = @as(u32, 89);
145pub const CAUSE_INVALID_TRANSIT_NETWORK_SELECTION = @as(u32, 91);
146pub const CAUSE_TOO_MANY_PENDING_ADD_PARTY = @as(u32, 92);
147pub const CAUSE_AAL_PARAMETERS_UNSUPPORTED = @as(u32, 93);
148pub const CAUSE_MANDATORY_IE_MISSING = @as(u32, 96);
149pub const CAUSE_UNIMPLEMENTED_MESSAGE_TYPE = @as(u32, 97);
150pub const CAUSE_UNIMPLEMENTED_IE = @as(u32, 99);
151pub const CAUSE_INVALID_IE_CONTENTS = @as(u32, 100);
152pub const CAUSE_INVALID_STATE_FOR_MESSAGE = @as(u32, 101);
153pub const CAUSE_RECOVERY_ON_TIMEOUT = @as(u32, 102);
154pub const CAUSE_INCORRECT_MESSAGE_LENGTH = @as(u32, 104);
155pub const CAUSE_PROTOCOL_ERROR = @as(u32, 111);
156pub const CAUSE_COND_UNKNOWN = @as(u32, 0);
157pub const CAUSE_COND_PERMANENT = @as(u32, 1);
158pub const CAUSE_COND_TRANSIENT = @as(u32, 2);
159pub const CAUSE_REASON_USER = @as(u32, 0);
160pub const CAUSE_REASON_IE_MISSING = @as(u32, 4);
161pub const CAUSE_REASON_IE_INSUFFICIENT = @as(u32, 8);
162pub const CAUSE_PU_PROVIDER = @as(u32, 0);
163pub const CAUSE_PU_USER = @as(u32, 8);
164pub const CAUSE_NA_NORMAL = @as(u32, 0);
165pub const CAUSE_NA_ABNORMAL = @as(u32, 4);
166pub const QOS_CLASS0 = @as(u32, 0);
167pub const QOS_CLASS1 = @as(u32, 1);
168pub const QOS_CLASS2 = @as(u32, 2);
169pub const QOS_CLASS3 = @as(u32, 3);
170pub const QOS_CLASS4 = @as(u32, 4);
171pub const TNS_TYPE_NATIONAL = @as(u32, 64);
172pub const TNS_PLAN_CARRIER_ID_CODE = @as(u32, 1);
173pub const SIO_GET_NUMBER_OF_ATM_DEVICES = @as(u32, 1343619073);
174pub const SIO_GET_ATM_ADDRESS = @as(u32, 3491102722);
175pub const SIO_ASSOCIATE_PVC = @as(u32, 2417360899);
176pub const SIO_GET_ATM_CONNECTION_ID = @as(u32, 1343619076);
177pub const RIO_MSG_DONT_NOTIFY = @as(u32, 1);
178pub const RIO_MSG_DEFER = @as(u32, 2);
179pub const RIO_MSG_WAITALL = @as(u32, 4);
180pub const RIO_MSG_COMMIT_ONLY = @as(u32, 8);
181pub const RIO_MAX_CQ_SIZE = @as(u32, 134217728);
182pub const RIO_CORRUPT_CQ = @as(u32, 4294967295);
183pub const WINDOWS_AF_IRDA = @as(u32, 26);
184pub const WCE_AF_IRDA = @as(u32, 22);
185pub const IRDA_PROTO_SOCK_STREAM = @as(u32, 1);
186pub const SOL_IRLMP = @as(u32, 255);
187pub const IRLMP_ENUMDEVICES = @as(u32, 16);
188pub const IRLMP_IAS_SET = @as(u32, 17);
189pub const IRLMP_IAS_QUERY = @as(u32, 18);
190pub const IRLMP_SEND_PDU_LEN = @as(u32, 19);
191pub const IRLMP_EXCLUSIVE_MODE = @as(u32, 20);
192pub const IRLMP_IRLPT_MODE = @as(u32, 21);
193pub const IRLMP_9WIRE_MODE = @as(u32, 22);
194pub const IRLMP_TINYTP_MODE = @as(u32, 23);
195pub const IRLMP_PARAMETERS = @as(u32, 24);
196pub const IRLMP_DISCOVERY_MODE = @as(u32, 25);
197pub const IRLMP_SHARP_MODE = @as(u32, 32);
198pub const IAS_ATTRIB_NO_CLASS = @as(u32, 16);
199pub const IAS_ATTRIB_NO_ATTRIB = @as(u32, 0);
200pub const IAS_ATTRIB_INT = @as(u32, 1);
201pub const IAS_ATTRIB_OCTETSEQ = @as(u32, 2);
202pub const IAS_ATTRIB_STR = @as(u32, 3);
203pub const IAS_MAX_USER_STRING = @as(u32, 256);
204pub const IAS_MAX_OCTET_STRING = @as(u32, 1024);
205pub const IAS_MAX_CLASSNAME = @as(u32, 64);
206pub const IAS_MAX_ATTRIBNAME = @as(u32, 256);
207pub const LmCharSetASCII = @as(u32, 0);
208pub const LmCharSetISO_8859_1 = @as(u32, 1);
209pub const LmCharSetISO_8859_2 = @as(u32, 2);
210pub const LmCharSetISO_8859_3 = @as(u32, 3);
211pub const LmCharSetISO_8859_4 = @as(u32, 4);
212pub const LmCharSetISO_8859_5 = @as(u32, 5);
213pub const LmCharSetISO_8859_6 = @as(u32, 6);
214pub const LmCharSetISO_8859_7 = @as(u32, 7);
215pub const LmCharSetISO_8859_8 = @as(u32, 8);
216pub const LmCharSetISO_8859_9 = @as(u32, 9);
217pub const LmCharSetUNICODE = @as(u32, 255);
218pub const LM_BAUD_1200 = @as(u32, 1200);
219pub const LM_BAUD_2400 = @as(u32, 2400);
220pub const LM_BAUD_9600 = @as(u32, 9600);
221pub const LM_BAUD_19200 = @as(u32, 19200);
222pub const LM_BAUD_38400 = @as(u32, 38400);
223pub const LM_BAUD_57600 = @as(u32, 57600);
224pub const LM_BAUD_115200 = @as(u32, 115200);
225pub const LM_BAUD_576K = @as(u32, 576000);
226pub const LM_BAUD_1152K = @as(u32, 1152000);
227pub const LM_BAUD_4M = @as(u32, 4000000);
228pub const LM_BAUD_16M = @as(u32, 16000000);
229pub const IPX_PTYPE = @as(u32, 16384);
230pub const IPX_FILTERPTYPE = @as(u32, 16385);
231pub const IPX_STOPFILTERPTYPE = @as(u32, 16387);
232pub const IPX_DSTYPE = @as(u32, 16386);
233pub const IPX_EXTENDED_ADDRESS = @as(u32, 16388);
234pub const IPX_RECVHDR = @as(u32, 16389);
235pub const IPX_MAXSIZE = @as(u32, 16390);
236pub const IPX_ADDRESS = @as(u32, 16391);
237pub const IPX_GETNETINFO = @as(u32, 16392);
238pub const IPX_GETNETINFO_NORIP = @as(u32, 16393);
239pub const IPX_SPXGETCONNECTIONSTATUS = @as(u32, 16395);
240pub const IPX_ADDRESS_NOTIFY = @as(u32, 16396);
241pub const IPX_MAX_ADAPTER_NUM = @as(u32, 16397);
242pub const IPX_RERIPNETNUMBER = @as(u32, 16398);
243pub const IPX_RECEIVE_BROADCAST = @as(u32, 16399);
244pub const IPX_IMMEDIATESPXACK = @as(u32, 16400);
245pub const IPPROTO_RM = @as(u32, 113);
246pub const MAX_MCAST_TTL = @as(u32, 255);
247pub const RM_OPTIONSBASE = @as(u32, 1000);
248pub const RM_RATE_WINDOW_SIZE = @as(u32, 1001);
249pub const RM_SET_MESSAGE_BOUNDARY = @as(u32, 1002);
250pub const RM_FLUSHCACHE = @as(u32, 1003);
251pub const RM_SENDER_WINDOW_ADVANCE_METHOD = @as(u32, 1004);
252pub const RM_SENDER_STATISTICS = @as(u32, 1005);
253pub const RM_LATEJOIN = @as(u32, 1006);
254pub const RM_SET_SEND_IF = @as(u32, 1007);
255pub const RM_ADD_RECEIVE_IF = @as(u32, 1008);
256pub const RM_DEL_RECEIVE_IF = @as(u32, 1009);
257pub const RM_SEND_WINDOW_ADV_RATE = @as(u32, 1010);
258pub const RM_USE_FEC = @as(u32, 1011);
259pub const RM_SET_MCAST_TTL = @as(u32, 1012);
260pub const RM_RECEIVER_STATISTICS = @as(u32, 1013);
261pub const RM_HIGH_SPEED_INTRANET_OPT = @as(u32, 1014);
262pub const SENDER_DEFAULT_RATE_KBITS_PER_SEC = @as(u32, 56);
263pub const SENDER_DEFAULT_WINDOW_ADV_PERCENTAGE = @as(u32, 15);
264pub const MAX_WINDOW_INCREMENT_PERCENTAGE = @as(u32, 25);
265pub const SENDER_DEFAULT_LATE_JOINER_PERCENTAGE = @as(u32, 0);
266pub const SENDER_MAX_LATE_JOINER_PERCENTAGE = @as(u32, 75);
267pub const BITS_PER_BYTE = @as(u32, 8);
268pub const LOG2_BITS_PER_BYTE = @as(u32, 3);
269pub const SOCKET_DEFAULT2_QM_POLICY = Guid.initString("aec2ef9c-3a4d-4d3e-8842-239942e39a47");
270pub const REAL_TIME_NOTIFICATION_CAPABILITY = Guid.initString("6b59819a-5cae-492d-a901-2a3c2c50164f");
271pub const REAL_TIME_NOTIFICATION_CAPABILITY_EX = Guid.initString("6843da03-154a-4616-a508-44371295f96b");
272pub const ASSOCIATE_NAMERES_CONTEXT = Guid.initString("59a38b67-d4fe-46e1-ba3c-87ea74ca3049");
273pub const TCP_INITIAL_RTO_DEFAULT_RTT = @as(u32, 0);
274pub const TCP_INITIAL_RTO_DEFAULT_MAX_SYN_RETRANSMISSIONS = @as(u32, 0);
275pub const SOCKET_SETTINGS_GUARANTEE_ENCRYPTION = @as(u32, 1);
276pub const SOCKET_SETTINGS_ALLOW_INSECURE = @as(u32, 2);
277pub const SOCKET_SETTINGS_IPSEC_SKIP_FILTER_INSTANTIATION = @as(u32, 1);
278pub const SOCKET_SETTINGS_IPSEC_OPTIONAL_PEER_NAME_VERIFICATION = @as(u32, 2);
279pub const SOCKET_SETTINGS_IPSEC_ALLOW_FIRST_INBOUND_PKT_UNENCRYPTED = @as(u32, 4);
280pub const SOCKET_SETTINGS_IPSEC_PEER_NAME_IS_RAW_FORMAT = @as(u32, 8);
281pub const SOCKET_QUERY_IPSEC2_ABORT_CONNECTION_ON_FIELD_CHANGE = @as(u32, 1);
282pub const SOCKET_QUERY_IPSEC2_FIELD_MASK_MM_SA_ID = @as(u32, 1);
283pub const SOCKET_QUERY_IPSEC2_FIELD_MASK_QM_SA_ID = @as(u32, 2);
284pub const SOCKET_INFO_CONNECTION_SECURED = @as(u32, 1);
285pub const SOCKET_INFO_CONNECTION_ENCRYPTED = @as(u32, 2);
286pub const SOCKET_INFO_CONNECTION_IMPERSONATED = @as(u32, 4);
287pub const IN4ADDR_LOOPBACK = @as(u32, 16777343);
288pub const IN4ADDR_LOOPBACKPREFIX_LENGTH = @as(u32, 8);
289pub const IN4ADDR_LINKLOCALPREFIX_LENGTH = @as(u32, 16);
290pub const IN4ADDR_MULTICASTPREFIX_LENGTH = @as(u32, 4);
291pub const IFF_UP = @as(u32, 1);
292pub const IFF_BROADCAST = @as(u32, 2);
293pub const IFF_LOOPBACK = @as(u32, 4);
294pub const IFF_POINTTOPOINT = @as(u32, 8);
295pub const IFF_MULTICAST = @as(u32, 16);
296pub const IP_OPTIONS = @as(u32, 1);
297pub const IP_HDRINCL = @as(u32, 2);
298pub const IP_TOS = @as(u32, 3);
299pub const IP_TTL = @as(u32, 4);
300pub const IP_MULTICAST_IF = @as(u32, 9);
301pub const IP_MULTICAST_TTL = @as(u32, 10);
302pub const IP_MULTICAST_LOOP = @as(u32, 11);
303pub const IP_ADD_MEMBERSHIP = @as(u32, 12);
304pub const IP_DROP_MEMBERSHIP = @as(u32, 13);
305pub const IP_DONTFRAGMENT = @as(u32, 14);
306pub const IP_ADD_SOURCE_MEMBERSHIP = @as(u32, 15);
307pub const IP_DROP_SOURCE_MEMBERSHIP = @as(u32, 16);
308pub const IP_BLOCK_SOURCE = @as(u32, 17);
309pub const IP_UNBLOCK_SOURCE = @as(u32, 18);
310pub const IP_PKTINFO = @as(u32, 19);
311pub const IP_HOPLIMIT = @as(u32, 21);
312pub const IP_RECVTTL = @as(u32, 21);
313pub const IP_RECEIVE_BROADCAST = @as(u32, 22);
314pub const IP_RECVIF = @as(u32, 24);
315pub const IP_RECVDSTADDR = @as(u32, 25);
316pub const IP_IFLIST = @as(u32, 28);
317pub const IP_ADD_IFLIST = @as(u32, 29);
318pub const IP_DEL_IFLIST = @as(u32, 30);
319pub const IP_UNICAST_IF = @as(u32, 31);
320pub const IP_RTHDR = @as(u32, 32);
321pub const IP_GET_IFLIST = @as(u32, 33);
322pub const IP_RECVRTHDR = @as(u32, 38);
323pub const IP_TCLASS = @as(u32, 39);
324pub const IP_RECVTCLASS = @as(u32, 40);
325pub const IP_RECVTOS = @as(u32, 40);
326pub const IP_ORIGINAL_ARRIVAL_IF = @as(u32, 47);
327pub const IP_ECN = @as(u32, 50);
328pub const IP_PKTINFO_EX = @as(u32, 51);
329pub const IP_WFP_REDIRECT_RECORDS = @as(u32, 60);
330pub const IP_WFP_REDIRECT_CONTEXT = @as(u32, 70);
331pub const IP_MTU_DISCOVER = @as(u32, 71);
332pub const IP_MTU = @as(u32, 73);
333pub const IP_NRT_INTERFACE = @as(u32, 74);
334pub const IP_RECVERR = @as(u32, 75);
335pub const IP_USER_MTU = @as(u32, 76);
336pub const IP_UNSPECIFIED_TYPE_OF_SERVICE = @as(i32, -1);
337pub const IN6ADDR_LINKLOCALPREFIX_LENGTH = @as(u32, 64);
338pub const IN6ADDR_MULTICASTPREFIX_LENGTH = @as(u32, 8);
339pub const IN6ADDR_SOLICITEDNODEMULTICASTPREFIX_LENGTH = @as(u32, 104);
340pub const IN6ADDR_V4MAPPEDPREFIX_LENGTH = @as(u32, 96);
341pub const IN6ADDR_6TO4PREFIX_LENGTH = @as(u32, 16);
342pub const IN6ADDR_TEREDOPREFIX_LENGTH = @as(u32, 32);
343pub const MCAST_JOIN_GROUP = @as(u32, 41);
344pub const MCAST_LEAVE_GROUP = @as(u32, 42);
345pub const MCAST_BLOCK_SOURCE = @as(u32, 43);
346pub const MCAST_UNBLOCK_SOURCE = @as(u32, 44);
347pub const MCAST_JOIN_SOURCE_GROUP = @as(u32, 45);
348pub const MCAST_LEAVE_SOURCE_GROUP = @as(u32, 46);
349pub const IPV6_HOPOPTS = @as(u32, 1);
350pub const IPV6_HDRINCL = @as(u32, 2);
351pub const IPV6_UNICAST_HOPS = @as(u32, 4);
352pub const IPV6_MULTICAST_IF = @as(u32, 9);
353pub const IPV6_MULTICAST_HOPS = @as(u32, 10);
354pub const IPV6_MULTICAST_LOOP = @as(u32, 11);
355pub const IPV6_ADD_MEMBERSHIP = @as(u32, 12);
356pub const IPV6_DROP_MEMBERSHIP = @as(u32, 13);
357pub const IPV6_DONTFRAG = @as(u32, 14);
358pub const IPV6_PKTINFO = @as(u32, 19);
359pub const IPV6_HOPLIMIT = @as(u32, 21);
360pub const IPV6_PROTECTION_LEVEL = @as(u32, 23);
361pub const IPV6_RECVIF = @as(u32, 24);
362pub const IPV6_RECVDSTADDR = @as(u32, 25);
363pub const IPV6_CHECKSUM = @as(u32, 26);
364pub const IPV6_V6ONLY = @as(u32, 27);
365pub const IPV6_IFLIST = @as(u32, 28);
366pub const IPV6_ADD_IFLIST = @as(u32, 29);
367pub const IPV6_DEL_IFLIST = @as(u32, 30);
368pub const IPV6_UNICAST_IF = @as(u32, 31);
369pub const IPV6_RTHDR = @as(u32, 32);
370pub const IPV6_GET_IFLIST = @as(u32, 33);
371pub const IPV6_RECVRTHDR = @as(u32, 38);
372pub const IPV6_TCLASS = @as(u32, 39);
373pub const IPV6_RECVTCLASS = @as(u32, 40);
374pub const IPV6_ECN = @as(u32, 50);
375pub const IPV6_PKTINFO_EX = @as(u32, 51);
376pub const IPV6_WFP_REDIRECT_RECORDS = @as(u32, 60);
377pub const IPV6_WFP_REDIRECT_CONTEXT = @as(u32, 70);
378pub const IPV6_MTU_DISCOVER = @as(u32, 71);
379pub const IPV6_MTU = @as(u32, 72);
380pub const IPV6_NRT_INTERFACE = @as(u32, 74);
381pub const IPV6_RECVERR = @as(u32, 75);
382pub const IPV6_USER_MTU = @as(u32, 76);
383pub const IP_UNSPECIFIED_HOP_LIMIT = @as(i32, -1);
384pub const PROTECTION_LEVEL_UNRESTRICTED = @as(u32, 10);
385pub const PROTECTION_LEVEL_EDGERESTRICTED = @as(u32, 20);
386pub const PROTECTION_LEVEL_RESTRICTED = @as(u32, 30);
387pub const INET_ADDRSTRLEN = @as(u32, 22);
388pub const INET6_ADDRSTRLEN = @as(u32, 65);
389pub const TCP_OFFLOAD_NO_PREFERENCE = @as(u32, 0);
390pub const TCP_OFFLOAD_NOT_PREFERRED = @as(u32, 1);
391pub const TCP_OFFLOAD_PREFERRED = @as(u32, 2);
392pub const TCP_EXPEDITED_1122 = @as(u32, 2);
393pub const TCP_KEEPALIVE = @as(u32, 3);
394pub const TCP_MAXSEG = @as(u32, 4);
395pub const TCP_MAXRT = @as(u32, 5);
396pub const TCP_STDURG = @as(u32, 6);
397pub const TCP_NOURG = @as(u32, 7);
398pub const TCP_ATMARK = @as(u32, 8);
399pub const TCP_NOSYNRETRIES = @as(u32, 9);
400pub const TCP_TIMESTAMPS = @as(u32, 10);
401pub const TCP_OFFLOAD_PREFERENCE = @as(u32, 11);
402pub const TCP_CONGESTION_ALGORITHM = @as(u32, 12);
403pub const TCP_DELAY_FIN_ACK = @as(u32, 13);
404pub const TCP_MAXRTMS = @as(u32, 14);
405pub const TCP_FASTOPEN = @as(u32, 15);
406pub const TCP_KEEPCNT = @as(u32, 16);
407pub const TCP_KEEPINTVL = @as(u32, 17);
408pub const TCP_FAIL_CONNECT_ON_ICMP_ERROR = @as(u32, 18);
409pub const TCP_ICMP_ERROR_INFO = @as(u32, 19);
410pub const UDP_SEND_MSG_SIZE = @as(u32, 2);
411pub const UDP_RECV_MAX_COALESCED_SIZE = @as(u32, 3);
412pub const UDP_COALESCED_INFO = @as(u32, 3);
413pub const AF_UNSPEC = @as(u32, 0);
414pub const AF_UNIX = @as(u32, 1);
415pub const AF_INET = @as(u32, 2);
416pub const AF_IMPLINK = @as(u32, 3);
417pub const AF_PUP = @as(u32, 4);
418pub const AF_CHAOS = @as(u32, 5);
419pub const AF_NS = @as(u32, 6);
420pub const AF_ISO = @as(u32, 7);
421pub const AF_ECMA = @as(u32, 8);
422pub const AF_DATAKIT = @as(u32, 9);
423pub const AF_CCITT = @as(u32, 10);
424pub const AF_SNA = @as(u32, 11);
425pub const AF_DECnet = @as(u32, 12);
426pub const AF_DLI = @as(u32, 13);
427pub const AF_LAT = @as(u32, 14);
428pub const AF_HYLINK = @as(u32, 15);
429pub const AF_APPLETALK = @as(u32, 16);
430pub const AF_NETBIOS = @as(u32, 17);
431pub const AF_VOICEVIEW = @as(u32, 18);
432pub const AF_FIREFOX = @as(u32, 19);
433pub const AF_UNKNOWN1 = @as(u32, 20);
434pub const AF_BAN = @as(u32, 21);
435pub const AF_ATM = @as(u32, 22);
436pub const AF_INET6 = @as(u32, 23);
437pub const AF_CLUSTER = @as(u32, 24);
438pub const AF_12844 = @as(u32, 25);
439pub const AF_IRDA = @as(u32, 26);
440pub const AF_NETDES = @as(u32, 28);
441pub const AF_MAX = @as(u32, 29);
442pub const AF_TCNPROCESS = @as(u32, 29);
443pub const AF_TCNMESSAGE = @as(u32, 30);
444pub const AF_ICLFXBM = @as(u32, 31);
445pub const AF_LINK = @as(u32, 33);
446pub const AF_HYPERV = @as(u32, 34);
447pub const SOCK_STREAM = @as(u32, 1);
448pub const SOCK_DGRAM = @as(u32, 2);
449pub const SOCK_RAW = @as(u32, 3);
450pub const SOCK_RDM = @as(u32, 4);
451pub const SOCK_SEQPACKET = @as(u32, 5);
452pub const SOL_SOCKET = @as(u32, 65535);
453pub const SO_DEBUG = @as(u32, 1);
454pub const SO_ACCEPTCONN = @as(u32, 2);
455pub const SO_REUSEADDR = @as(u32, 4);
456pub const SO_KEEPALIVE = @as(u32, 8);
457pub const SO_DONTROUTE = @as(u32, 16);
458pub const SO_BROADCAST = @as(u32, 32);
459pub const SO_USELOOPBACK = @as(u32, 64);
460pub const SO_LINGER = @as(u32, 128);
461pub const SO_OOBINLINE = @as(u32, 256);
462pub const SO_SNDBUF = @as(u32, 4097);
463pub const SO_RCVBUF = @as(u32, 4098);
464pub const SO_SNDLOWAT = @as(u32, 4099);
465pub const SO_RCVLOWAT = @as(u32, 4100);
466pub const SO_SNDTIMEO = @as(u32, 4101);
467pub const SO_RCVTIMEO = @as(u32, 4102);
468pub const SO_ERROR = @as(u32, 4103);
469pub const SO_TYPE = @as(u32, 4104);
470pub const SO_BSP_STATE = @as(u32, 4105);
471pub const SO_GROUP_ID = @as(u32, 8193);
472pub const SO_GROUP_PRIORITY = @as(u32, 8194);
473pub const SO_MAX_MSG_SIZE = @as(u32, 8195);
474pub const SO_CONDITIONAL_ACCEPT = @as(u32, 12290);
475pub const SO_PAUSE_ACCEPT = @as(u32, 12291);
476pub const SO_COMPARTMENT_ID = @as(u32, 12292);
477pub const SO_RANDOMIZE_PORT = @as(u32, 12293);
478pub const SO_PORT_SCALABILITY = @as(u32, 12294);
479pub const SO_REUSE_UNICASTPORT = @as(u32, 12295);
480pub const SO_REUSE_MULTICASTPORT = @as(u32, 12296);
481pub const SO_ORIGINAL_DST = @as(u32, 12303);
482pub const WSK_SO_BASE = @as(u32, 16384);
483pub const TCP_NODELAY = @as(u32, 1);
484pub const IOC_UNIX = @as(u32, 0);
485pub const IOC_WS2 = @as(u32, 134217728);
486pub const IOC_PROTOCOL = @as(u32, 268435456);
487pub const IOC_VENDOR = @as(u32, 402653184);
488pub const IPPROTO_IP = @as(u32, 0);
489pub const IPPORT_TCPMUX = @as(u32, 1);
490pub const IPPORT_ECHO = @as(u32, 7);
491pub const IPPORT_DISCARD = @as(u32, 9);
492pub const IPPORT_SYSTAT = @as(u32, 11);
493pub const IPPORT_DAYTIME = @as(u32, 13);
494pub const IPPORT_NETSTAT = @as(u32, 15);
495pub const IPPORT_QOTD = @as(u32, 17);
496pub const IPPORT_MSP = @as(u32, 18);
497pub const IPPORT_CHARGEN = @as(u32, 19);
498pub const IPPORT_FTP_DATA = @as(u32, 20);
499pub const IPPORT_FTP = @as(u32, 21);
500pub const IPPORT_TELNET = @as(u32, 23);
501pub const IPPORT_SMTP = @as(u32, 25);
502pub const IPPORT_TIMESERVER = @as(u32, 37);
503pub const IPPORT_NAMESERVER = @as(u32, 42);
504pub const IPPORT_WHOIS = @as(u32, 43);
505pub const IPPORT_MTP = @as(u32, 57);
506pub const IPPORT_TFTP = @as(u32, 69);
507pub const IPPORT_RJE = @as(u32, 77);
508pub const IPPORT_FINGER = @as(u32, 79);
509pub const IPPORT_TTYLINK = @as(u32, 87);
510pub const IPPORT_SUPDUP = @as(u32, 95);
511pub const IPPORT_POP3 = @as(u32, 110);
512pub const IPPORT_NTP = @as(u32, 123);
513pub const IPPORT_EPMAP = @as(u32, 135);
514pub const IPPORT_NETBIOS_NS = @as(u32, 137);
515pub const IPPORT_NETBIOS_DGM = @as(u32, 138);
516pub const IPPORT_NETBIOS_SSN = @as(u32, 139);
517pub const IPPORT_IMAP = @as(u32, 143);
518pub const IPPORT_SNMP = @as(u32, 161);
519pub const IPPORT_SNMP_TRAP = @as(u32, 162);
520pub const IPPORT_IMAP3 = @as(u32, 220);
521pub const IPPORT_LDAP = @as(u32, 389);
522pub const IPPORT_HTTPS = @as(u32, 443);
523pub const IPPORT_MICROSOFT_DS = @as(u32, 445);
524pub const IPPORT_EXECSERVER = @as(u32, 512);
525pub const IPPORT_LOGINSERVER = @as(u32, 513);
526pub const IPPORT_CMDSERVER = @as(u32, 514);
527pub const IPPORT_EFSSERVER = @as(u32, 520);
528pub const IPPORT_BIFFUDP = @as(u32, 512);
529pub const IPPORT_WHOSERVER = @as(u32, 513);
530pub const IPPORT_ROUTESERVER = @as(u32, 520);
531pub const IPPORT_RESERVED = @as(u32, 1024);
532pub const IPPORT_REGISTERED_MAX = @as(u32, 49151);
533pub const IPPORT_DYNAMIC_MIN = @as(u32, 49152);
534pub const IPPORT_DYNAMIC_MAX = @as(u32, 65535);
535pub const IN_CLASSA_NET = @as(u32, 4278190080);
536pub const IN_CLASSA_NSHIFT = @as(u32, 24);
537pub const IN_CLASSA_HOST = @as(u32, 16777215);
538pub const IN_CLASSA_MAX = @as(u32, 128);
539pub const IN_CLASSB_NET = @as(u32, 4294901760);
540pub const IN_CLASSB_NSHIFT = @as(u32, 16);
541pub const IN_CLASSB_HOST = @as(u32, 65535);
542pub const IN_CLASSB_MAX = @as(u32, 65536);
543pub const IN_CLASSC_NET = @as(u32, 4294967040);
544pub const IN_CLASSC_NSHIFT = @as(u32, 8);
545pub const IN_CLASSC_HOST = @as(u32, 255);
546pub const IN_CLASSD_NET = @as(u32, 4026531840);
547pub const IN_CLASSD_NSHIFT = @as(u32, 28);
548pub const IN_CLASSD_HOST = @as(u32, 268435455);
549pub const INADDR_LOOPBACK = @as(u32, 2130706433);
550pub const INADDR_NONE = @as(u32, 4294967295);
551pub const IOCPARM_MASK = @as(u32, 127);
552pub const IOC_VOID = @as(u32, 536870912);
553pub const IOC_OUT = @as(u32, 1073741824);
554pub const IOC_IN = @as(u32, 2147483648);
555pub const MSG_TRUNC = @as(u32, 256);
556pub const MSG_CTRUNC = @as(u32, 512);
557pub const MSG_BCAST = @as(u32, 1024);
558pub const MSG_MCAST = @as(u32, 2048);
559pub const MSG_ERRQUEUE = @as(u32, 4096);
560pub const AI_PASSIVE = @as(u32, 1);
561pub const AI_CANONNAME = @as(u32, 2);
562pub const AI_NUMERICHOST = @as(u32, 4);
563pub const AI_NUMERICSERV = @as(u32, 8);
564pub const AI_DNS_ONLY = @as(u32, 16);
565pub const AI_ALL = @as(u32, 256);
566pub const AI_ADDRCONFIG = @as(u32, 1024);
567pub const AI_V4MAPPED = @as(u32, 2048);
568pub const AI_NON_AUTHORITATIVE = @as(u32, 16384);
569pub const AI_SECURE = @as(u32, 32768);
570pub const AI_RETURN_PREFERRED_NAMES = @as(u32, 65536);
571pub const AI_FQDN = @as(u32, 131072);
572pub const AI_FILESERVER = @as(u32, 262144);
573pub const AI_DISABLE_IDN_ENCODING = @as(u32, 524288);
574pub const AI_EXTENDED = @as(u32, 2147483648);
575pub const AI_RESOLUTION_HANDLE = @as(u32, 1073741824);
576pub const ADDRINFOEX_VERSION_2 = @as(u32, 2);
577pub const ADDRINFOEX_VERSION_3 = @as(u32, 3);
578pub const ADDRINFOEX_VERSION_4 = @as(u32, 4);
579pub const NS_ALL = @as(u32, 0);
580pub const NS_SAP = @as(u32, 1);
581pub const NS_NDS = @as(u32, 2);
582pub const NS_PEER_BROWSE = @as(u32, 3);
583pub const NS_SLP = @as(u32, 5);
584pub const NS_DHCP = @as(u32, 6);
585pub const NS_TCPIP_LOCAL = @as(u32, 10);
586pub const NS_TCPIP_HOSTS = @as(u32, 11);
587pub const NS_DNS = @as(u32, 12);
588pub const NS_NETBT = @as(u32, 13);
589pub const NS_WINS = @as(u32, 14);
590pub const NS_NLA = @as(u32, 15);
591pub const NS_NBP = @as(u32, 20);
592pub const NS_MS = @as(u32, 30);
593pub const NS_STDA = @as(u32, 31);
594pub const NS_NTDS = @as(u32, 32);
595pub const NS_EMAIL = @as(u32, 37);
596pub const NS_X500 = @as(u32, 40);
597pub const NS_NIS = @as(u32, 41);
598pub const NS_NISPLUS = @as(u32, 42);
599pub const NS_WRQ = @as(u32, 50);
600pub const NS_NETDES = @as(u32, 60);
601pub const NI_NOFQDN = @as(u32, 1);
602pub const NI_NUMERICHOST = @as(u32, 2);
603pub const NI_NAMEREQD = @as(u32, 4);
604pub const NI_NUMERICSERV = @as(u32, 8);
605pub const NI_DGRAM = @as(u32, 16);
606pub const NI_MAXHOST = @as(u32, 1025);
607pub const NI_MAXSERV = @as(u32, 32);
608pub const INCL_WINSOCK_API_PROTOTYPES = @as(u32, 1);
609pub const INCL_WINSOCK_API_TYPEDEFS = @as(u32, 0);
610pub const FD_SETSIZE = @as(u32, 64);
611pub const IMPLINK_IP = @as(u32, 155);
612pub const IMPLINK_LOWEXPER = @as(u32, 156);
613pub const IMPLINK_HIGHEXPER = @as(u32, 158);
614pub const WSADESCRIPTION_LEN = @as(u32, 256);
615pub const WSASYS_STATUS_LEN = @as(u32, 128);
616pub const SOCKET_ERROR = @as(i32, -1);
617pub const FROM_PROTOCOL_INFO = @as(i32, -1);
618pub const SO_PROTOCOL_INFOA = @as(u32, 8196);
619pub const SO_PROTOCOL_INFOW = @as(u32, 8197);
620pub const PVD_CONFIG = @as(u32, 12289);
621pub const SOMAXCONN = @as(u32, 2147483647);
622pub const MSG_PEEK = @as(u32, 2);
623pub const MSG_WAITALL = @as(u32, 8);
624pub const MSG_PUSH_IMMEDIATE = @as(u32, 32);
625pub const MSG_PARTIAL = @as(u32, 32768);
626pub const MSG_INTERRUPT = @as(u32, 16);
627pub const MSG_MAXIOVLEN = @as(u32, 16);
628pub const MAXGETHOSTSTRUCT = @as(u32, 1024);
629pub const FD_READ_BIT = @as(u32, 0);
630pub const FD_WRITE_BIT = @as(u32, 1);
631pub const FD_OOB_BIT = @as(u32, 2);
632pub const FD_ACCEPT_BIT = @as(u32, 3);
633pub const FD_CONNECT_BIT = @as(u32, 4);
634pub const FD_CLOSE_BIT = @as(u32, 5);
635pub const FD_QOS_BIT = @as(u32, 6);
636pub const FD_GROUP_QOS_BIT = @as(u32, 7);
637pub const FD_ROUTING_INTERFACE_CHANGE_BIT = @as(u32, 8);
638pub const FD_ADDRESS_LIST_CHANGE_BIT = @as(u32, 9);
639pub const FD_MAX_EVENTS = @as(u32, 10);
640pub const CF_ACCEPT = @as(u32, 0);
641pub const CF_REJECT = @as(u32, 1);
642pub const CF_DEFER = @as(u32, 2);
643pub const SD_RECEIVE = @as(u32, 0);
644pub const SD_SEND = @as(u32, 1);
645pub const SD_BOTH = @as(u32, 2);
646pub const SG_UNCONSTRAINED_GROUP = @as(u32, 1);
647pub const SG_CONSTRAINED_GROUP = @as(u32, 2);
648pub const MAX_PROTOCOL_CHAIN = @as(u32, 7);
649pub const BASE_PROTOCOL = @as(u32, 1);
650pub const LAYERED_PROTOCOL = @as(u32, 0);
651pub const WSAPROTOCOL_LEN = @as(u32, 255);
652pub const PFL_MULTIPLE_PROTO_ENTRIES = @as(u32, 1);
653pub const PFL_RECOMMENDED_PROTO_ENTRY = @as(u32, 2);
654pub const PFL_HIDDEN = @as(u32, 4);
655pub const PFL_MATCHES_PROTOCOL_ZERO = @as(u32, 8);
656pub const PFL_NETWORKDIRECT_PROVIDER = @as(u32, 16);
657pub const XP1_CONNECTIONLESS = @as(u32, 1);
658pub const XP1_GUARANTEED_DELIVERY = @as(u32, 2);
659pub const XP1_GUARANTEED_ORDER = @as(u32, 4);
660pub const XP1_MESSAGE_ORIENTED = @as(u32, 8);
661pub const XP1_PSEUDO_STREAM = @as(u32, 16);
662pub const XP1_GRACEFUL_CLOSE = @as(u32, 32);
663pub const XP1_EXPEDITED_DATA = @as(u32, 64);
664pub const XP1_CONNECT_DATA = @as(u32, 128);
665pub const XP1_DISCONNECT_DATA = @as(u32, 256);
666pub const XP1_SUPPORT_BROADCAST = @as(u32, 512);
667pub const XP1_SUPPORT_MULTIPOINT = @as(u32, 1024);
668pub const XP1_MULTIPOINT_CONTROL_PLANE = @as(u32, 2048);
669pub const XP1_MULTIPOINT_DATA_PLANE = @as(u32, 4096);
670pub const XP1_QOS_SUPPORTED = @as(u32, 8192);
671pub const XP1_INTERRUPT = @as(u32, 16384);
672pub const XP1_UNI_SEND = @as(u32, 32768);
673pub const XP1_UNI_RECV = @as(u32, 65536);
674pub const XP1_IFS_HANDLES = @as(u32, 131072);
675pub const XP1_PARTIAL_MESSAGE = @as(u32, 262144);
676pub const XP1_SAN_SUPPORT_SDP = @as(u32, 524288);
677pub const BIGENDIAN = @as(u32, 0);
678pub const LITTLEENDIAN = @as(u32, 1);
679pub const SECURITY_PROTOCOL_NONE = @as(u32, 0);
680pub const JL_SENDER_ONLY = @as(u32, 1);
681pub const JL_RECEIVER_ONLY = @as(u32, 2);
682pub const JL_BOTH = @as(u32, 4);
683pub const WSA_FLAG_OVERLAPPED = @as(u32, 1);
684pub const WSA_FLAG_MULTIPOINT_C_ROOT = @as(u32, 2);
685pub const WSA_FLAG_MULTIPOINT_C_LEAF = @as(u32, 4);
686pub const WSA_FLAG_MULTIPOINT_D_ROOT = @as(u32, 8);
687pub const WSA_FLAG_MULTIPOINT_D_LEAF = @as(u32, 16);
688pub const WSA_FLAG_ACCESS_SYSTEM_SECURITY = @as(u32, 64);
689pub const WSA_FLAG_NO_HANDLE_INHERIT = @as(u32, 128);
690pub const WSA_FLAG_REGISTERED_IO = @as(u32, 256);
691pub const TH_NETDEV = @as(u32, 1);
692pub const TH_TAPI = @as(u32, 2);
693pub const SERVICE_MULTIPLE = @as(u32, 1);
694pub const NS_LOCALNAME = @as(u32, 19);
695pub const RES_UNUSED_1 = @as(u32, 1);
696pub const RES_FLUSH_CACHE = @as(u32, 2);
697pub const RES_SERVICE = @as(u32, 4);
698pub const LUP_DEEP = @as(u32, 1);
699pub const LUP_CONTAINERS = @as(u32, 2);
700pub const LUP_NOCONTAINERS = @as(u32, 4);
701pub const LUP_NEAREST = @as(u32, 8);
702pub const LUP_RETURN_NAME = @as(u32, 16);
703pub const LUP_RETURN_TYPE = @as(u32, 32);
704pub const LUP_RETURN_VERSION = @as(u32, 64);
705pub const LUP_RETURN_COMMENT = @as(u32, 128);
706pub const LUP_RETURN_ADDR = @as(u32, 256);
707pub const LUP_RETURN_BLOB = @as(u32, 512);
708pub const LUP_RETURN_ALIASES = @as(u32, 1024);
709pub const LUP_RETURN_QUERY_STRING = @as(u32, 2048);
710pub const LUP_RETURN_ALL = @as(u32, 4080);
711pub const LUP_RES_SERVICE = @as(u32, 32768);
712pub const LUP_FLUSHCACHE = @as(u32, 4096);
713pub const LUP_FLUSHPREVIOUS = @as(u32, 8192);
714pub const LUP_NON_AUTHORITATIVE = @as(u32, 16384);
715pub const LUP_SECURE = @as(u32, 32768);
716pub const LUP_RETURN_PREFERRED_NAMES = @as(u32, 65536);
717pub const LUP_DNS_ONLY = @as(u32, 131072);
718pub const LUP_ADDRCONFIG = @as(u32, 1048576);
719pub const LUP_DUAL_ADDR = @as(u32, 2097152);
720pub const LUP_FILESERVER = @as(u32, 4194304);
721pub const LUP_DISABLE_IDN_ENCODING = @as(u32, 8388608);
722pub const LUP_API_ANSI = @as(u32, 16777216);
723pub const LUP_RESOLUTION_HANDLE = @as(u32, 2147483648);
724pub const RESULT_IS_ALIAS = @as(u32, 1);
725pub const RESULT_IS_ADDED = @as(u32, 16);
726pub const RESULT_IS_CHANGED = @as(u32, 32);
727pub const RESULT_IS_DELETED = @as(u32, 64);
728pub const POLLRDNORM = @as(u32, 256);
729pub const POLLRDBAND = @as(u32, 512);
730pub const POLLPRI = @as(u32, 1024);
731pub const POLLWRNORM = @as(u32, 16);
732pub const POLLWRBAND = @as(u32, 32);
733pub const POLLERR = @as(u32, 1);
734pub const POLLHUP = @as(u32, 2);
735pub const POLLNVAL = @as(u32, 4);
736pub const SO_CONNDATA = @as(u32, 28672);
737pub const SO_CONNOPT = @as(u32, 28673);
738pub const SO_DISCDATA = @as(u32, 28674);
739pub const SO_DISCOPT = @as(u32, 28675);
740pub const SO_CONNDATALEN = @as(u32, 28676);
741pub const SO_CONNOPTLEN = @as(u32, 28677);
742pub const SO_DISCDATALEN = @as(u32, 28678);
743pub const SO_DISCOPTLEN = @as(u32, 28679);
744pub const SO_OPENTYPE = @as(u32, 28680);
745pub const SO_SYNCHRONOUS_ALERT = @as(u32, 16);
746pub const SO_SYNCHRONOUS_NONALERT = @as(u32, 32);
747pub const SO_MAXDG = @as(u32, 28681);
748pub const SO_MAXPATHDG = @as(u32, 28682);
749pub const SO_UPDATE_ACCEPT_CONTEXT = @as(u32, 28683);
750pub const SO_CONNECT_TIME = @as(u32, 28684);
751pub const SO_UPDATE_CONNECT_CONTEXT = @as(u32, 28688);
752pub const TCP_BSDURGENT = @as(u32, 28672);
753pub const TF_DISCONNECT = @as(u32, 1);
754pub const TF_REUSE_SOCKET = @as(u32, 2);
755pub const TF_WRITE_BEHIND = @as(u32, 4);
756pub const TF_USE_DEFAULT_WORKER = @as(u32, 0);
757pub const TF_USE_SYSTEM_THREAD = @as(u32, 16);
758pub const TF_USE_KERNEL_APC = @as(u32, 32);
759pub const TP_ELEMENT_MEMORY = @as(u32, 1);
760pub const TP_ELEMENT_FILE = @as(u32, 2);
761pub const TP_ELEMENT_EOP = @as(u32, 4);
762pub const NLA_ALLUSERS_NETWORK = @as(u32, 1);
763pub const NLA_FRIENDLY_NAME = @as(u32, 2);
764pub const WSPDESCRIPTION_LEN = @as(u32, 255);
765pub const WSS_OPERATION_IN_PROGRESS = @as(i32, 259);
766pub const LSP_SYSTEM = @as(u32, 2147483648);
767pub const LSP_INSPECTOR = @as(u32, 1);
768pub const LSP_REDIRECTOR = @as(u32, 2);
769pub const LSP_PROXY = @as(u32, 4);
770pub const LSP_FIREWALL = @as(u32, 8);
771pub const LSP_INBOUND_MODIFY = @as(u32, 16);
772pub const LSP_OUTBOUND_MODIFY = @as(u32, 32);
773pub const LSP_CRYPTO_COMPRESS = @as(u32, 64);
774pub const LSP_LOCAL_CACHE = @as(u32, 128);
775pub const IPPROTO_ICMP = @as(u32, 1);
776pub const IPPROTO_IGMP = @as(u32, 2);
777pub const IPPROTO_GGP = @as(u32, 3);
778pub const IPPROTO_TCP = @as(u32, 6);
779pub const IPPROTO_PUP = @as(u32, 12);
780pub const IPPROTO_UDP = @as(u32, 17);
781pub const IPPROTO_IDP = @as(u32, 22);
782pub const IPPROTO_ND = @as(u32, 77);
783pub const IPPROTO_RAW = @as(u32, 255);
784pub const IPPROTO_MAX = @as(u32, 256);
785pub const IP_DEFAULT_MULTICAST_TTL = @as(u32, 1);
786pub const IP_DEFAULT_MULTICAST_LOOP = @as(u32, 1);
787pub const IP_MAX_MEMBERSHIPS = @as(u32, 20);
788pub const AF_IPX = @as(u32, 6);
789pub const FD_READ = @as(u32, 1);
790pub const FD_WRITE = @as(u32, 2);
791pub const FD_OOB = @as(u32, 4);
792pub const FD_ACCEPT = @as(u32, 8);
793pub const FD_CONNECT = @as(u32, 16);
794pub const FD_CLOSE = @as(u32, 32);
795pub const SERVICE_RESOURCE = @as(u32, 1);
796pub const SERVICE_SERVICE = @as(u32, 2);
797pub const SERVICE_LOCAL = @as(u32, 4);
798pub const SERVICE_FLAG_DEFER = @as(u32, 1);
799pub const SERVICE_FLAG_HARD = @as(u32, 2);
800pub const PROP_COMMENT = @as(u32, 1);
801pub const PROP_LOCALE = @as(u32, 2);
802pub const PROP_DISPLAY_HINT = @as(u32, 4);
803pub const PROP_VERSION = @as(u32, 8);
804pub const PROP_START_TIME = @as(u32, 16);
805pub const PROP_MACHINE = @as(u32, 32);
806pub const PROP_ADDRESSES = @as(u32, 256);
807pub const PROP_SD = @as(u32, 512);
808pub const PROP_ALL = @as(u32, 2147483648);
809pub const SERVICE_ADDRESS_FLAG_RPC_CN = @as(u32, 1);
810pub const SERVICE_ADDRESS_FLAG_RPC_DG = @as(u32, 2);
811pub const SERVICE_ADDRESS_FLAG_RPC_NB = @as(u32, 4);
812pub const NS_DEFAULT = @as(u32, 0);
813pub const NS_VNS = @as(u32, 50);
814pub const NSTYPE_HIERARCHICAL = @as(u32, 1);
815pub const NSTYPE_DYNAMIC = @as(u32, 2);
816pub const NSTYPE_ENUMERABLE = @as(u32, 4);
817pub const NSTYPE_WORKGROUP = @as(u32, 8);
818pub const XP_CONNECTIONLESS = @as(u32, 1);
819pub const XP_GUARANTEED_DELIVERY = @as(u32, 2);
820pub const XP_GUARANTEED_ORDER = @as(u32, 4);
821pub const XP_MESSAGE_ORIENTED = @as(u32, 8);
822pub const XP_PSEUDO_STREAM = @as(u32, 16);
823pub const XP_GRACEFUL_CLOSE = @as(u32, 32);
824pub const XP_EXPEDITED_DATA = @as(u32, 64);
825pub const XP_CONNECT_DATA = @as(u32, 128);
826pub const XP_DISCONNECT_DATA = @as(u32, 256);
827pub const XP_SUPPORTS_BROADCAST = @as(u32, 512);
828pub const XP_SUPPORTS_MULTICAST = @as(u32, 1024);
829pub const XP_BANDWIDTH_ALLOCATION = @as(u32, 2048);
830pub const XP_FRAGMENTATION = @as(u32, 4096);
831pub const XP_ENCRYPTS = @as(u32, 8192);
832pub const RES_SOFT_SEARCH = @as(u32, 1);
833pub const RES_FIND_MULTIPLE = @as(u32, 2);
834pub const SET_SERVICE_PARTIAL_SUCCESS = @as(u32, 1);
835pub const UDP_NOCHECKSUM = @as(u32, 1);
836pub const UDP_CHECKSUM_COVERAGE = @as(u32, 20);
837pub const GAI_STRERROR_BUFFER_SIZE = @as(u32, 1024);
838
839pub const LPCONDITIONPROC = fn (
840 lpCallerId: *WSABUF,
841 lpCallerData: *WSABUF,
842 lpSQOS: *QOS,
843 lpGQOS: *QOS,
844 lpCalleeId: *WSABUF,
845 lpCalleeData: *WSABUF,
846 g: *u32,
847 dwCallbackData: usize,
848) callconv(WINAPI) i32;
849
850pub const LPWSAOVERLAPPED_COMPLETION_ROUTINE = fn (
851 dwError: u32,
852 cbTransferred: u32,
853 lpOverlapped: *OVERLAPPED,
854 dwFlags: u32,
855) callconv(WINAPI) void;
856
857pub const FLOWSPEC = extern struct {
858 TokenRate: u32,
859 TokenBucketSize: u32,
860 PeakBandwidth: u32,
861 Latency: u32,
862 DelayVariation: u32,
863 ServiceType: u32,
864 MaxSduSize: u32,
865 MinimumPolicedSize: u32,
866};
867
868pub const QOS = extern struct {
869 SendingFlowspec: FLOWSPEC,
870 ReceivingFlowspec: FLOWSPEC,
871 ProviderSpecific: WSABUF,
872};
873
874pub const SOCKET_ADDRESS = extern struct {
875 lpSockaddr: *sockaddr,
876 iSockaddrLength: i32,
877};
878
879pub const SOCKET_ADDRESS_LIST = extern struct {
880 iAddressCount: i32,
881 Address: [1]SOCKET_ADDRESS,
882};
14883
15pub const WSADATA = if (@sizeOf(usize) == @sizeOf(u64))884pub const WSADATA = if (@sizeOf(usize) == @sizeOf(u64))
16 extern struct {885 extern struct {
...@@ -33,15 +902,11 @@ else...@@ -33,15 +902,11 @@ else
33 lpVendorInfo: *u8,902 lpVendorInfo: *u8,
34 };903 };
35904
36pub const MAX_PROTOCOL_CHAIN = 7;
37
38pub const WSAPROTOCOLCHAIN = extern struct {905pub const WSAPROTOCOLCHAIN = extern struct {
39 ChainLen: c_int,906 ChainLen: c_int,
40 ChainEntries: [MAX_PROTOCOL_CHAIN]DWORD,907 ChainEntries: [MAX_PROTOCOL_CHAIN]DWORD,
41};908};
42909
43pub const WSAPROTOCOL_LEN = 255;
44
45pub const WSAPROTOCOL_INFOA = extern struct {910pub const WSAPROTOCOL_INFOA = extern struct {
46 dwServiceFlags1: DWORD,911 dwServiceFlags1: DWORD,
47 dwServiceFlags2: DWORD,912 dwServiceFlags2: DWORD,
...@@ -88,20 +953,20 @@ pub const WSAPROTOCOL_INFOW = extern struct {...@@ -88,20 +953,20 @@ pub const WSAPROTOCOL_INFOW = extern struct {
88 szProtocol: [WSAPROTOCOL_LEN + 1]WCHAR,953 szProtocol: [WSAPROTOCOL_LEN + 1]WCHAR,
89};954};
90955
91pub const GROUP = u32;956pub const sockproto = extern struct {
92957 sp_family: u16,
93pub const SG_UNCONSTRAINED_GROUP = 0x1;958 sp_protocol: u16,
94pub const SG_CONSTRAINED_GROUP = 0x2;959};
95960
96pub const WSA_FLAG_OVERLAPPED = 0x01;961pub const linger = extern struct {
97pub const WSA_FLAG_MULTIPOINT_C_ROOT = 0x02;962 l_onoff: u16,
98pub const WSA_FLAG_MULTIPOINT_C_LEAF = 0x04;963 l_linger: u16,
99pub const WSA_FLAG_MULTIPOINT_D_ROOT = 0x08;964};
100pub const WSA_FLAG_MULTIPOINT_D_LEAF = 0x10;
101pub const WSA_FLAG_ACCESS_SYSTEM_SECURITY = 0x40;
102pub const WSA_FLAG_NO_HANDLE_INHERIT = 0x80;
103965
104pub const WSAEVENT = HANDLE;966pub const WSANETWORKEVENTS = extern struct {
967 lNetworkEvents: i32,
968 iErrorCode: [10]i32,
969};
105970
106pub const WSAOVERLAPPED = extern struct {971pub const WSAOVERLAPPED = extern struct {
107 Internal: DWORD,972 Internal: DWORD,
...@@ -111,82 +976,9 @@ pub const WSAOVERLAPPED = extern struct {...@@ -111,82 +976,9 @@ pub const WSAOVERLAPPED = extern struct {
111 hEvent: ?WSAEVENT,976 hEvent: ?WSAEVENT,
112};977};
113978
114pub const WSAOVERLAPPED_COMPLETION_ROUTINE = fn (dwError: DWORD, cbTransferred: DWORD, lpOverlapped: *WSAOVERLAPPED, dwFlags: DWORD) callconv(.C) void;979pub const addrinfo = addrinfoa;
115
116pub const ADDRESS_FAMILY = u16;
117980
118// Microsoft use the signed c_int for this, but it should never be negative981pub const addrinfoa = extern struct {
119pub const socklen_t = u32;
120
121pub const AF_UNSPEC = 0;
122pub const AF_UNIX = 1;
123pub const AF_INET = 2;
124pub const AF_IMPLINK = 3;
125pub const AF_PUP = 4;
126pub const AF_CHAOS = 5;
127pub const AF_NS = 6;
128pub const AF_IPX = AF_NS;
129pub const AF_ISO = 7;
130pub const AF_OSI = AF_ISO;
131pub const AF_ECMA = 8;
132pub const AF_DATAKIT = 9;
133pub const AF_CCITT = 10;
134pub const AF_SNA = 11;
135pub const AF_DECnet = 12;
136pub const AF_DLI = 13;
137pub const AF_LAT = 14;
138pub const AF_HYLINK = 15;
139pub const AF_APPLETALK = 16;
140pub const AF_NETBIOS = 17;
141pub const AF_VOICEVIEW = 18;
142pub const AF_FIREFOX = 19;
143pub const AF_UNKNOWN1 = 20;
144pub const AF_BAN = 21;
145pub const AF_ATM = 22;
146pub const AF_INET6 = 23;
147pub const AF_CLUSTER = 24;
148pub const AF_12844 = 25;
149pub const AF_IRDA = 26;
150pub const AF_NETDES = 28;
151pub const AF_TCNPROCESS = 29;
152pub const AF_TCNMESSAGE = 30;
153pub const AF_ICLFXBM = 31;
154pub const AF_BTH = 32;
155pub const AF_MAX = 33;
156
157pub const SOCK_STREAM = 1;
158pub const SOCK_DGRAM = 2;
159pub const SOCK_RAW = 3;
160pub const SOCK_RDM = 4;
161pub const SOCK_SEQPACKET = 5;
162
163pub const IPPROTO_ICMP = 1;
164pub const IPPROTO_IGMP = 2;
165pub const BTHPROTO_RFCOMM = 3;
166pub const IPPROTO_TCP = 6;
167pub const IPPROTO_UDP = 17;
168pub const IPPROTO_ICMPV6 = 58;
169pub const IPPROTO_RM = 113;
170
171pub const AI_PASSIVE = 0x00001;
172pub const AI_CANONNAME = 0x00002;
173pub const AI_NUMERICHOST = 0x00004;
174pub const AI_NUMERICSERV = 0x00008;
175pub const AI_ADDRCONFIG = 0x00400;
176pub const AI_V4MAPPED = 0x00800;
177pub const AI_NON_AUTHORITATIVE = 0x04000;
178pub const AI_SECURE = 0x08000;
179pub const AI_RETURN_PREFERRED_NAMES = 0x10000;
180pub const AI_DISABLE_IDN_ENCODING = 0x80000;
181
182pub const FIONBIO = -2147195266;
183
184pub const sockaddr = extern struct {
185 family: ADDRESS_FAMILY,
186 data: [14]u8,
187};
188
189pub const addrinfo = extern struct {
190 flags: i32,982 flags: i32,
191 family: i32,983 family: i32,
192 socktype: i32,984 socktype: i32,
...@@ -197,6 +989,32 @@ pub const addrinfo = extern struct {...@@ -197,6 +989,32 @@ pub const addrinfo = extern struct {
197 next: ?*addrinfo,989 next: ?*addrinfo,
198};990};
199991
992pub const addrinfoexA = extern struct {
993 ai_flags: i32,
994 ai_family: i32,
995 ai_socktype: i32,
996 ai_protocol: i32,
997 ai_addrlen: usize,
998 ai_canonname: [*:0]u8,
999 ai_addr: *sockaddr,
1000 ai_blob: *c_void,
1001 ai_bloblen: usize,
1002 ai_provider: *Guid,
1003 ai_next: *addrinfoexA,
1004};
1005
1006pub const sockaddr = extern struct {
1007 family: ADDRESS_FAMILY,
1008 data: [14]u8,
1009};
1010
1011pub const sockaddr_storage = extern struct {
1012 family: ADDRESS_FAMILY,
1013 __pad1: [6]u8,
1014 __align: i64,
1015 __pad2: [112]u8,
1016};
1017
200/// IPv4 socket address1018/// IPv4 socket address
201pub const sockaddr_in = extern struct {1019pub const sockaddr_in = extern struct {
202 family: ADDRESS_FAMILY = AF_INET,1020 family: ADDRESS_FAMILY = AF_INET,
...@@ -225,7 +1043,10 @@ pub const WSABUF = extern struct {...@@ -225,7 +1043,10 @@ pub const WSABUF = extern struct {
225 buf: [*]u8,1043 buf: [*]u8,
226};1044};
2271045
228pub const WSAMSG = extern struct {1046pub const msghdr = WSAMSG;
1047pub const msghdr_const = WSAMSG_const;
1048
1049pub const WSAMSG_const = extern struct {
229 name: *const sockaddr,1050 name: *const sockaddr,
230 namelen: INT,1051 namelen: INT,
231 lpBuffers: [*]WSABUF,1052 lpBuffers: [*]WSABUF,
...@@ -234,26 +1055,108 @@ pub const WSAMSG = extern struct {...@@ -234,26 +1055,108 @@ pub const WSAMSG = extern struct {
234 dwFlags: DWORD,1055 dwFlags: DWORD,
235};1056};
2361057
1058pub const WSAMSG = extern struct {
1059 name: *sockaddr,
1060 namelen: INT,
1061 lpBuffers: [*]WSABUF,
1062 dwBufferCount: DWORD,
1063 Control: WSABUF,
1064 dwFlags: DWORD,
1065};
1066
1067pub const WSAPOLLFD = pollfd;
1068
237pub const pollfd = extern struct {1069pub const pollfd = extern struct {
238 fd: SOCKET,1070 fd: SOCKET,
239 events: SHORT,1071 events: SHORT,
240 revents: SHORT,1072 revents: SHORT,
241};1073};
2421074
243// Event flag definitions for WSAPoll().1075pub const TRANSMIT_FILE_BUFFERS = extern struct {
1076 Head: *c_void,
1077 HeadLength: u32,
1078 Tail: *c_void,
1079 TailLength: u32,
1080};
1081
1082pub const LPFN_TRANSMITFILE = fn (
1083 hSocket: SOCKET,
1084 hFile: HANDLE,
1085 nNumberOfBytesToWrite: u32,
1086 nNumberOfBytesPerSend: u32,
1087 lpOverlapped: ?*OVERLAPPED,
1088 lpTransmitBuffers: ?*TRANSMIT_FILE_BUFFERS,
1089 dwReserved: u32,
1090) callconv(WINAPI) BOOL;
1091
1092pub const LPFN_ACCEPTEX = fn (
1093 sListenSocket: SOCKET,
1094 sAcceptSocket: SOCKET,
1095 lpOutputBuffer: *c_void,
1096 dwReceiveDataLength: u32,
1097 dwLocalAddressLength: u32,
1098 dwRemoteAddressLength: u32,
1099 lpdwBytesReceived: *u32,
1100 lpOverlapped: *OVERLAPPED,
1101) callconv(WINAPI) BOOL;
1102
1103pub const LPFN_GETACCEPTEXSOCKADDRS = fn (
1104 lpOutputBuffer: *c_void,
1105 dwReceiveDataLength: u32,
1106 dwLocalAddressLength: u32,
1107 dwRemoteAddressLength: u32,
1108 LocalSockaddr: **sockaddr,
1109 LocalSockaddrLength: *i32,
1110 RemoteSockaddr: **sockaddr,
1111 RemoteSockaddrLength: *i32,
1112) callconv(WINAPI) void;
1113
1114pub const LFN_WSASENDMSG = fn (
1115 s: SOCKET,
1116 lpMsg: *WSAMSG_const,
1117 dwFlags: u32,
1118 lpNumberOfBytesSent: ?*u32,
1119 lpOverlapped: ?*OVERLAPPED,
1120 lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1121) callconv(WINAPI) i32;
2441122
245pub const POLLRDNORM = 0x0100;1123pub const LPFN_WSARECVMSG = fn (
246pub const POLLRDBAND = 0x0200;1124 s: SOCKET,
247pub const POLLIN = (POLLRDNORM | POLLRDBAND);1125 lpMsg: *WSAMSG,
248pub const POLLPRI = 0x0400;1126 lpdwNumberOfBytesRecv: ?*u32,
1127 lpOverlapped: ?*OVERLAPPED,
1128 lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1129) callconv(WINAPI) i32;
2491130
250pub const POLLWRNORM = 0x0010;1131pub const LPSERVICE_CALLBACK_PROC = fn (
251pub const POLLOUT = (POLLWRNORM);1132 lParam: LPARAM,
252pub const POLLWRBAND = 0x0020;1133 hAsyncTaskHandle: HANDLE,
1134) callconv(WINAPI) void;
2531135
254pub const POLLERR = 0x0001;1136pub const SERVICE_ASYNC_INFO = extern struct {
255pub const POLLHUP = 0x0002;1137 lpServiceCallbackProc: LPSERVICE_CALLBACK_PROC,
256pub const POLLNVAL = 0x0004;1138 lParam: LPARAM,
1139 hAsyncTaskHandle: HANDLE,
1140};
1141
1142pub const LPLOOKUPSERVICE_COMPLETION_ROUTINE = fn (
1143 dwError: u32,
1144 dwBytes: u32,
1145 lpOverlapped: *OVERLAPPED,
1146) callconv(WINAPI) void;
1147
1148pub const fd_set = extern struct {
1149 fd_count: u32,
1150 fd_array: [64]SOCKET,
1151};
1152
1153pub const hostent = extern struct {
1154 h_name: [*]u8,
1155 h_aliases: **i8,
1156 h_addrtype: i16,
1157 h_length: i16,
1158 h_addr_list: **i8,
1159};
2571160
258// https://docs.microsoft.com/en-au/windows/win32/winsock/windows-sockets-error-codes-21161// https://docs.microsoft.com/en-au/windows/win32/winsock/windows-sockets-error-codes-2
259pub const WinsockError = extern enum(u16) {1162pub const WinsockError = extern enum(u16) {
...@@ -704,180 +1607,649 @@ pub const WinsockError = extern enum(u16) {...@@ -704,180 +1607,649 @@ pub const WinsockError = extern enum(u16) {
704 _,1607 _,
705};1608};
7061609
707/// no parameters1610pub extern "ws2_32" fn accept(
708const IOC_VOID = 0x80000000;1611 s: SOCKET,
1612 addr: ?*sockaddr,
1613 addrlen: ?*i32,
1614) callconv(WINAPI) SOCKET;
1615
1616pub extern "ws2_32" fn bind(
1617 s: SOCKET,
1618 name: *const sockaddr,
1619 namelen: i32,
1620) callconv(WINAPI) i32;
1621
1622pub extern "ws2_32" fn closesocket(
1623 s: SOCKET,
1624) callconv(WINAPI) i32;
7091625
710/// copy out parameters1626pub extern "ws2_32" fn connect(
711const IOC_OUT = 0x40000000;1627 s: SOCKET,
1628 name: *const sockaddr,
1629 namelen: i32,
1630) callconv(WINAPI) i32;
7121631
713/// copy in parameters1632pub extern "ws2_32" fn ioctlsocket(
714const IOC_IN = 0x80000000;1633 s: SOCKET,
1634 cmd: i32,
1635 argp: *u32,
1636) callconv(WINAPI) i32;
7151637
716/// The IOCTL is a generic Windows Sockets 2 IOCTL code. New IOCTL codes defined for Windows Sockets 2 will have T == 1.1638pub extern "ws2_32" fn getpeername(
717const IOC_WS2 = 0x08000000;1639 s: SOCKET,
1640 name: *sockaddr,
1641 namelen: *i32,
1642) callconv(WINAPI) i32;
7181643
719pub const SIO_BASE_HANDLE = IOC_OUT | IOC_WS2 | 34;1644pub extern "ws2_32" fn getsockname(
1645 s: SOCKET,
1646 name: *sockaddr,
1647 namelen: *i32,
1648) callconv(WINAPI) i32;
1649
1650pub extern "ws2_32" fn getsockopt(
1651 s: SOCKET,
1652 level: i32,
1653 optname: i32,
1654 optval: [*]u8,
1655 optlen: *i32,
1656) callconv(WINAPI) i32;
1657
1658pub extern "ws2_32" fn htonl(
1659 hostlong: u32,
1660) callconv(WINAPI) u32;
1661
1662pub extern "ws2_32" fn htons(
1663 hostshort: u16,
1664) callconv(WINAPI) u16;
1665
1666pub extern "ws2_32" fn inet_addr(
1667 cp: [*]const u8,
1668) callconv(WINAPI) u32;
1669
1670pub extern "ws2_32" fn listen(
1671 s: SOCKET,
1672 backlog: i32,
1673) callconv(WINAPI) i32;
1674
1675pub extern "ws2_32" fn ntohl(
1676 netlong: u32,
1677) callconv(WINAPI) u32;
1678
1679pub extern "ws2_32" fn ntohs(
1680 netshort: u16,
1681) callconv(WINAPI) u16;
1682
1683pub extern "ws2_32" fn recv(
1684 s: SOCKET,
1685 buf: [*]u8,
1686 len: i32,
1687 flags: i32,
1688) callconv(WINAPI) i32;
7201689
721pub const SOL_SOCKET = 0xffff;1690pub extern "ws2_32" fn recvfrom(
1691 s: SOCKET,
1692 buf: [*]u8,
1693 len: i32,
1694 flags: i32,
1695 from: ?*sockaddr,
1696 fromlen: ?*i32,
1697) callconv(WINAPI) i32;
7221698
723pub const SO_DEBUG = 0x0001;1699pub extern "ws2_32" fn select(
724pub const SO_ACCEPTCONN = 0x0002;1700 nfds: i32,
725pub const SO_REUSEADDR = 0x0004;1701 readfds: ?*fd_set,
726pub const SO_KEEPALIVE = 0x0008;1702 writefds: ?*fd_set,
727pub const SO_DONTROUTE = 0x0010;1703 exceptfds: ?*fd_set,
728pub const SO_BROADCAST = 0x0020;1704 timeout: ?*const timeval,
729pub const SO_USELOOPBACK = 0x0040;1705) callconv(WINAPI) i32;
730pub const SO_LINGER = 0x0080;
731pub const SO_OOBINLINE = 0x0100;
7321706
733pub const SO_DONTLINGER = ~@as(u32, SO_LINGER);1707pub extern "ws2_32" fn send(
734pub const SO_EXCLUSIVEADDRUSE = ~@as(u32, SO_REUSEADDR);1708 s: SOCKEt,
1709 buf: [*]const u8,
1710 len: i32,
1711 flags: u32,
1712) callconv(WINAPI) i32;
7351713
736pub const SO_SNDBUF = 0x1001;1714pub extern "ws2_32" fn sendto(
737pub const SO_RCVBUF = 0x1002;1715 s: SOCKET,
738pub const SO_SNDLOWAT = 0x1003;1716 buf: [*]const u8,
739pub const SO_RCVLOWAT = 0x1004;1717 len: i32,
740pub const SO_SNDTIMEO = 0x1005;1718 flags: i32,
741pub const SO_RCVTIMEO = 0x1006;1719 to: *const sockaddr,
742pub const SO_ERROR = 0x1007;1720 tolen: i32,
743pub const SO_TYPE = 0x1008;1721) callconv(WINAPI) i32;
7441722
745pub const SO_GROUP_ID = 0x2001;1723pub extern "ws2_32" fn setsockopt(
746pub const SO_GROUP_PRIORITY = 0x2002;1724 s: SOCKET,
747pub const SO_MAX_MSG_SIZE = 0x2003;1725 level: i32,
748pub const SO_PROTOCOL_INFOA = 0x2004;1726 optname: i32,
749pub const SO_PROTOCOL_INFOW = 0x2005;1727 optval: ?[*]const u8,
1728 optlen: i32,
1729) callconv(WINAPI) i32;
7501730
751pub const PVD_CONFIG = 0x3001;1731pub extern "ws2_32" fn shutdown(
752pub const SO_CONDITIONAL_ACCEPT = 0x3002;1732 s: SOCKET,
1733 how: i32,
1734) callconv(WINAPI) i32;
7531735
754pub const TCP_NODELAY = 0x0001;1736pub extern "ws2_32" fn socket(
1737 af: i32,
1738 @"type": i32,
1739 protocol: i32,
1740) callconv(WINAPI) SOCKET;
7551741
756pub extern "ws2_32" fn WSAStartup(1742pub extern "ws2_32" fn WSAStartup(
757 wVersionRequired: WORD,1743 wVersionRequired: WORD,
758 lpWSAData: *WSADATA,1744 lpWSAData: *WSADATA,
759) callconv(WINAPI) c_int;1745) callconv(WINAPI) i32;
760pub extern "ws2_32" fn WSACleanup() callconv(WINAPI) c_int;1746
1747pub extern "ws2_32" fn WSACleanup() callconv(WINAPI) i32;
1748
1749pub extern "ws2_32" fn WSASetLastError(iError: i32) callconv(WINAPI) void;
1750
761pub extern "ws2_32" fn WSAGetLastError() callconv(WINAPI) WinsockError;1751pub extern "ws2_32" fn WSAGetLastError() callconv(WINAPI) WinsockError;
762pub extern "ws2_32" fn WSASocketA(1752
763 af: c_int,1753pub extern "ws2_32" fn WSAIsBlocking(WINAPI) BOOL;
764 type: c_int,1754
765 protocol: c_int,1755pub extern "ws2_32" fn WSAUnhookBlockingHook() callconv(WINAPI) i32;
766 lpProtocolInfo: ?*WSAPROTOCOL_INFOA,1756
767 g: GROUP,1757pub extern "ws2_32" fn WSASetBlockingHook(lpBlockFunc: FARPROC) FARPROC;
768 dwFlags: DWORD,1758
769) callconv(WINAPI) SOCKET;1759pub extern "ws2_32" fn WSACancelBlockingCall() callconv(WINAPI) i32;
770pub extern "ws2_32" fn WSASocketW(1760
771 af: c_int,1761pub extern "ws2_32" fn WSAAsyncGetServByName(
772 type: c_int,1762 hWnd: HWND,
773 protocol: c_int,1763 wMsg: u32,
774 lpProtocolInfo: ?*WSAPROTOCOL_INFOW,1764 name: [*:0]const u8,
775 g: GROUP,1765 proto: ?[*:0]const u8,
776 dwFlags: DWORD,1766 buf: [*]u8,
777) callconv(WINAPI) SOCKET;1767 buflen: i32,
778pub extern "ws2_32" fn closesocket(s: SOCKET) callconv(WINAPI) c_int;1768) callconv(WINAPI) HANDLE;
779pub extern "ws2_32" fn WSAIoctl(1769
1770pub extern "ws2_32" fn WSAAsyncGetServByPort(
1771 hWnd: HWND,
1772 wMsg: u32,
1773 port: i32,
1774 proto: ?[*:0]const u8,
1775 buf: [*]u8,
1776 buflen: i32,
1777) callconv(WINAPI) HANDLE;
1778
1779pub extern "ws2_32" fn WSAAsyncGetProtoByName(
1780 hWnd: HWND,
1781 wMsg: u32,
1782 name: [*:0]const u8,
1783 buf: [*]u8,
1784 buflen: i32,
1785) callconv(WINAPI) HANDLE;
1786
1787pub extern "ws2_32" fn WSAAsyncGetProtoByNumber(
1788 hWnd: HWND,
1789 wMsg: u32,
1790 number: i32,
1791 buf: [*]u8,
1792 buflen: i32,
1793) callconv(WINAPI) HANDLE;
1794
1795pub extern "ws2_32" fn WSACancelAsyncRequest(hAsyncTaskHandle: HANDLE) callconv(WINAPI) i32;
1796
1797pub extern "ws2_32" fn WSAAsyncSelect(
780 s: SOCKET,1798 s: SOCKET,
781 dwIoControlCode: DWORD,1799 hWnd: HWND,
782 lpvInBuffer: ?*const c_void,1800 wMsg: u32,
783 cbInBuffer: DWORD,1801 lEvent: i32,
784 lpvOutBuffer: ?LPVOID,1802) callconv(WINAPI) i32;
785 cbOutBuffer: DWORD,1803
786 lpcbBytesReturned: LPDWORD,1804pub extern "ws2_32" fn WSAAccept(
787 lpOverlapped: ?*WSAOVERLAPPED,
788 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,
789) callconv(WINAPI) c_int;
790pub extern "ws2_32" fn accept(
791 s: SOCKET,1805 s: SOCKET,
792 addr: ?*sockaddr,1806 addr: ?*sockaddr,
793 addrlen: ?*c_int,1807 addrlen: ?*i32,
1808 lpfnCondition: ?LPCONDITIONPROC,
1809 dwCallbackData: usize,
794) callconv(WINAPI) SOCKET;1810) callconv(WINAPI) SOCKET;
795pub extern "ws2_32" fn bind(1811
1812pub extern "ws2_32" fn WSACloseEvent(hEvent: HANDLE) callconv(WINAPI) BOOL;
1813
1814pub extern "ws2_32" fn WSAConnect(
796 s: SOCKET,1815 s: SOCKET,
797 addr: ?*const sockaddr,1816 name: *const sockaddr,
798 addrlen: c_int,1817 namelen: i32,
799) callconv(WINAPI) c_int;1818 lpCallerData: ?*WSABUF,
800pub extern "ws2_32" fn connect(1819 lpCalleeData: ?*WSABUF,
1820 lpSQOS: ?*QOS,
1821 lpGQOS: ?*QOS,
1822) callconv(WINAPI) i32;
1823
1824pub extern "ws2_32" fn WSAConnectByNameW(
1825 s: SOCKET,
1826 nodename: [*:0]const u16,
1827 servicename: [*:0]const u16,
1828 LocalAddressLength: ?*u32,
1829 LocalAddress: ?*sockaddr,
1830 RemoteAddressLength: ?*u32,
1831 RemoteAddress: ?*sockaddr,
1832 timeout: ?*const timeval,
1833 Reserved: *OVERLAPPED,
1834) callconv(WINAPI) BOOL;
1835
1836pub extern "ws2_32" fn WSAConnectByNameA(
1837 s: SOCKET,
1838 nodename: [*:0]const u8,
1839 servicename: [*:0]const u8,
1840 LocalAddressLength: ?*u32,
1841 LocalAddress: ?*sockaddr,
1842 RemoteAddressLength: ?*u32,
1843 RemoteAddress: ?*sockaddr,
1844 timeout: ?*const timeval,
1845 Reserved: *OVERLAPPED,
1846) callconv(WINAPI) BOOL;
1847
1848pub extern "ws2_32" fn WSAConnectByList(
1849 s: SOCKET,
1850 SocketAddress: *SOCKET_ADDRESS_LIST,
1851 LocalAddressLength: ?*u32,
1852 LocalAddress: ?*sockaddr,
1853 RemoteAddressLength: ?*u32,
1854 RemoteAddress: ?*sockaddr,
1855 timeout: ?*const timeval,
1856 Reserved: *OVERLAPPED,
1857) callconv(WINAPI) BOOL;
1858
1859pub extern "ws2_32" fn WSACreateEvent() callconv(WINAPI) HANDLE;
1860
1861pub extern "ws2_32" fn WSADuplicateSocketA(
1862 s: SOCKET,
1863 dwProcessId: u32,
1864 lpProtocolInfo: *WSAPROTOCOL_INFOA,
1865) callconv(WINAPI) i32;
1866
1867pub extern "ws2_32" fn WSADuplicateSocketW(
1868 s: SOCKET,
1869 dwProcessId: u32,
1870 lpProtocolInfo: *WSAPROTOCOL_INFOW,
1871) callconv(WINAPI) i32;
1872
1873pub extern "ws2_32" fn WSAEnumNetworkEvents(
1874 s: SOCKET,
1875 hEventObject: HANDLE,
1876 lpNetworkEvents: *WSANETWORKEVENTS,
1877) callconv(WINAPI) i32;
1878
1879pub extern "ws2_32" fn WSAEnumProtocolsA(
1880 lpiProtocols: ?*i32,
1881 lpProtocolBuffer: ?*WSAPROTOCOL_INFOA,
1882 lpdwBufferLength: *u32,
1883) callconv(WINAPI) i32;
1884
1885pub extern "ws2_32" fn WSAEnumProtocolsW(
1886 lpiProtocols: ?*i32,
1887 lpProtocolBuffer: ?*WSAPROTOCOL_INFOW,
1888 lpdwBufferLength: *u32,
1889) callconv(WINAPI) i32;
1890
1891pub extern "ws2_32" fn WSAEventSelect(
1892 s: SOCKET,
1893 hEventObject: HANDLE,
1894 lNetworkEvents: i32,
1895) callconv(WINAPI) i32;
1896
1897pub extern "ws2_32" fn WSAGetOverlappedResult(
1898 s: SOCKET,
1899 lpOverlapped: *OVERLAPPED,
1900 lpcbTransfer: *u32,
1901 fWait: BOOL,
1902 lpdwFlags: *u32,
1903) callconv(WINAPI) BOOL;
1904
1905pub extern "ws2_32" fn WSAGetQOSByName(
1906 s: SOCKET,
1907 lpQOSName: *WSABUF,
1908 lpQOS: *QOS,
1909) callconv(WINAPI) BOOL;
1910
1911pub extern "ws2_32" fn WSAHtonl(
1912 s: SOCKET,
1913 hostlong: u32,
1914 lpnetlong: *u32,
1915) callconv(WINAPI) i32;
1916
1917pub extern "ws2_32" fn WSAHtons(
1918 s: SOCKET,
1919 hostshort: u16,
1920 lpnetshort: *u16,
1921) callconv(WINAPI) i32;
1922
1923pub extern "ws2_32" fn WSAIoctl(
1924 s: SOCKET,
1925 dwIoControlCode: u32,
1926 lpvInBuffer: ?*c_void,
1927 cbInBuffer: u32,
1928 lpvOutbuffer: ?*c_void,
1929 cbOutbuffer: u32,
1930 lpcbBytesReturned: *u32,
1931 lpOverlapped: ?*OVERLAPPED,
1932 lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
1933) callconv(WINAPI) i32;
1934
1935pub extern "ws2_32" fn WSAJoinLeaf(
801 s: SOCKET,1936 s: SOCKET,
802 name: *const sockaddr,1937 name: *const sockaddr,
803 namelen: c_int,1938 namelen: i32,
804) callconv(WINAPI) c_int;1939 lpCallerdata: ?*WSABUF,
805pub extern "ws2_32" fn listen(1940 lpCalleeData: ?*WSABUF,
1941 lpSQOS: ?*QOS,
1942 lpGQOS: ?*QOS,
1943 dwFlags: u32,
1944) callconv(WINAPI) SOCKET;
1945
1946pub extern "ws2_32" fn WSANtohl(
806 s: SOCKET,1947 s: SOCKET,
807 backlog: c_int,1948 netlong: u32,
808) callconv(WINAPI) c_int;1949 lphostlong: *u32,
1950) callconv(WINAPI) u32;
1951
1952pub extern "ws2_32" fn WSANtohs(
1953 s: SOCKET,
1954 netshort: u16,
1955 lphostshort: *u16,
1956) callconv(WINAPI) i32;
1957
809pub extern "ws2_32" fn WSARecv(1958pub extern "ws2_32" fn WSARecv(
810 s: SOCKET,1959 s: SOCKET,
811 lpBuffers: [*]const WSABUF,1960 lpBuffers: [*]WSABUF,
812 dwBufferCount: DWORD,1961 dwBufferCouynt: u32,
813 lpNumberOfBytesRecvd: ?*DWORD,1962 lpNumberOfBytesRecv: ?*u32,
814 lpFlags: *DWORD,1963 lpFlags: *u32,
815 lpOverlapped: ?*WSAOVERLAPPED,1964 lpOverlapped: ?*OVERLAPPED,
816 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,1965 lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
817) callconv(WINAPI) c_int;1966) callconv(WINAPI) i32;
1967
1968pub extern "ws2_32" fn WSARecvDisconnect(
1969 s: SOCKET,
1970 lpInboundDisconnectData: ?*WSABUF,
1971) callconv(WINAPI) i32;
1972
818pub extern "ws2_32" fn WSARecvFrom(1973pub extern "ws2_32" fn WSARecvFrom(
819 s: SOCKET,1974 s: SOCKET,
820 lpBuffers: [*]const WSABUF,1975 lpBuffers: [*]WSABUF,
821 dwBufferCount: DWORD,1976 dwBuffercount: u32,
822 lpNumberOfBytesRecvd: ?*DWORD,1977 lpNumberOfBytesRecvd: ?*u32,
823 lpFlags: *DWORD,1978 lpFlags: *u32,
824 lpFrom: ?*sockaddr,1979 lpFrom: ?*sockaddr,
825 lpFromlen: ?*socklen_t,1980 lpFromlen: ?*i32,
826 lpOverlapped: ?*WSAOVERLAPPED,1981 lpOverlapped: ?*OVERLAPPED,
827 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,1982 lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
828) callconv(WINAPI) c_int;1983) callconv(WINAPI) i32;
1984
1985pub extern "ws2_32" fn WSAResetEvent(hEvent: HANDLE) callconv(WINAPI) i32;
1986
829pub extern "ws2_32" fn WSASend(1987pub extern "ws2_32" fn WSASend(
830 s: SOCKET,1988 s: SOCKET,
831 lpBuffers: [*]WSABUF,1989 lpBuffers: [*]WSABUF,
832 dwBufferCount: DWORD,1990 dwBufferCount: u32,
833 lpNumberOfBytesSent: ?*DWORD,1991 lpNumberOfBytesSent: ?*U32,
834 dwFlags: DWORD,1992 dwFlags: u32,
835 lpOverlapped: ?*WSAOVERLAPPED,1993 lpOverlapped: ?*OVERLAPPED,
836 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,1994 lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
837) callconv(WINAPI) c_int;1995) callconv(WINAPI) i32;
1996
1997pub extern "ws2_32" fn WSASendMsg(
1998 s: SOCKET,
1999 lpMsg: *WSAMSG_const,
2000 dwFlags: u32,
2001 lpNumberOfBytesSent: ?*u32,
2002 lpOverlapped: ?*OVERLAPPED,
2003 lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
2004) callconv(WINAPI) i32;
2005
2006pub extern "ws2_32" fn WSARecvMsg(
2007 s: SOCKET,
2008 lpMsg: *WSAMSG,
2009 lpdwNumberOfBytesRecv: ?*u32,
2010 lpOverlapped: ?*OVERLAPPED,
2011 lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
2012) callconv(WINAPI) i32;
2013
2014pub extern "ws2_32" fn WSASendDisconnect(
2015 s: SOCKET,
2016 lpOutboundDisconnectData: ?*WSABUF,
2017) callconv(WINAPI) i32;
2018
838pub extern "ws2_32" fn WSASendTo(2019pub extern "ws2_32" fn WSASendTo(
839 s: SOCKET,2020 s: SOCKET,
840 lpBuffers: [*]WSABUF,2021 lpBuffers: [*]WSABUF,
841 dwBufferCount: DWORD,2022 dwBufferCount: u32,
842 lpNumberOfBytesSent: ?*DWORD,2023 lpNumberOfBytesSent: ?*u32,
843 dwFlags: DWORD,2024 dwFlags: u32,
844 lpTo: ?*const sockaddr,2025 lpTo: ?*const sockaddr,
845 iTolen: c_int,2026 iToLen: i32,
846 lpOverlapped: ?*WSAOVERLAPPED,2027 lpOverlapped: ?*OVERLAPPED,
847 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,2028 lpCompletionRounte: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
848) callconv(WINAPI) c_int;2029) callconv(WINAPI) i32;
2030
2031pub extern "ws2_32" fn WSASetEvent(
2032 hEvent: HANDLE,
2033) callconv(WINAPI) BOOL;
2034
2035pub extern "ws2_32" fn WSASocketA(
2036 af: i32,
2037 @"type": i32,
2038 protocol: i32,
2039 lpProtocolInfo: ?*WSAPROTOCOL_INFOA,
2040 g: u32,
2041 dwFlags: u32,
2042) callconv(WINAPI) SOCKET;
2043
2044pub extern "ws2_32" fn WSASocketW(
2045 af: i32,
2046 @"type": i32,
2047 protocol: i32,
2048 lpProtocolInfo: ?*WSAPROTOCOL_INFOW,
2049 g: u32,
2050 dwFlags: u32,
2051) callconv(WINAPI) SOCKET;
2052
2053pub extern "ws2_32" fn WSAWaitForMultipleEvents(
2054 cEvents: u32,
2055 lphEvents: [*]const HANDLE,
2056 fWaitAll: BOOL,
2057 dwTimeout: u32,
2058 fAlertable: BOOL,
2059) callconv(WINAPI) u32;
2060
2061pub extern "ws2_32" fn WSAAddressToStringA(
2062 lpsaAddress: *sockaddr,
2063 dwAddressLength: u32,
2064 lpProtocolInfo: ?*WSAPROTOCOL_INFOA,
2065 lpszAddressString: [*]u8,
2066 lpdwAddressStringLength: *u32,
2067) callconv(WINAPI) i32;
2068
2069pub extern "ws2_32" fn WSAAddressToStringW(
2070 lpsaAddress: *sockaddr,
2071 dwAddressLength: u32,
2072 lpProtocolInfo: ?*WSAPROTOCOL_INFOW,
2073 lpszAddressString: [*]u16,
2074 lpdwAddressStringLength: *u32,
2075) callconv(WINAPI) i32;
2076
2077pub extern "ws2_32" fn WSAStringToAddressA(
2078 AddressString: [*:0]const u8,
2079 AddressFamily: i32,
2080 lpProtocolInfo: ?*WSAPROTOCOL_INFOA,
2081 lpAddress: *sockaddr,
2082 lpAddressLength: *i32,
2083) callconv(WINAPI) i32;
2084
2085pub extern "ws2_32" fn WSAStringToAddressW(
2086 AddressString: [*:0]const u16,
2087 AddressFamily: i32,
2088 lpProtocolInfo: ?*WSAPROTOCOL_INFOW,
2089 lpAddrses: *sockaddr,
2090 lpAddressLength: *i32,
2091) callconv(WINAPI) i32;
2092
2093pub extern "ws2_32" fn WSAProviderConfigChange(
2094 lpNotificationHandle: *HANDLE,
2095 lpOverlapped: ?*OVERLAPPED,
2096 lpCompletionRoutine: ?LPWSAOVERLAPPED_COMPLETION_ROUTINE,
2097) callconv(WINAPI) i32;
2098
849pub extern "ws2_32" fn WSAPoll(2099pub extern "ws2_32" fn WSAPoll(
850 fdArray: [*]pollfd,2100 fdArray: [*]WSAPOLLFD,
851 fds: c_ulong,2101 fds: u32,
852 timeout: c_int,2102 timeout: i32,
853) callconv(WINAPI) c_int;2103) callconv(WINAPI) i32;
2104
2105pub extern "mswsock" fn WSARecvEx(
2106 s: SOCKET,
2107 buf: [*]u8,
2108 len: i32,
2109 flags: *i32,
2110) callconv(WINAPI) i32;
2111
2112pub extern "mswsock" fn TransmitFile(
2113 hSocket: SOCKET,
2114 hFile: HANDLE,
2115 nNumberOfBytesToWrite: u32,
2116 nNumberOfBytesPerSend: u32,
2117 lpOverlapped: ?*OVERLAPPED,
2118 lpTransmitBuffers: ?*TRANSMIT_FILE_BUFFERS,
2119 dwReserved: u32,
2120) callconv(WINAPI) BOOL;
2121
2122pub extern "mswsock" fn AcceptEx(
2123 sListenSocket: SOCKET,
2124 sAcceptSocket: SOCKET,
2125 lpOutputBuffer: *c_void,
2126 dwReceiveDataLength: u32,
2127 dwLocalAddressLength: u32,
2128 dwRemoteAddressLength: u32,
2129 lpdwBytesReceived: *u32,
2130 lpOverlapped: *OVERLAPPED,
2131) callconv(WINAPI) BOOL;
2132
2133pub extern "mswsock" fn GetAcceptExSockaddrs(
2134 lpOutputBuffer: *c_void,
2135 dwReceiveDataLength: u32,
2136 dwLocalAddressLength: u32,
2137 dwRemoteAddressLength: u32,
2138 LocalSockaddr: **sockaddr,
2139 LocalSockaddrLength: *i32,
2140 RemoteSockaddr: **sockaddr,
2141 RemoteSockaddrLength: *i32,
2142) callconv(WINAPI) void;
2143
2144pub extern "ws2_32" fn WSAProviderCompleteAsyncCall(
2145 hAsyncCall: HANDLE,
2146 iRetCode: i32,
2147) callconv(WINAPI) i32;
2148
2149pub extern "mswsock" fn EnumProtocolsA(
2150 lpiProtocols: ?*i32,
2151 lpProtocolBuffer: *c_void,
2152 lpdwBufferLength: *u32,
2153) callconv(WINAPI) i32;
2154
2155pub extern "mswsock" fn EnumProtocolsW(
2156 lpiProtocols: ?*i32,
2157 lpProtocolBuffer: *c_void,
2158 lpdwBufferLength: *u32,
2159) callconv(WINAPI) i32;
2160
2161pub extern "mswsock" fn GetAddressByNameA(
2162 dwNameSpace: u32,
2163 lpServiceType: *GUID,
2164 lpServiceName: ?[*:0]u8,
2165 lpiProtocols: ?*i32,
2166 dwResolution: u32,
2167 lpServiceAsyncInfo: ?*SERVICE_ASYNC_INFO,
2168 lpCsaddrBuffer: *c_void,
2169 lpAliasBuffer: ?[*:0]const u8,
2170 lpdwAliasBufferLength: *u32,
2171) callconv(WINAPI) i32;
2172
2173pub extern "mswsock" fn GetAddressByNameW(
2174 dwNameSpace: u32,
2175 lpServiceType: *GUID,
2176 lpServiceName: ?[*:0]u16,
2177 lpiProtocols: ?*i32,
2178 dwResolution: u32,
2179 lpServiceAsyncInfo: ?*SERVICE_ASYNC_INFO,
2180 lpCsaddrBuffer: *c_void,
2181 ldwBufferLEngth: *u32,
2182 lpAliasBuffer: ?[*:0]u16,
2183 lpdwAliasBufferLength: *u32,
2184) callconv(WINAPI) i32;
2185
2186pub extern "mswsock" fn GetTypeByNameA(
2187 lpServiceName: [*:0]u8,
2188 lpServiceType: *GUID,
2189) callconv(WINAPI) i32;
2190
2191pub extern "mswsock" fn GetTypeByNameW(
2192 lpServiceName: [*:0]u16,
2193 lpServiceType: *GUID,
2194) callconv(WINAPI) i32;
2195
2196pub extern "mswsock" fn GetNameByTypeA(
2197 lpServiceType: *GUID,
2198 lpServiceName: [*:0]u8,
2199 dwNameLength: u32,
2200) callconv(WINAPI) i32;
2201
2202pub extern "mswsock" fn GetNameByTypeW(
2203 lpServiceType: *GUID,
2204 lpServiceName: [*:0]u16,
2205 dwNameLength: u32,
2206) callconv(WINAPI) i32;
2207
854pub extern "ws2_32" fn getaddrinfo(2208pub extern "ws2_32" fn getaddrinfo(
855 pNodeName: [*:0]const u8,2209 pNodeName: ?[*:0]const u8,
856 pServiceName: [*:0]const u8,2210 pServiceName: ?[*:0]const u8,
857 pHints: *const addrinfo,2211 pHints: ?*const addrinfoa,
858 ppResult: **addrinfo,2212 ppResult: **addrinfoa,
2213) callconv(WINAPI) i32;
2214
2215pub extern "ws2_32" fn GetAddrInfoExA(
2216 pName: ?[*:0]const u8,
2217 pServiceName: ?[*:0]const u8,
2218 dwNameSapce: u32,
2219 lpNspId: ?*GUID,
2220 hints: ?*const addrinfoexA,
2221 ppResult: **addrinfoexA,
2222 timeout: ?*timeval,
2223 lpOverlapped: ?*OVERLAPPED,
2224 lpCompletionRoutine: ?LPLOOKUPSERVICE_COMPLETION_ROUTINE,
859) callconv(WINAPI) i32;2225) callconv(WINAPI) i32;
2226
2227pub extern "ws2_32" fn GetAddrInfoExCancel(
2228 lpHandle: *HANDLE,
2229) callconv(WINAPI) i32;
2230
2231pub extern "ws2_32" fn GetAddrInfoExOverlappedResult(
2232 lpOverlapped: *OVERLAPPED,
2233) callconv(WINAPI) i32;
2234
860pub extern "ws2_32" fn freeaddrinfo(2235pub extern "ws2_32" fn freeaddrinfo(
861 pAddrInfo: *addrinfo,2236 pAddrInfo: ?*addrinfoa,
862) callconv(WINAPI) void;2237) callconv(WINAPI) void;
863pub extern "ws2_32" fn ioctlsocket(2238
864 s: SOCKET,2239pub extern "ws2_32" fn FreeAddrInfoEx(
865 cmd: c_long,2240 pAddrInfoEx: ?*addrinfoexA,
866 argp: *c_ulong,2241) callconv(WINAPI) void;
867) callconv(WINAPI) c_int;2242
868pub extern "ws2_32" fn getsockname(2243pub extern "ws2_32" fn getnameinfo(
869 s: SOCKET,2244 pSockaddr: *const sockaddr,
870 name: *sockaddr,2245 SockaddrLength: i32,
871 namelen: *c_int,2246 pNodeBuffer: ?[*]u8,
872) callconv(WINAPI) c_int;2247 NodeBufferSize: u32,
873pub extern "ws2_32" fn setsockopt(2248 pServiceBuffer: ?[*]u8,
874 s: SOCKET,2249 ServiceBufferName: u32,
875 level: u32,2250 Flags: i32,
876 optname: u32,2251) callconv(WINAPI) i32;
877 optval: ?*const c_void,2252
878 optlen: socklen_t,2253pub extern "IPHLPAPI" fn if_nametoindex(
879) callconv(WINAPI) c_int;2254 InterfaceName: [*:0]const u8,
880pub extern "ws2_32" fn shutdown(2255) callconv(WINAPI) u32;
881 s: SOCKET,
882 how: c_int,
883) callconv(WINAPI) c_int;
lib/std/x.zig+1-1
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const std = @import("std.zig");7const std = @import("std.zig");
88
9pub const os = struct {9pub const os = struct {
10 pub const Socket = @import("x/os/Socket.zig");10 pub const Socket = @import("x/os/socket.zig").Socket;
11 pub usingnamespace @import("x/os/net.zig");11 pub usingnamespace @import("x/os/net.zig");
12};12};
1313
lib/std/x/net/tcp.zig+47-38
...@@ -89,41 +89,30 @@ pub const Client = struct {...@@ -89,41 +89,30 @@ pub const Client = struct {
89 return self.socket.connect(address.into());89 return self.socket.connect(address.into());
90 }90 }
9191
92 /// Read data from the socket into the buffer provided. It returns the
93 /// number of bytes read into the buffer provided.
94 pub fn read(self: Client, buf: []u8) !usize {
95 return self.socket.read(buf);
96 }
97
98 /// Read data from the socket into the buffer provided with a set of flags92 /// Read data from the socket into the buffer provided with a set of flags
99 /// specified. It returns the number of bytes read into the buffer provided.93 /// specified. It returns the number of bytes read into the buffer provided.
100 pub fn recv(self: Client, buf: []u8, flags: u32) !usize {94 pub fn read(self: Client, buf: []u8, flags: u32) !usize {
101 return self.socket.recv(buf, flags);95 return self.socket.read(buf, flags);
102 }
103
104 /// Write a buffer of data provided to the socket. It returns the number
105 /// of bytes that are written to the socket.
106 pub fn write(self: Client, buf: []const u8) !usize {
107 return self.socket.write(buf);
108 }
109
110 /// Writes multiple I/O vectors to the socket. It returns the number
111 /// of bytes that are written to the socket.
112 pub fn writev(self: Client, buffers: []const os.iovec_const) !usize {
113 return self.socket.writev(buffers);
114 }96 }
11597
116 /// Write a buffer of data provided to the socket with a set of flags specified.98 /// Write a buffer of data provided to the socket with a set of flags specified.
117 /// It returns the number of bytes that are written to the socket.99 /// It returns the number of bytes that are written to the socket.
118 pub fn send(self: Client, buf: []const u8, flags: u32) !usize {100 pub fn write(self: Client, buf: []const u8, flags: u32) !usize {
119 return self.socket.send(buf, flags);101 return self.socket.write(buf, flags);
120 }102 }
121103
122 /// Writes multiple I/O vectors with a prepended message header to the socket104 /// Writes multiple I/O vectors with a prepended message header to the socket
123 /// with a set of flags specified. It returns the number of bytes that are105 /// with a set of flags specified. It returns the number of bytes that are
124 /// written to the socket.106 /// written to the socket.
125 pub fn sendmsg(self: Client, msg: os.msghdr_const, flags: u32) !usize {107 pub fn writeVectorized(self: Client, msg: os.msghdr_const, flags: u32) !usize {
126 return self.socket.sendmsg(msg, flags);108 return self.socket.writeVectorized(msg, flags);
109 }
110
111 /// Read multiple I/O vectors with a prepended message header from the socket
112 /// with a set of flags specified. It returns the number of bytes that were
113 /// read into the buffer provided.
114 pub fn readVectorized(self: cLIENT, msg: *os.msghdr, flags: u32) !usize {
115 return self.socket.readVectorized(msg, flags);
127 }116 }
128117
129 /// Query and return the latest cached error on the client's underlying socket.118 /// Query and return the latest cached error on the client's underlying socket.
...@@ -146,12 +135,41 @@ pub const Client = struct {...@@ -146,12 +135,41 @@ pub const Client = struct {
146 return ip.Address.from(try self.socket.getLocalAddress());135 return ip.Address.from(try self.socket.getLocalAddress());
147 }136 }
148137
138 /// Query the address that the socket is connected to.
139 pub fn getRemoteAddress(self: Client) !ip.Address {
140 return ip.Address.from(try self.socket.getRemoteAddress());
141 }
142
143 /// Have close() or shutdown() syscalls block until all queued messages in the client have been successfully
144 /// sent, or if the timeout specified in seconds has been reached. It returns `error.UnsupportedSocketOption`
145 /// if the host does not support the option for a socket to linger around up until a timeout specified in
146 /// seconds.
147 pub fn setLinger(self: Client, timeout_seconds: ?u16) !void {
148 return self.socket.setLinger(timeout_seconds);
149 }
150
151 /// Have keep-alive messages be sent periodically. The timing in which keep-alive messages are sent are
152 /// dependant on operating system settings. It returns `error.UnsupportedSocketOption` if the host does
153 /// not support periodically sending keep-alive messages on connection-oriented sockets.
154 pub fn setKeepAlive(self: Client, enabled: bool) !void {
155 return self.socket.setKeepAlive(enabled);
156 }
157
149 /// Disable Nagle's algorithm on a TCP socket. It returns `error.UnsupportedSocketOption` if158 /// Disable Nagle's algorithm on a TCP socket. It returns `error.UnsupportedSocketOption` if
150 /// the host does not support sockets disabling Nagle's algorithm.159 /// the host does not support sockets disabling Nagle's algorithm.
151 pub fn setNoDelay(self: Client, enabled: bool) !void {160 pub fn setNoDelay(self: Client, enabled: bool) !void {
152 if (comptime @hasDecl(os, "TCP_NODELAY")) {161 if (comptime @hasDecl(os, "TCP_NODELAY")) {
153 const bytes = mem.asBytes(&@as(usize, @boolToInt(enabled)));162 const bytes = mem.asBytes(&@as(usize, @boolToInt(enabled)));
154 return os.setsockopt(self.socket.fd, os.IPPROTO_TCP, os.TCP_NODELAY, bytes);163 return self.socket.setOption(os.IPPROTO_TCP, os.TCP_NODELAY, bytes);
164 }
165 return error.UnsupportedSocketOption;
166 }
167
168 /// Enables TCP Quick ACK on a TCP socket to immediately send rather than delay ACKs when necessary. It returns
169 /// `error.UnsupportedSocketOption` if the host does not support TCP Quick ACK.
170 pub fn setQuickACK(self: Client, enabled: bool) !void {
171 if (comptime @hasDecl(os, "TCP_QUICKACK")) {
172 return self.socket.setOption(os.IPPROTO_TCP, os.TCP_QUICKACK, mem.asBytes(&@as(u32, @boolToInt(enabled))));
155 }173 }
156 return error.UnsupportedSocketOption;174 return error.UnsupportedSocketOption;
157 }175 }
...@@ -169,7 +187,7 @@ pub const Client = struct {...@@ -169,7 +187,7 @@ pub const Client = struct {
169 /// Set a timeout on the socket that is to occur if no messages are successfully written187 /// Set a timeout on the socket that is to occur if no messages are successfully written
170 /// to its bound destination after a specified number of milliseconds. A subsequent write188 /// to its bound destination after a specified number of milliseconds. A subsequent write
171 /// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.189 /// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.
172 pub fn setWriteTimeout(self: Client, milliseconds: usize) !void {190 pub fn setWriteTimeout(self: Client, milliseconds: u32) !void {
173 return self.socket.setWriteTimeout(milliseconds);191 return self.socket.setWriteTimeout(milliseconds);
174 }192 }
175193
...@@ -177,7 +195,7 @@ pub const Client = struct {...@@ -177,7 +195,7 @@ pub const Client = struct {
177 /// from its bound destination after a specified number of milliseconds. A subsequent195 /// from its bound destination after a specified number of milliseconds. A subsequent
178 /// read from the socket will thereafter return `error.WouldBlock` should the timeout be196 /// read from the socket will thereafter return `error.WouldBlock` should the timeout be
179 /// exceeded.197 /// exceeded.
180 pub fn setReadTimeout(self: Client, milliseconds: usize) !void {198 pub fn setReadTimeout(self: Client, milliseconds: u32) !void {
181 return self.socket.setReadTimeout(milliseconds);199 return self.socket.setReadTimeout(milliseconds);
182 }200 }
183};201};
...@@ -251,16 +269,7 @@ pub const Listener = struct {...@@ -251,16 +269,7 @@ pub const Listener = struct {
251 /// support TCP Fast Open.269 /// support TCP Fast Open.
252 pub fn setFastOpen(self: Listener, enabled: bool) !void {270 pub fn setFastOpen(self: Listener, enabled: bool) !void {
253 if (comptime @hasDecl(os, "TCP_FASTOPEN")) {271 if (comptime @hasDecl(os, "TCP_FASTOPEN")) {
254 return os.setsockopt(self.socket.fd, os.IPPROTO_TCP, os.TCP_FASTOPEN, mem.asBytes(&@as(usize, @boolToInt(enabled))));272 return self.socket.setOption(os.IPPROTO_TCP, os.TCP_FASTOPEN, mem.asBytes(&@as(u32, @boolToInt(enabled))));
255 }
256 return error.UnsupportedSocketOption;
257 }
258
259 /// Enables TCP Quick ACK on a TCP socket to immediately send rather than delay ACKs when necessary. It returns
260 /// `error.UnsupportedSocketOption` if the host does not support TCP Quick ACK.
261 pub fn setQuickACK(self: Listener, enabled: bool) !void {
262 if (comptime @hasDecl(os, "TCP_QUICKACK")) {
263 return os.setsockopt(self.socket.fd, os.IPPROTO_TCP, os.TCP_QUICKACK, mem.asBytes(&@as(usize, @boolToInt(enabled))));
264 }273 }
265 return error.UnsupportedSocketOption;274 return error.UnsupportedSocketOption;
266 }275 }
...@@ -322,7 +331,7 @@ test "tcp/client: set read timeout of 1 millisecond on blocking client" {...@@ -322,7 +331,7 @@ test "tcp/client: set read timeout of 1 millisecond on blocking client" {
322 defer conn.deinit();331 defer conn.deinit();
323332
324 var buf: [1]u8 = undefined;333 var buf: [1]u8 = undefined;
325 try testing.expectError(error.WouldBlock, client.read(&buf));334 try testing.expectError(error.WouldBlock, client.reader(0).read(&buf));
326}335}
327336
328test "tcp/listener: bind to unspecified ipv4 address" {337test "tcp/listener: bind to unspecified ipv4 address" {
lib/std/x/os/Socket.zig deleted-295
...@@ -1,295 +0,0 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7const std = @import("../../std.zig");
8const net = @import("net.zig");
9
10const os = std.os;
11const fmt = std.fmt;
12const mem = std.mem;
13const time = std.time;
14
15/// A generic socket abstraction.
16const Socket = @This();
17
18/// A socket-address pair.
19pub const Connection = struct {
20 socket: Socket,
21 address: Socket.Address,
22
23 /// Enclose a socket and address into a socket-address pair.
24 pub fn from(socket: Socket, address: Socket.Address) Socket.Connection {
25 return .{ .socket = socket, .address = address };
26 }
27};
28
29/// A generic socket address abstraction. It is safe to directly access and modify
30/// the fields of a `Socket.Address`.
31pub const Address = union(enum) {
32 ipv4: net.IPv4.Address,
33 ipv6: net.IPv6.Address,
34
35 /// Instantiate a new address with a IPv4 host and port.
36 pub fn initIPv4(host: net.IPv4, port: u16) Socket.Address {
37 return .{ .ipv4 = .{ .host = host, .port = port } };
38 }
39
40 /// Instantiate a new address with a IPv6 host and port.
41 pub fn initIPv6(host: net.IPv6, port: u16) Socket.Address {
42 return .{ .ipv6 = .{ .host = host, .port = port } };
43 }
44
45 /// Parses a `sockaddr` into a generic socket address.
46 pub fn fromNative(address: *align(4) const os.sockaddr) Socket.Address {
47 switch (address.family) {
48 os.AF_INET => {
49 const info = @ptrCast(*const os.sockaddr_in, address);
50 const host = net.IPv4{ .octets = @bitCast([4]u8, info.addr) };
51 const port = mem.bigToNative(u16, info.port);
52 return Socket.Address.initIPv4(host, port);
53 },
54 os.AF_INET6 => {
55 const info = @ptrCast(*const os.sockaddr_in6, address);
56 const host = net.IPv6{ .octets = info.addr, .scope_id = info.scope_id };
57 const port = mem.bigToNative(u16, info.port);
58 return Socket.Address.initIPv6(host, port);
59 },
60 else => unreachable,
61 }
62 }
63
64 /// Encodes a generic socket address into an extern union that may be reliably
65 /// casted into a `sockaddr` which may be passed into socket syscalls.
66 pub fn toNative(self: Socket.Address) extern union {
67 ipv4: os.sockaddr_in,
68 ipv6: os.sockaddr_in6,
69 } {
70 return switch (self) {
71 .ipv4 => |address| .{
72 .ipv4 = .{
73 .addr = @bitCast(u32, address.host.octets),
74 .port = mem.nativeToBig(u16, address.port),
75 },
76 },
77 .ipv6 => |address| .{
78 .ipv6 = .{
79 .addr = address.host.octets,
80 .port = mem.nativeToBig(u16, address.port),
81 .scope_id = address.host.scope_id,
82 .flowinfo = 0,
83 },
84 },
85 };
86 }
87
88 /// Returns the number of bytes that make up the `sockaddr` equivalent to the address.
89 pub fn getNativeSize(self: Socket.Address) u32 {
90 return switch (self) {
91 .ipv4 => @sizeOf(os.sockaddr_in),
92 .ipv6 => @sizeOf(os.sockaddr_in6),
93 };
94 }
95
96 /// Implements the `std.fmt.format` API.
97 pub fn format(
98 self: Socket.Address,
99 comptime layout: []const u8,
100 opts: fmt.FormatOptions,
101 writer: anytype,
102 ) !void {
103 switch (self) {
104 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
105 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
106 }
107 }
108};
109
110/// The underlying handle of a socket.
111fd: os.socket_t,
112
113/// Open a new socket.
114pub fn init(domain: u32, socket_type: u32, protocol: u32) !Socket {
115 return Socket{ .fd = try os.socket(domain, socket_type, protocol) };
116}
117
118/// Enclose a socket abstraction over an existing socket file descriptor.
119pub fn from(fd: os.socket_t) Socket {
120 return Socket{ .fd = fd };
121}
122
123/// Closes the socket.
124pub fn deinit(self: Socket) void {
125 os.closeSocket(self.fd);
126}
127
128/// Shutdown either the read side, write side, or all side of the socket.
129pub fn shutdown(self: Socket, how: os.ShutdownHow) !void {
130 return os.shutdown(self.fd, how);
131}
132
133/// Binds the socket to an address.
134pub fn bind(self: Socket, address: Socket.Address) !void {
135 return os.bind(self.fd, @ptrCast(*const os.sockaddr, &address.toNative()), address.getNativeSize());
136}
137
138/// Start listening for incoming connections on the socket.
139pub fn listen(self: Socket, max_backlog_size: u31) !void {
140 return os.listen(self.fd, max_backlog_size);
141}
142
143/// Have the socket attempt to the connect to an address.
144pub fn connect(self: Socket, address: Socket.Address) !void {
145 return os.connect(self.fd, @ptrCast(*const os.sockaddr, &address.toNative()), address.getNativeSize());
146}
147
148/// Accept a pending incoming connection queued to the kernel backlog
149/// of the socket.
150pub fn accept(self: Socket, flags: u32) !Socket.Connection {
151 var address: os.sockaddr = undefined;
152 var address_len: u32 = @sizeOf(os.sockaddr);
153
154 const socket = Socket{ .fd = try os.accept(self.fd, &address, &address_len, flags) };
155 const socket_address = Socket.Address.fromNative(@alignCast(4, &address));
156
157 return Socket.Connection.from(socket, socket_address);
158}
159
160/// Read data from the socket into the buffer provided. It returns the
161/// number of bytes read into the buffer provided.
162pub fn read(self: Socket, buf: []u8) !usize {
163 return os.read(self.fd, buf);
164}
165
166/// Read data from the socket into the buffer provided with a set of flags
167/// specified. It returns the number of bytes read into the buffer provided.
168pub fn recv(self: Socket, buf: []u8, flags: u32) !usize {
169 return os.recv(self.fd, buf, flags);
170}
171
172/// Write a buffer of data provided to the socket. It returns the number
173/// of bytes that are written to the socket.
174pub fn write(self: Socket, buf: []const u8) !usize {
175 return os.write(self.fd, buf);
176}
177
178/// Writes multiple I/O vectors to the socket. It returns the number
179/// of bytes that are written to the socket.
180pub fn writev(self: Socket, buffers: []const os.iovec_const) !usize {
181 return os.writev(self.fd, buffers);
182}
183
184/// Write a buffer of data provided to the socket with a set of flags specified.
185/// It returns the number of bytes that are written to the socket.
186pub fn send(self: Socket, buf: []const u8, flags: u32) !usize {
187 return os.send(self.fd, buf, flags);
188}
189
190/// Writes multiple I/O vectors with a prepended message header to the socket
191/// with a set of flags specified. It returns the number of bytes that are
192/// written to the socket.
193pub fn sendmsg(self: Socket, msg: os.msghdr_const, flags: u32) !usize {
194 return os.sendmsg(self.fd, msg, flags);
195}
196
197/// Query the address that the socket is locally bounded to.
198pub fn getLocalAddress(self: Socket) !Socket.Address {
199 var address: os.sockaddr = undefined;
200 var address_len: u32 = @sizeOf(os.sockaddr);
201 try os.getsockname(self.fd, &address, &address_len);
202 return Socket.Address.fromNative(@alignCast(4, &address));
203}
204
205/// Query and return the latest cached error on the socket.
206pub fn getError(self: Socket) !void {
207 return os.getsockoptError(self.fd);
208}
209
210/// Query the read buffer size of the socket.
211pub fn getReadBufferSize(self: Socket) !u32 {
212 var value: u32 = undefined;
213 var value_len: u32 = @sizeOf(u32);
214
215 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&value), &value_len);
216 return switch (os.errno(rc)) {
217 0 => value,
218 os.EBADF => error.BadFileDescriptor,
219 os.EFAULT => error.InvalidAddressSpace,
220 os.EINVAL => error.InvalidSocketOption,
221 os.ENOPROTOOPT => error.UnknownSocketOption,
222 os.ENOTSOCK => error.NotASocket,
223 else => |err| os.unexpectedErrno(err),
224 };
225}
226
227/// Query the write buffer size of the socket.
228pub fn getWriteBufferSize(self: Socket) !u32 {
229 var value: u32 = undefined;
230 var value_len: u32 = @sizeOf(u32);
231
232 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&value), &value_len);
233 return switch (os.errno(rc)) {
234 0 => value,
235 os.EBADF => error.BadFileDescriptor,
236 os.EFAULT => error.InvalidAddressSpace,
237 os.EINVAL => error.InvalidSocketOption,
238 os.ENOPROTOOPT => error.UnknownSocketOption,
239 os.ENOTSOCK => error.NotASocket,
240 else => |err| os.unexpectedErrno(err),
241 };
242}
243
244/// Allow multiple sockets on the same host to listen on the same address. It returns `error.UnsupportedSocketOption` if
245/// the host does not support sockets listening the same address.
246pub fn setReuseAddress(self: Socket, enabled: bool) !void {
247 if (comptime @hasDecl(os, "SO_REUSEADDR")) {
248 return os.setsockopt(self.fd, os.SOL_SOCKET, os.SO_REUSEADDR, mem.asBytes(&@as(usize, @boolToInt(enabled))));
249 }
250 return error.UnsupportedSocketOption;
251}
252
253/// Allow multiple sockets on the same host to listen on the same port. It returns `error.UnsupportedSocketOption` if
254/// the host does not supports sockets listening on the same port.
255pub fn setReusePort(self: Socket, enabled: bool) !void {
256 if (comptime @hasDecl(os, "SO_REUSEPORT")) {
257 return os.setsockopt(self.fd, os.SOL_SOCKET, os.SO_REUSEPORT, mem.asBytes(&@as(usize, @boolToInt(enabled))));
258 }
259 return error.UnsupportedSocketOption;
260}
261
262/// Set the write buffer size of the socket.
263pub fn setWriteBufferSize(self: Socket, size: u32) !void {
264 return os.setsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&size));
265}
266
267/// Set the read buffer size of the socket.
268pub fn setReadBufferSize(self: Socket, size: u32) !void {
269 return os.setsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&size));
270}
271
272/// Set a timeout on the socket that is to occur if no messages are successfully written
273/// to its bound destination after a specified number of milliseconds. A subsequent write
274/// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.
275pub fn setWriteTimeout(self: Socket, milliseconds: usize) !void {
276 const timeout = os.timeval{
277 .tv_sec = @intCast(i32, milliseconds / time.ms_per_s),
278 .tv_usec = @intCast(i32, (milliseconds % time.ms_per_s) * time.us_per_ms),
279 };
280
281 return os.setsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDTIMEO, mem.asBytes(&timeout));
282}
283
284/// Set a timeout on the socket that is to occur if no messages are successfully read
285/// from its bound destination after a specified number of milliseconds. A subsequent
286/// read from the socket will thereafter return `error.WouldBlock` should the timeout be
287/// exceeded.
288pub fn setReadTimeout(self: Socket, milliseconds: usize) !void {
289 const timeout = os.timeval{
290 .tv_sec = @intCast(i32, milliseconds / time.ms_per_s),
291 .tv_usec = @intCast(i32, (milliseconds % time.ms_per_s) * time.us_per_ms),
292 };
293
294 return os.setsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVTIMEO, mem.asBytes(&timeout));
295}
lib/std/x/os/net.zig+9
...@@ -20,6 +20,14 @@ pub fn resolveScopeID(name: []const u8) !u32 {...@@ -20,6 +20,14 @@ pub fn resolveScopeID(name: []const u8) !u32 {
20 if (comptime @hasDecl(os, "IFNAMESIZE")) {20 if (comptime @hasDecl(os, "IFNAMESIZE")) {
21 if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong;21 if (name.len >= os.IFNAMESIZE - 1) return error.NameTooLong;
2222
23 if (comptime builtin.os.tag == .windows) {
24 var interface_name: [os.IFNAMESIZE]u8 = undefined;
25 mem.copy(u8, &interface_name, name);
26 interface_name[name.len] = 0;
27
28 return os.windows.ws2_32.if_nametoindex(@ptrCast([*:0]const u8, &interface_name));
29 }
30
23 const fd = try os.socket(os.AF_UNIX, os.SOCK_DGRAM, 0);31 const fd = try os.socket(os.AF_UNIX, os.SOCK_DGRAM, 0);
24 defer os.closeSocket(fd);32 defer os.closeSocket(fd);
2533
...@@ -31,6 +39,7 @@ pub fn resolveScopeID(name: []const u8) !u32 {...@@ -31,6 +39,7 @@ pub fn resolveScopeID(name: []const u8) !u32 {
3139
32 return @bitCast(u32, f.ifru.ivalue);40 return @bitCast(u32, f.ifru.ivalue);
33 }41 }
42
34 return error.Unsupported;43 return error.Unsupported;
35}44}
3645
lib/std/x/os/socket.zig created+156
...@@ -0,0 +1,156 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7const std = @import("../../std.zig");
8const net = @import("net.zig");
9
10const io = std.io;
11const os = std.os;
12const fmt = std.fmt;
13const mem = std.mem;
14const time = std.time;
15const builtin = std.builtin;
16
17/// Import in a `Socket` abstraction depending on the platform we are compiling against.
18pub usingnamespace switch (builtin.os.tag) {
19 .windows => @import("socket_windows.zig"),
20 else => @import("socket_posix.zig"),
21};
22
23/// A common subset of shared structs across cross-platform abstractions over socket syscalls.
24pub fn Mixin(comptime Self: type) type {
25 return struct {
26 /// A socket-address pair.
27 pub const Connection = struct {
28 socket: Self,
29 address: Self.Address,
30
31 /// Enclose a socket and address into a socket-address pair.
32 pub fn from(socket: Self, address: Self.Address) Self.Connection {
33 return .{ .socket = socket, .address = address };
34 }
35 };
36
37 /// A generic socket address abstraction. It is safe to directly access and modify
38 /// the fields of a `Self.Address`.
39 pub const Address = union(enum) {
40 ipv4: net.IPv4.Address,
41 ipv6: net.IPv6.Address,
42
43 /// Instantiate a new address with a IPv4 host and port.
44 pub fn initIPv4(host: net.IPv4, port: u16) Self.Address {
45 return .{ .ipv4 = .{ .host = host, .port = port } };
46 }
47
48 /// Instantiate a new address with a IPv6 host and port.
49 pub fn initIPv6(host: net.IPv6, port: u16) Self.Address {
50 return .{ .ipv6 = .{ .host = host, .port = port } };
51 }
52
53 /// Parses a `sockaddr` into a generic socket address.
54 pub fn fromNative(address: *align(4) const os.sockaddr) Self.Address {
55 switch (address.family) {
56 os.AF_INET => {
57 const info = @ptrCast(*const os.sockaddr_in, address);
58 const host = net.IPv4{ .octets = @bitCast([4]u8, info.addr) };
59 const port = mem.bigToNative(u16, info.port);
60 return Self.Address.initIPv4(host, port);
61 },
62 os.AF_INET6 => {
63 const info = @ptrCast(*const os.sockaddr_in6, address);
64 const host = net.IPv6{ .octets = info.addr, .scope_id = info.scope_id };
65 const port = mem.bigToNative(u16, info.port);
66 return Self.Address.initIPv6(host, port);
67 },
68 else => unreachable,
69 }
70 }
71
72 /// Encodes a generic socket address into an extern union that may be reliably
73 /// casted into a `sockaddr` which may be passed into socket syscalls.
74 pub fn toNative(self: Self.Address) extern union {
75 ipv4: os.sockaddr_in,
76 ipv6: os.sockaddr_in6,
77 } {
78 return switch (self) {
79 .ipv4 => |address| .{
80 .ipv4 = .{
81 .addr = @bitCast(u32, address.host.octets),
82 .port = mem.nativeToBig(u16, address.port),
83 },
84 },
85 .ipv6 => |address| .{
86 .ipv6 = .{
87 .addr = address.host.octets,
88 .port = mem.nativeToBig(u16, address.port),
89 .scope_id = address.host.scope_id,
90 .flowinfo = 0,
91 },
92 },
93 };
94 }
95
96 /// Returns the number of bytes that make up the `sockaddr` equivalent to the address.
97 pub fn getNativeSize(self: Self.Address) u32 {
98 return switch (self) {
99 .ipv4 => @sizeOf(os.sockaddr_in),
100 .ipv6 => @sizeOf(os.sockaddr_in6),
101 };
102 }
103
104 /// Implements the `std.fmt.format` API.
105 pub fn format(
106 self: Self.Address,
107 comptime layout: []const u8,
108 opts: fmt.FormatOptions,
109 writer: anytype,
110 ) !void {
111 switch (self) {
112 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
113 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
114 }
115 }
116 };
117
118 /// Implements `std.io.Reader`.
119 pub const Reader = struct {
120 socket: Self,
121 flags: u32,
122
123 /// Implements `readFn` for `std.io.Reader`.
124 pub fn read(self: Self.Reader, buffer: []u8) !usize {
125 return self.socket.read(buffer, self.flags);
126 }
127 };
128
129 /// Implements `std.io.Writer`.
130 pub const Writer = struct {
131 socket: Self,
132 flags: u32,
133
134 /// Implements `writeFn` for `std.io.Writer`.
135 pub fn write(self: Self.Writer, buffer: []const u8) !usize {
136 return self.socket.write(buffer, self.flags);
137 }
138 };
139
140 /// Extracts the error set of a function.
141 /// TODO: remove after Socket.{read, write} error unions are well-defined across different platforms
142 fn ErrorSetOf(comptime Function: anytype) type {
143 return @typeInfo(@typeInfo(@TypeOf(Function)).Fn.return_type.?).ErrorUnion.error_set;
144 }
145
146 /// Wrap `Socket` into `std.io.Reader`.
147 pub fn reader(self: Self, flags: u32) io.Reader(Self.Reader, ErrorSetOf(Self.Reader.read), Self.Reader.read) {
148 return .{ .context = .{ .socket = self, .flags = flags } };
149 }
150
151 /// Wrap `Socket` into `std.io.Writer`.
152 pub fn writer(self: Self, flags: u32) io.Writer(Self.Writer, ErrorSetOf(Self.Writer.write), Self.Writer.write) {
153 return .{ .context = .{ .socket = self, .flags = flags } };
154 }
155 };
156}
lib/std/x/os/socket_posix.zig created+235
...@@ -0,0 +1,235 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7const std = @import("../../std.zig");
8
9const os = std.os;
10const mem = std.mem;
11const time = std.time;
12
13pub const Socket = struct {
14 /// Import in `Socket.Address` and `Socket.Connection`.
15 pub usingnamespace @import("socket.zig").Mixin(Socket);
16
17 /// The underlying handle of a socket.
18 fd: os.socket_t,
19
20 /// Open a new socket.
21 pub fn init(domain: u32, socket_type: u32, protocol: u32) !Socket {
22 return Socket{ .fd = try os.socket(domain, socket_type, protocol) };
23 }
24
25 /// Enclose a socket abstraction over an existing socket file descriptor.
26 pub fn from(fd: os.socket_t) Socket {
27 return Socket{ .fd = fd };
28 }
29
30 /// Closes the socket.
31 pub fn deinit(self: Socket) void {
32 os.closeSocket(self.fd);
33 }
34
35 /// Shutdown either the read side, write side, or all side of the socket.
36 pub fn shutdown(self: Socket, how: os.ShutdownHow) !void {
37 return os.shutdown(self.fd, how);
38 }
39
40 /// Binds the socket to an address.
41 pub fn bind(self: Socket, address: Socket.Address) !void {
42 return os.bind(self.fd, @ptrCast(*const os.sockaddr, &address.toNative()), address.getNativeSize());
43 }
44
45 /// Start listening for incoming connections on the socket.
46 pub fn listen(self: Socket, max_backlog_size: u31) !void {
47 return os.listen(self.fd, max_backlog_size);
48 }
49
50 /// Have the socket attempt to the connect to an address.
51 pub fn connect(self: Socket, address: Socket.Address) !void {
52 return os.connect(self.fd, @ptrCast(*const os.sockaddr, &address.toNative()), address.getNativeSize());
53 }
54
55 /// Accept a pending incoming connection queued to the kernel backlog
56 /// of the socket.
57 pub fn accept(self: Socket, flags: u32) !Socket.Connection {
58 var address: os.sockaddr = undefined;
59 var address_len: u32 = @sizeOf(os.sockaddr);
60
61 const socket = Socket{ .fd = try os.accept(self.fd, &address, &address_len, flags) };
62 const socket_address = Socket.Address.fromNative(@alignCast(4, &address));
63
64 return Socket.Connection.from(socket, socket_address);
65 }
66
67 /// Read data from the socket into the buffer provided with a set of flags
68 /// specified. It returns the number of bytes read into the buffer provided.
69 pub fn read(self: Socket, buf: []u8, flags: u32) !usize {
70 return os.recv(self.fd, buf, flags);
71 }
72
73 /// Write a buffer of data provided to the socket with a set of flags specified.
74 /// It returns the number of bytes that are written to the socket.
75 pub fn write(self: Socket, buf: []const u8, flags: u32) !usize {
76 return os.send(self.fd, buf, flags);
77 }
78
79 /// Writes multiple I/O vectors with a prepended message header to the socket
80 /// with a set of flags specified. It returns the number of bytes that are
81 /// written to the socket.
82 pub fn writeVectorized(self: Socket, msg: os.msghdr_const, flags: u32) !usize {
83 return os.sendmsg(self.fd, msg, flags);
84 }
85
86 /// Read multiple I/O vectors with a prepended message header from the socket
87 /// with a set of flags specified. It returns the number of bytes that were
88 /// read into the buffer provided.
89 pub fn readVectorized(self: Socket, msg: *os.msghdr, flags: u32) !usize {
90 return error.NotImplemented;
91 }
92
93 /// Query the address that the socket is locally bounded to.
94 pub fn getLocalAddress(self: Socket) !Socket.Address {
95 var address: os.sockaddr_storage = undefined;
96 var address_len: u32 = @sizeOf(os.sockaddr_storage);
97 try os.getsockname(self.fd, @ptrCast(*os.sockaddr, &address), &address_len);
98 return Socket.Address.fromNative(@alignCast(4, @ptrCast(*os.sockaddr, &address)));
99 }
100
101 /// Query the address that the socket is connected to.
102 pub fn getRemoteAddress(self: Socket) !Socket.Address {
103 var address: os.sockaddr_storage = undefined;
104 var address_len: u32 = @sizeOf(os.sockaddr_storage);
105 try os.getpeername(self.fd, @ptrCast(*os.sockaddr, &address), &address_len);
106 return Socket.Address.fromNative(@alignCast(4, @ptrCast(*os.sockaddr, &address)));
107 }
108
109 /// Query and return the latest cached error on the socket.
110 pub fn getError(self: Socket) !void {
111 return os.getsockoptError(self.fd);
112 }
113
114 /// Query the read buffer size of the socket.
115 pub fn getReadBufferSize(self: Socket) !u32 {
116 var value: u32 = undefined;
117 var value_len: u32 = @sizeOf(u32);
118
119 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&value), &value_len);
120 return switch (os.errno(rc)) {
121 0 => value,
122 os.EBADF => error.BadFileDescriptor,
123 os.EFAULT => error.InvalidAddressSpace,
124 os.EINVAL => error.InvalidSocketOption,
125 os.ENOPROTOOPT => error.UnknownSocketOption,
126 os.ENOTSOCK => error.NotASocket,
127 else => |err| os.unexpectedErrno(err),
128 };
129 }
130
131 /// Query the write buffer size of the socket.
132 pub fn getWriteBufferSize(self: Socket) !u32 {
133 var value: u32 = undefined;
134 var value_len: u32 = @sizeOf(u32);
135
136 const rc = os.system.getsockopt(self.fd, os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&value), &value_len);
137 return switch (os.errno(rc)) {
138 0 => value,
139 os.EBADF => error.BadFileDescriptor,
140 os.EFAULT => error.InvalidAddressSpace,
141 os.EINVAL => error.InvalidSocketOption,
142 os.ENOPROTOOPT => error.UnknownSocketOption,
143 os.ENOTSOCK => error.NotASocket,
144 else => |err| os.unexpectedErrno(err),
145 };
146 }
147
148 /// Set a socket option.
149 pub fn setOption(self: Socket, level: u32, name: u32, value: []const u8) !void {
150 return os.setsockopt(self.fd, level, name, value);
151 }
152
153 /// Have close() or shutdown() syscalls block until all queued messages in the socket have been successfully
154 /// sent, or if the timeout specified in seconds has been reached. It returns `error.UnsupportedSocketOption`
155 /// if the host does not support the option for a socket to linger around up until a timeout specified in
156 /// seconds.
157 pub fn setLinger(self: Socket, timeout_seconds: ?u16) !void {
158 if (comptime @hasDecl(os, "SO_LINGER")) {
159 const settings = struct {
160 l_onoff: c_int,
161 l_linger: c_int,
162 }{
163 .l_onoff = @intCast(c_int, @boolToInt(timeout_seconds != null)),
164 .l_linger = if (timeout_seconds) |seconds| @intCast(c_int, seconds) else 0,
165 };
166
167 return self.setOption(os.SOL_SOCKET, os.SO_LINGER, mem.asBytes(&settings));
168 }
169
170 return error.UnsupportedSocketOption;
171 }
172
173 /// On connection-oriented sockets, have keep-alive messages be sent periodically. The timing in which keep-alive
174 /// messages are sent are dependant on operating system settings. It returns `error.UnsupportedSocketOption` if
175 /// the host does not support periodically sending keep-alive messages on connection-oriented sockets.
176 pub fn setKeepAlive(self: Socket, enabled: bool) !void {
177 if (comptime @hasDecl(os, "SO_KEEPALIVE")) {
178 return self.setOption(os.SOL_SOCKET, os.SO_KEEPALIVE, mem.asBytes(&@as(u32, @boolToInt(enabled))));
179 }
180 return error.UnsupportedSocketOption;
181 }
182
183 /// Allow multiple sockets on the same host to listen on the same address. It returns `error.UnsupportedSocketOption` if
184 /// the host does not support sockets listening the same address.
185 pub fn setReuseAddress(self: Socket, enabled: bool) !void {
186 if (comptime @hasDecl(os, "SO_REUSEADDR")) {
187 return self.setOption(os.SOL_SOCKET, os.SO_REUSEADDR, mem.asBytes(&@as(u32, @boolToInt(enabled))));
188 }
189 return error.UnsupportedSocketOption;
190 }
191
192 /// Allow multiple sockets on the same host to listen on the same port. It returns `error.UnsupportedSocketOption` if
193 /// the host does not supports sockets listening on the same port.
194 pub fn setReusePort(self: Socket, enabled: bool) !void {
195 if (comptime @hasDecl(os, "SO_REUSEPORT")) {
196 return self.setOption(os.SOL_SOCKET, os.SO_REUSEPORT, mem.asBytes(&@as(u32, @boolToInt(enabled))));
197 }
198 return error.UnsupportedSocketOption;
199 }
200
201 /// Set the write buffer size of the socket.
202 pub fn setWriteBufferSize(self: Socket, size: u32) !void {
203 return self.setOption(os.SOL_SOCKET, os.SO_SNDBUF, mem.asBytes(&size));
204 }
205
206 /// Set the read buffer size of the socket.
207 pub fn setReadBufferSize(self: Socket, size: u32) !void {
208 return self.setOption(os.SOL_SOCKET, os.SO_RCVBUF, mem.asBytes(&size));
209 }
210
211 /// Set a timeout on the socket that is to occur if no messages are successfully written
212 /// to its bound destination after a specified number of milliseconds. A subsequent write
213 /// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.
214 pub fn setWriteTimeout(self: Socket, milliseconds: usize) !void {
215 const timeout = os.timeval{
216 .tv_sec = @intCast(i32, milliseconds / time.ms_per_s),
217 .tv_usec = @intCast(i32, (milliseconds % time.ms_per_s) * time.us_per_ms),
218 };
219
220 return self.setOption(os.SOL_SOCKET, os.SO_SNDTIMEO, mem.asBytes(&timeout));
221 }
222
223 /// Set a timeout on the socket that is to occur if no messages are successfully read
224 /// from its bound destination after a specified number of milliseconds. A subsequent
225 /// read from the socket will thereafter return `error.WouldBlock` should the timeout be
226 /// exceeded.
227 pub fn setReadTimeout(self: Socket, milliseconds: usize) !void {
228 const timeout = os.timeval{
229 .tv_sec = @intCast(i32, milliseconds / time.ms_per_s),
230 .tv_usec = @intCast(i32, (milliseconds % time.ms_per_s) * time.us_per_ms),
231 };
232
233 return self.setOption(os.SOL_SOCKET, os.SO_RCVTIMEO, mem.asBytes(&timeout));
234 }
235};
lib/std/x/os/socket_windows.zig created+392
...@@ -0,0 +1,392 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7const std = @import("../../std.zig");
8const net = @import("net.zig");
9
10const os = std.os;
11const mem = std.mem;
12
13const windows = std.os.windows;
14const ws2_32 = windows.ws2_32;
15
16pub const Socket = struct {
17 /// Import in `Socket.Address` and `Socket.Connection`.
18 pub usingnamespace @import("socket.zig").Mixin(Socket);
19
20 /// The underlying handle of a socket.
21 fd: os.socket_t,
22
23 /// Open a new socket.
24 pub fn init(domain: u32, socket_type: u32, protocol: u32) !Socket {
25 var filtered_socket_type = socket_type & ~@as(u32, os.SOCK_CLOEXEC);
26
27 var filtered_flags = ws2_32.WSA_FLAG_OVERLAPPED;
28 if (socket_type & os.SOCK_CLOEXEC != 0) {
29 filtered_flags |= ws2_32.WSA_FLAG_NO_HANDLE_INHERIT;
30 }
31
32 const fd = ws2_32.WSASocketW(
33 @intCast(i32, domain),
34 @intCast(i32, filtered_socket_type),
35 @intCast(i32, protocol),
36 null,
37 0,
38 filtered_flags,
39 );
40 if (fd == ws2_32.INVALID_SOCKET) {
41 return switch (ws2_32.WSAGetLastError()) {
42 .WSANOTINITIALISED => {
43 _ = try windows.WSAStartup(2, 2);
44 return Socket.init(domain, socket_type, protocol);
45 },
46 .WSAEAFNOSUPPORT => error.AddressFamilyNotSupported,
47 .WSAEMFILE => error.ProcessFdQuotaExceeded,
48 .WSAENOBUFS => error.SystemResources,
49 .WSAEPROTONOSUPPORT => error.ProtocolNotSupported,
50 else => |err| windows.unexpectedWSAError(err),
51 };
52 }
53
54 return Socket{ .fd = fd };
55 }
56
57 /// Enclose a socket abstraction over an existing socket file descriptor.
58 pub fn from(fd: os.socket_t) Socket {
59 return Socket{ .fd = fd };
60 }
61
62 /// Closes the socket.
63 pub fn deinit(self: Socket) void {
64 _ = ws2_32.closesocket(self.fd);
65 }
66
67 /// Shutdown either the read side, write side, or all side of the socket.
68 pub fn shutdown(self: Socket, how: os.ShutdownHow) !void {
69 const rc = ws2_32.shutdown(self.fd, switch (how) {
70 .recv => ws2_32.SD_RECEIVE,
71 .send => ws2_32.SD_SEND,
72 .both => ws2_32.SD_BOTH,
73 });
74 if (rc == ws2_32.SOCKET_ERROR) {
75 return switch (ws2_32.WSAGetLastError()) {
76 .WSAECONNABORTED => return error.ConnectionAborted,
77 .WSAECONNRESET => return error.ConnectionResetByPeer,
78 .WSAEINPROGRESS => return error.BlockingOperationInProgress,
79 .WSAEINVAL => unreachable,
80 .WSAENETDOWN => return error.NetworkSubsystemFailed,
81 .WSAENOTCONN => return error.SocketNotConnected,
82 .WSAENOTSOCK => unreachable,
83 .WSANOTINITIALISED => unreachable,
84 else => |err| return windows.unexpectedWSAError(err),
85 };
86 }
87 }
88
89 /// Binds the socket to an address.
90 pub fn bind(self: Socket, address: Socket.Address) !void {
91 const rc = ws2_32.bind(self.fd, @ptrCast(*const ws2_32.sockaddr, &address.toNative()), @intCast(c_int, address.getNativeSize()));
92 if (rc == ws2_32.SOCKET_ERROR) {
93 return switch (ws2_32.WSAGetLastError()) {
94 .WSAENETDOWN => error.NetworkSubsystemFailed,
95 .WSAEACCES => error.AccessDenied,
96 .WSAEADDRINUSE => error.AddressInUse,
97 .WSAEADDRNOTAVAIL => error.AddressNotAvailable,
98 .WSAEFAULT => error.BadAddress,
99 .WSAEINPROGRESS => error.WouldBlock,
100 .WSAEINVAL => error.AlreadyBound,
101 .WSAENOBUFS => error.NoEphemeralPortsAvailable,
102 .WSAENOTSOCK => error.NotASocket,
103 else => |err| windows.unexpectedWSAError(err),
104 };
105 }
106 }
107
108 /// Start listening for incoming connections on the socket.
109 pub fn listen(self: Socket, max_backlog_size: u31) !void {
110 const rc = ws2_32.listen(self.fd, max_backlog_size);
111 if (rc == ws2_32.SOCKET_ERROR) {
112 return switch (ws2_32.WSAGetLastError()) {
113 .WSAENETDOWN => error.NetworkSubsystemFailed,
114 .WSAEADDRINUSE => error.AddressInUse,
115 .WSAEISCONN => error.AlreadyConnected,
116 .WSAEINVAL => error.SocketNotBound,
117 .WSAEMFILE, .WSAENOBUFS => error.SystemResources,
118 .WSAENOTSOCK => error.FileDescriptorNotASocket,
119 .WSAEOPNOTSUPP => error.OperationNotSupported,
120 .WSAEINPROGRESS => error.WouldBlock,
121 else => |err| windows.unexpectedWSAError(err),
122 };
123 }
124 }
125
126 /// Have the socket attempt to the connect to an address.
127 pub fn connect(self: Socket, address: Socket.Address) !void {
128 const rc = ws2_32.connect(self.fd, @ptrCast(*const ws2_32.sockaddr, &address.toNative()), @intCast(c_int, address.getNativeSize()));
129 if (rc == ws2_32.SOCKET_ERROR) {
130 return switch (ws2_32.WSAGetLastError()) {
131 .WSAEADDRINUSE => error.AddressInUse,
132 .WSAEADDRNOTAVAIL => error.AddressNotAvailable,
133 .WSAECONNREFUSED => error.ConnectionRefused,
134 .WSAETIMEDOUT => error.ConnectionTimedOut,
135 .WSAEFAULT => error.BadAddress,
136 .WSAEINVAL => error.ListeningSocket,
137 .WSAEISCONN => error.AlreadyConnected,
138 .WSAENOTSOCK => error.NotASocket,
139 .WSAEACCES => error.BroadcastNotEnabled,
140 .WSAENOBUFS => error.SystemResources,
141 .WSAEAFNOSUPPORT => error.AddressFamilyNotSupported,
142 .WSAEINPROGRESS, .WSAEWOULDBLOCK => error.WouldBlock,
143 .WSAEHOSTUNREACH, .WSAENETUNREACH => error.NetworkUnreachable,
144 else => |err| windows.unexpectedWSAError(err),
145 };
146 }
147 }
148
149 /// Accept a pending incoming connection queued to the kernel backlog
150 /// of the socket.
151 pub fn accept(self: Socket, flags: u32) !Socket.Connection {
152 var address: ws2_32.sockaddr = undefined;
153 var address_len: c_int = @sizeOf(ws2_32.sockaddr);
154
155 const rc = ws2_32.accept(self.fd, &address, &address_len);
156 if (rc == ws2_32.INVALID_SOCKET) {
157 return switch (ws2_32.WSAGetLastError()) {
158 .WSANOTINITIALISED => unreachable,
159 .WSAECONNRESET => error.ConnectionResetByPeer,
160 .WSAEFAULT => unreachable,
161 .WSAEINVAL => error.SocketNotListening,
162 .WSAEMFILE => error.ProcessFdQuotaExceeded,
163 .WSAENETDOWN => error.NetworkSubsystemFailed,
164 .WSAENOBUFS => error.FileDescriptorNotASocket,
165 .WSAEOPNOTSUPP => error.OperationNotSupported,
166 .WSAEWOULDBLOCK => error.WouldBlock,
167 else => |err| windows.unexpectedWSAError(err),
168 };
169 }
170
171 const socket = Socket.from(rc);
172 const socket_address = Socket.Address.fromNative(@alignCast(4, &address));
173
174 return Socket.Connection.from(socket, socket_address);
175 }
176
177 /// Read data from the socket into the buffer provided with a set of flags
178 /// specified. It returns the number of bytes read into the buffer provided.
179 pub fn read(self: Socket, buf: []u8, flags: u32) !usize {
180 var bufs = &[_]ws2_32.WSABUF{.{ .len = @intCast(u32, buf.len), .buf = buf.ptr }};
181 var flags_ = flags;
182
183 const rc = ws2_32.WSARecv(self.fd, bufs, 1, null, &flags_, null, null);
184 if (rc == ws2_32.SOCKET_ERROR) {
185 return switch (ws2_32.WSAGetLastError()) {
186 .WSAECONNABORTED => error.ConnectionAborted,
187 .WSAECONNRESET => error.ConnectionResetByPeer,
188 .WSAEDISCON => error.ConnectionClosedByPeer,
189 .WSAEFAULT => error.BadBuffer,
190 .WSAEINPROGRESS,
191 .WSAEWOULDBLOCK,
192 .WSA_IO_PENDING,
193 .WSAETIMEDOUT,
194 => error.WouldBlock,
195 .WSAEINTR => error.Cancelled,
196 .WSAEINVAL => error.SocketNotBound,
197 .WSAEMSGSIZE => error.MessageTooLarge,
198 .WSAENETDOWN => error.NetworkSubsystemFailed,
199 .WSAENETRESET => error.NetworkReset,
200 .WSAENOTCONN => error.SocketNotConnected,
201 .WSAENOTSOCK => error.FileDescriptorNotASocket,
202 .WSAEOPNOTSUPP => error.OperationNotSupported,
203 .WSAESHUTDOWN => error.AlreadyShutdown,
204 .WSA_OPERATION_ABORTED => error.OperationAborted,
205 else => |err| windows.unexpectedWSAError(err),
206 };
207 }
208
209 return @intCast(usize, rc);
210 }
211
212 /// Write a buffer of data provided to the socket with a set of flags specified.
213 /// It returns the number of bytes that are written to the socket.
214 pub fn write(self: Socket, buf: []const u8, flags: u32) !usize {
215 var bufs = &[_]ws2_32.WSABUF{.{ .len = @intCast(u32, buf.len), .buf = buf.ptr }};
216 var flags_ = flags;
217
218 const rc = ws2_32.WSASend(self.fd, bufs, 1, null, &flags_, null, null);
219 if (rc == ws2_32.SOCKET_ERROR) {
220 return switch (ws2_32.WSAGetLastError()) {
221 .WSAECONNABORTED => error.ConnectionAborted,
222 .WSAECONNRESET => error.ConnectionResetByPeer,
223 .WSAEFAULT => error.BadBuffer,
224 .WSAEINPROGRESS,
225 .WSAEWOULDBLOCK,
226 .WSA_IO_PENDING,
227 .WSAETIMEDOUT,
228 => error.WouldBlock,
229 .WSAEINTR => error.Cancelled,
230 .WSAEINVAL => error.SocketNotBound,
231 .WSAEMSGSIZE => error.MessageTooLarge,
232 .WSAENETDOWN => error.NetworkSubsystemFailed,
233 .WSAENETRESET => error.NetworkReset,
234 .WSAENOBUFS => error.BufferDeadlock,
235 .WSAENOTCONN => error.SocketNotConnected,
236 .WSAENOTSOCK => error.FileDescriptorNotASocket,
237 .WSAEOPNOTSUPP => error.OperationNotSupported,
238 .WSAESHUTDOWN => error.AlreadyShutdown,
239 .WSA_OPERATION_ABORTED => error.OperationAborted,
240 else => |err| windows.unexpectedWSAError(err),
241 };
242 }
243
244 return @intCast(usize, rc);
245 }
246
247 /// Writes multiple I/O vectors with a prepended message header to the socket
248 /// with a set of flags specified. It returns the number of bytes that are
249 /// written to the socket.
250 pub fn writeVectorized(self: Socket, msg: os.msghdr_const, flags: u32) !usize {
251 return error.NotImplemented;
252 }
253
254 /// Read multiple I/O vectors with a prepended message header from the socket
255 /// with a set of flags specified. It returns the number of bytes that were
256 /// read into the buffer provided.
257 pub fn readVectorized(self: Socket, msg: *os.msghdr, flags: u32) !usize {
258 return error.NotImplemented;
259 }
260
261 /// Query the address that the socket is locally bounded to.
262 pub fn getLocalAddress(self: Socket) !Socket.Address {
263 var address: ws2_32.sockaddr_storage = undefined;
264 var address_len: c_int = @sizeOf(ws2_32.sockaddr_storage);
265
266 const rc = ws2_32.getsockname(self.fd, @ptrCast(*ws2_32.sockaddr, &address), &address_len);
267 if (rc == ws2_32.SOCKET_ERROR) {
268 return switch (ws2_32.WSAGetLastError()) {
269 .WSANOTINITIALISED => unreachable,
270 .WSAEFAULT => unreachable,
271 .WSAENETDOWN => error.NetworkSubsystemFailed,
272 .WSAENOTSOCK => error.FileDescriptorNotASocket,
273 .WSAEINVAL => error.SocketNotBound,
274 else => |err| windows.unexpectedWSAError(err),
275 };
276 }
277
278 return Socket.Address.fromNative(@alignCast(4, @ptrCast(*os.sockaddr, &address)));
279 }
280
281 /// Query the address that the socket is connected to.
282 pub fn getRemoteAddress(self: Socket) !Socket.Address {
283 var address: ws2_32.sockaddr_storage = undefined;
284 var address_len: c_int = @sizeOf(ws2_32.sockaddr_storage);
285
286 const rc = ws2_32.getpeername(self.fd, @ptrCast(*ws2_32.sockaddr, &address), &address_len);
287 if (rc == ws2_32.SOCKET_ERROR) {
288 return switch (ws2_32.WSAGetLastError()) {
289 .WSANOTINITIALISED => unreachable,
290 .WSAEFAULT => unreachable,
291 .WSAENETDOWN => error.NetworkSubsystemFailed,
292 .WSAENOTSOCK => error.FileDescriptorNotASocket,
293 .WSAEINVAL => error.SocketNotBound,
294 else => |err| windows.unexpectedWSAError(err),
295 };
296 }
297
298 return Socket.Address.fromNative(@alignCast(4, @ptrCast(*os.sockaddr, &address)));
299 }
300
301 /// Query and return the latest cached error on the socket.
302 pub fn getError(self: Socket) !void {
303 return {};
304 }
305
306 /// Query the read buffer size of the socket.
307 pub fn getReadBufferSize(self: Socket) !u32 {
308 return 0;
309 }
310
311 /// Query the write buffer size of the socket.
312 pub fn getWriteBufferSize(self: Socket) !u32 {
313 return 0;
314 }
315
316 /// Set a socket option.
317 pub fn setOption(self: Socket, level: u32, name: u32, value: []const u8) !void {
318 const rc = ws2_32.setsockopt(self.fd, @intCast(i32, level), @intCast(i32, name), value.ptr, @intCast(i32, value.len));
319 if (rc == ws2_32.SOCKET_ERROR) {
320 return switch (ws2_32.WSAGetLastError()) {
321 .WSANOTINITIALISED => unreachable,
322 .WSAENETDOWN => return error.NetworkSubsystemFailed,
323 .WSAEFAULT => unreachable,
324 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
325 .WSAEINVAL => return error.SocketNotBound,
326 .WSAENOTCONN => return error.SocketNotConnected,
327 .WSAESHUTDOWN => return error.AlreadyShutdown,
328 else => |err| windows.unexpectedWSAError(err),
329 };
330 }
331 }
332
333 /// Have close() or shutdown() syscalls block until all queued messages in the socket have been successfully
334 /// sent, or if the timeout specified in seconds has been reached. It returns `error.UnsupportedSocketOption`
335 /// if the host does not support the option for a socket to linger around up until a timeout specified in
336 /// seconds.
337 pub fn setLinger(self: Socket, timeout_seconds: ?u16) !void {
338 const settings = ws2_32.linger{
339 .l_onoff = @as(u16, @boolToInt(timeout_seconds != null)),
340 .l_linger = if (timeout_seconds) |seconds| seconds else 0,
341 };
342
343 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_LINGER, mem.asBytes(&settings));
344 }
345
346 /// On connection-oriented sockets, have keep-alive messages be sent periodically. The timing in which keep-alive
347 /// messages are sent are dependant on operating system settings. It returns `error.UnsupportedSocketOption` if
348 /// the host does not support periodically sending keep-alive messages on connection-oriented sockets.
349 pub fn setKeepAlive(self: Socket, enabled: bool) !void {
350 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_KEEPALIVE, mem.asBytes(&@as(u32, @boolToInt(enabled))));
351 }
352
353 /// Allow multiple sockets on the same host to listen on the same address. It returns `error.UnsupportedSocketOption` if
354 /// the host does not support sockets listening the same address.
355 pub fn setReuseAddress(self: Socket, enabled: bool) !void {
356 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_REUSEADDR, mem.asBytes(&@as(u32, @boolToInt(enabled))));
357 }
358
359 /// Allow multiple sockets on the same host to listen on the same port. It returns `error.UnsupportedSocketOption` if
360 /// the host does not supports sockets listening on the same port.
361 ///
362 /// TODO: verify if this truly mimicks SO_REUSEPORT behavior, or if SO_REUSE_UNICASTPORT provides the correct behavior
363 pub fn setReusePort(self: Socket, enabled: bool) !void {
364 try self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_BROADCAST, mem.asBytes(&@as(u32, @boolToInt(enabled))));
365 try self.setReuseAddress(enabled);
366 }
367
368 /// Set the write buffer size of the socket.
369 pub fn setWriteBufferSize(self: Socket, size: u32) !void {
370 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_SNDBUF, mem.asBytes(&size));
371 }
372
373 /// Set the read buffer size of the socket.
374 pub fn setReadBufferSize(self: Socket, size: u32) !void {
375 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_RCVBUF, mem.asBytes(&size));
376 }
377
378 /// Set a timeout on the socket that is to occur if no messages are successfully written
379 /// to its bound destination after a specified number of milliseconds. A subsequent write
380 /// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.
381 pub fn setWriteTimeout(self: Socket, milliseconds: u32) !void {
382 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_SNDTIMEO, mem.asBytes(&milliseconds));
383 }
384
385 /// Set a timeout on the socket that is to occur if no messages are successfully read
386 /// from its bound destination after a specified number of milliseconds. A subsequent
387 /// read from the socket will thereafter return `error.WouldBlock` should the timeout be
388 /// exceeded.
389 pub fn setReadTimeout(self: Socket, milliseconds: u32) !void {
390 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_RCVTIMEO, mem.asBytes(&milliseconds));
391 }
392};