1b8a62b91Sopenharmony_ci//! Adapt the Winsock2 API to resemble a POSIX-style libc API. 2b8a62b91Sopenharmony_ci 3b8a62b91Sopenharmony_ci#![allow(unused_imports)] 4b8a62b91Sopenharmony_ci#![allow(non_camel_case_types)] 5b8a62b91Sopenharmony_ci 6b8a62b91Sopenharmony_ciuse windows_sys::Win32::Networking::WinSock; 7b8a62b91Sopenharmony_ci 8b8a62b91Sopenharmony_cipub(crate) use libc::{ 9b8a62b91Sopenharmony_ci c_char, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint, c_ulong, c_ulonglong, 10b8a62b91Sopenharmony_ci c_ushort, c_void, ssize_t, 11b8a62b91Sopenharmony_ci}; 12b8a62b91Sopenharmony_cipub(crate) type socklen_t = i32; 13b8a62b91Sopenharmony_ci 14b8a62b91Sopenharmony_ci// windows-sys declares these constants as unsigned. For better compatibility 15b8a62b91Sopenharmony_ci// with Unix-family APIs, redeclare them as signed. Filed upstream: 16b8a62b91Sopenharmony_ci// <https://github.com/microsoft/windows-rs/issues/1718> 17b8a62b91Sopenharmony_cipub(crate) const AF_INET: i32 = WinSock::AF_INET as _; 18b8a62b91Sopenharmony_cipub(crate) const AF_INET6: i32 = WinSock::AF_INET6 as _; 19b8a62b91Sopenharmony_cipub(crate) const AF_UNSPEC: i32 = WinSock::AF_UNSPEC as _; 20b8a62b91Sopenharmony_cipub(crate) const SO_TYPE: i32 = WinSock::SO_TYPE as _; 21b8a62b91Sopenharmony_cipub(crate) const SO_REUSEADDR: i32 = WinSock::SO_REUSEADDR as _; 22b8a62b91Sopenharmony_cipub(crate) const SO_BROADCAST: i32 = WinSock::SO_BROADCAST as _; 23b8a62b91Sopenharmony_cipub(crate) const SO_LINGER: i32 = WinSock::SO_LINGER as _; 24b8a62b91Sopenharmony_cipub(crate) const SOL_SOCKET: i32 = WinSock::SOL_SOCKET as _; 25b8a62b91Sopenharmony_cipub(crate) const SO_RCVTIMEO: i32 = WinSock::SO_RCVTIMEO as _; 26b8a62b91Sopenharmony_cipub(crate) const SO_SNDTIMEO: i32 = WinSock::SO_SNDTIMEO as _; 27b8a62b91Sopenharmony_cipub(crate) const IP_TTL: i32 = WinSock::IP_TTL as _; 28b8a62b91Sopenharmony_cipub(crate) const TCP_NODELAY: i32 = WinSock::TCP_NODELAY as _; 29b8a62b91Sopenharmony_cipub(crate) const IP_ADD_MEMBERSHIP: i32 = WinSock::IP_ADD_MEMBERSHIP as _; 30b8a62b91Sopenharmony_cipub(crate) const IP_DROP_MEMBERSHIP: i32 = WinSock::IP_DROP_MEMBERSHIP as _; 31b8a62b91Sopenharmony_cipub(crate) const IP_MULTICAST_TTL: i32 = WinSock::IP_MULTICAST_TTL as _; 32b8a62b91Sopenharmony_cipub(crate) const IP_MULTICAST_LOOP: i32 = WinSock::IP_MULTICAST_LOOP as _; 33b8a62b91Sopenharmony_cipub(crate) const IPV6_ADD_MEMBERSHIP: i32 = WinSock::IPV6_ADD_MEMBERSHIP as _; 34b8a62b91Sopenharmony_cipub(crate) const IPV6_DROP_MEMBERSHIP: i32 = WinSock::IPV6_DROP_MEMBERSHIP as _; 35b8a62b91Sopenharmony_cipub(crate) const IPV6_MULTICAST_LOOP: i32 = WinSock::IPV6_MULTICAST_LOOP as _; 36b8a62b91Sopenharmony_cipub(crate) const IPV6_V6ONLY: i32 = WinSock::IPV6_V6ONLY as _; 37b8a62b91Sopenharmony_cipub(crate) const POLLERR: i16 = WinSock::POLLERR as _; 38b8a62b91Sopenharmony_cipub(crate) const POLLIN: i16 = WinSock::POLLIN as _; 39b8a62b91Sopenharmony_cipub(crate) const POLLNVAL: i16 = WinSock::POLLNVAL as _; 40b8a62b91Sopenharmony_cipub(crate) const POLLHUP: i16 = WinSock::POLLHUP as _; 41b8a62b91Sopenharmony_cipub(crate) const POLLPRI: i16 = WinSock::POLLPRI as _; 42b8a62b91Sopenharmony_cipub(crate) const POLLOUT: i16 = WinSock::POLLOUT as _; 43b8a62b91Sopenharmony_cipub(crate) const POLLRDNORM: i16 = WinSock::POLLRDNORM as _; 44b8a62b91Sopenharmony_cipub(crate) const POLLWRNORM: i16 = WinSock::POLLWRNORM as _; 45b8a62b91Sopenharmony_cipub(crate) const POLLRDBAND: i16 = WinSock::POLLRDBAND as _; 46b8a62b91Sopenharmony_cipub(crate) const POLLWRBAND: i16 = WinSock::POLLWRBAND as _; 47b8a62b91Sopenharmony_ci 48b8a62b91Sopenharmony_ci// As above, cast the types for better compatibility, and also rename these to 49b8a62b91Sopenharmony_ci// their Unix names. 50b8a62b91Sopenharmony_cipub(crate) const SHUT_RDWR: i32 = WinSock::SD_BOTH as _; 51b8a62b91Sopenharmony_cipub(crate) const SHUT_RD: i32 = WinSock::SD_RECEIVE as _; 52b8a62b91Sopenharmony_cipub(crate) const SHUT_WR: i32 = WinSock::SD_SEND as _; 53b8a62b91Sopenharmony_ci 54b8a62b91Sopenharmony_ci// Include the contents of `WinSock`, renaming as needed to match POSIX. 55b8a62b91Sopenharmony_ci// 56b8a62b91Sopenharmony_ci// Use `WSA_E_CANCELLED` for `ECANCELED` instead of `WSAECANCELLED`, because 57b8a62b91Sopenharmony_ci// `WSAECANCELLED` will be removed in the future. 58b8a62b91Sopenharmony_ci// <https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnsplookupserviceend#remarks> 59b8a62b91Sopenharmony_cipub(crate) use WinSock::{ 60b8a62b91Sopenharmony_ci closesocket as close, ioctlsocket as ioctl, WSAPoll as poll, ADDRESS_FAMILY as sa_family_t, 61b8a62b91Sopenharmony_ci ADDRINFOA as addrinfo, IN6_ADDR as in6_addr, IN_ADDR as in_addr, IPV6_MREQ as ipv6_mreq, 62b8a62b91Sopenharmony_ci IP_MREQ as ip_mreq, LINGER as linger, SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in, 63b8a62b91Sopenharmony_ci SOCKADDR_IN6 as sockaddr_in6, SOCKADDR_STORAGE as sockaddr_storage, WSAEACCES as EACCES, 64b8a62b91Sopenharmony_ci WSAEADDRINUSE as EADDRINUSE, WSAEADDRNOTAVAIL as EADDRNOTAVAIL, 65b8a62b91Sopenharmony_ci WSAEAFNOSUPPORT as EAFNOSUPPORT, WSAEALREADY as EALREADY, WSAEBADF as EBADF, 66b8a62b91Sopenharmony_ci WSAECONNABORTED as ECONNABORTED, WSAECONNREFUSED as ECONNREFUSED, WSAECONNRESET as ECONNRESET, 67b8a62b91Sopenharmony_ci WSAEDESTADDRREQ as EDESTADDRREQ, WSAEDISCON as EDISCON, WSAEDQUOT as EDQUOT, 68b8a62b91Sopenharmony_ci WSAEFAULT as EFAULT, WSAEHOSTDOWN as EHOSTDOWN, WSAEHOSTUNREACH as EHOSTUNREACH, 69b8a62b91Sopenharmony_ci WSAEINPROGRESS as EINPROGRESS, WSAEINTR as EINTR, WSAEINVAL as EINVAL, 70b8a62b91Sopenharmony_ci WSAEINVALIDPROCTABLE as EINVALIDPROCTABLE, WSAEINVALIDPROVIDER as EINVALIDPROVIDER, 71b8a62b91Sopenharmony_ci WSAEISCONN as EISCONN, WSAELOOP as ELOOP, WSAEMFILE as EMFILE, WSAEMSGSIZE as EMSGSIZE, 72b8a62b91Sopenharmony_ci WSAENAMETOOLONG as ENAMETOOLONG, WSAENETDOWN as ENETDOWN, WSAENETRESET as ENETRESET, 73b8a62b91Sopenharmony_ci WSAENETUNREACH as ENETUNREACH, WSAENOBUFS as ENOBUFS, WSAENOMORE as ENOMORE, 74b8a62b91Sopenharmony_ci WSAENOPROTOOPT as ENOPROTOOPT, WSAENOTCONN as ENOTCONN, WSAENOTEMPTY as ENOTEMPTY, 75b8a62b91Sopenharmony_ci WSAENOTSOCK as ENOTSOCK, WSAEOPNOTSUPP as EOPNOTSUPP, WSAEPFNOSUPPORT as EPFNOSUPPORT, 76b8a62b91Sopenharmony_ci WSAEPROCLIM as EPROCLIM, WSAEPROTONOSUPPORT as EPROTONOSUPPORT, WSAEPROTOTYPE as EPROTOTYPE, 77b8a62b91Sopenharmony_ci WSAEPROVIDERFAILEDINIT as EPROVIDERFAILEDINIT, WSAEREFUSED as EREFUSED, WSAEREMOTE as EREMOTE, 78b8a62b91Sopenharmony_ci WSAESHUTDOWN as ESHUTDOWN, WSAESOCKTNOSUPPORT as ESOCKTNOSUPPORT, WSAESTALE as ESTALE, 79b8a62b91Sopenharmony_ci WSAETIMEDOUT as ETIMEDOUT, WSAETOOMANYREFS as ETOOMANYREFS, WSAEUSERS as EUSERS, 80b8a62b91Sopenharmony_ci WSAEWOULDBLOCK as EWOULDBLOCK, WSAEWOULDBLOCK as EAGAIN, WSAPOLLFD as pollfd, 81b8a62b91Sopenharmony_ci WSA_E_CANCELLED as ECANCELED, *, 82b8a62b91Sopenharmony_ci}; 83