]>
Commit | Line | Data |
---|---|---|
fe692bf9 FG |
1 | //! Adapt the Winsock2 API to resemble a POSIX-style libc API. |
2 | ||
3 | #![allow(unused_imports)] | |
4 | #![allow(non_camel_case_types)] | |
5 | #![allow(dead_code)] | |
6 | ||
7 | use windows_sys::Win32::Networking::WinSock; | |
8 | ||
9 | // Define the basic C types. With Rust 1.64, we can use these from `core::ffi`. | |
10 | pub(crate) type c_schar = i8; | |
11 | pub(crate) type c_uchar = u8; | |
12 | pub(crate) type c_short = i16; | |
13 | pub(crate) type c_ushort = u16; | |
14 | pub(crate) type c_int = i32; | |
15 | pub(crate) type c_uint = u32; | |
16 | pub(crate) type c_longlong = i64; | |
17 | pub(crate) type c_ulonglong = u64; | |
18 | pub(crate) type ssize_t = isize; | |
19 | pub(crate) type c_char = i8; | |
20 | pub(crate) type c_long = i32; | |
21 | pub(crate) type c_ulong = u32; | |
22 | pub(crate) use core::ffi::c_void; | |
23 | ||
24 | // windows-sys declares these constants as u16. For better compatibility | |
25 | // with Unix-family APIs, redeclare them as u32. | |
26 | pub(crate) const AF_INET: i32 = WinSock::AF_INET as _; | |
27 | pub(crate) const AF_INET6: i32 = WinSock::AF_INET6 as _; | |
28 | pub(crate) const AF_UNSPEC: i32 = WinSock::AF_UNSPEC as _; | |
29 | ||
30 | // Include the contents of `WinSock`, renaming as needed to match POSIX. | |
31 | // | |
32 | // Use `WSA_E_CANCELLED` for `ECANCELED` instead of `WSAECANCELLED`, because | |
33 | // `WSAECANCELLED` will be removed in the future. | |
34 | // <https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnsplookupserviceend#remarks> | |
35 | pub(crate) use WinSock::{ | |
36 | closesocket as close, ioctlsocket as ioctl, WSAPoll as poll, ADDRESS_FAMILY as sa_family_t, | |
37 | ADDRINFOA as addrinfo, IN6_ADDR as in6_addr, IN_ADDR as in_addr, IPV6_MREQ as ipv6_mreq, | |
38 | IP_MREQ as ip_mreq, LINGER as linger, SD_BOTH as SHUT_RDWR, SD_RECEIVE as SHUT_RD, | |
39 | SD_SEND as SHUT_WR, SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in, | |
40 | SOCKADDR_IN6 as sockaddr_in6, SOCKADDR_STORAGE as sockaddr_storage, WSAEACCES as EACCES, | |
41 | WSAEADDRINUSE as EADDRINUSE, WSAEADDRNOTAVAIL as EADDRNOTAVAIL, | |
42 | WSAEAFNOSUPPORT as EAFNOSUPPORT, WSAEALREADY as EALREADY, WSAEBADF as EBADF, | |
43 | WSAECONNABORTED as ECONNABORTED, WSAECONNREFUSED as ECONNREFUSED, WSAECONNRESET as ECONNRESET, | |
44 | WSAEDESTADDRREQ as EDESTADDRREQ, WSAEDISCON as EDISCON, WSAEDQUOT as EDQUOT, | |
45 | WSAEFAULT as EFAULT, WSAEHOSTDOWN as EHOSTDOWN, WSAEHOSTUNREACH as EHOSTUNREACH, | |
46 | WSAEINPROGRESS as EINPROGRESS, WSAEINTR as EINTR, WSAEINVAL as EINVAL, | |
47 | WSAEINVALIDPROCTABLE as EINVALIDPROCTABLE, WSAEINVALIDPROVIDER as EINVALIDPROVIDER, | |
48 | WSAEISCONN as EISCONN, WSAELOOP as ELOOP, WSAEMFILE as EMFILE, WSAEMSGSIZE as EMSGSIZE, | |
49 | WSAENAMETOOLONG as ENAMETOOLONG, WSAENETDOWN as ENETDOWN, WSAENETRESET as ENETRESET, | |
50 | WSAENETUNREACH as ENETUNREACH, WSAENOBUFS as ENOBUFS, WSAENOMORE as ENOMORE, | |
51 | WSAENOPROTOOPT as ENOPROTOOPT, WSAENOTCONN as ENOTCONN, WSAENOTEMPTY as ENOTEMPTY, | |
52 | WSAENOTSOCK as ENOTSOCK, WSAEOPNOTSUPP as EOPNOTSUPP, WSAEPFNOSUPPORT as EPFNOSUPPORT, | |
53 | WSAEPROCLIM as EPROCLIM, WSAEPROTONOSUPPORT as EPROTONOSUPPORT, WSAEPROTOTYPE as EPROTOTYPE, | |
54 | WSAEPROVIDERFAILEDINIT as EPROVIDERFAILEDINIT, WSAEREFUSED as EREFUSED, WSAEREMOTE as EREMOTE, | |
55 | WSAESHUTDOWN as ESHUTDOWN, WSAESOCKTNOSUPPORT as ESOCKTNOSUPPORT, WSAESTALE as ESTALE, | |
56 | WSAETIMEDOUT as ETIMEDOUT, WSAETOOMANYREFS as ETOOMANYREFS, WSAEUSERS as EUSERS, | |
57 | WSAEWOULDBLOCK as EWOULDBLOCK, WSAEWOULDBLOCK as EAGAIN, WSAPOLLFD as pollfd, | |
58 | WSA_E_CANCELLED as ECANCELED, *, | |
59 | }; |