22#ifndef IO_SOCKET_WINDOWS_HPP
23#define IO_SOCKET_WINDOWS_HPP
51inline static constexpr int SOCKET_ERROR = ::SOCKET_ERROR;
74 return ::closesocket(socket);
78static constexpr int F_SETFL = 4;
79static constexpr int O_NONBLOCK = 2048;
100template <
typename... Args>
102 Args &&...args)
noexcept ->
int {
103 static_assert(
sizeof...(args) == 1,
104 "fcntl for windows is only implemented for F_SETFL and a "
105 "single argument O_NONBLOCK.");
106 assert(cmd == F_SETFL &&
"fcntl for windows is only implemented for F_SETFL");
108 auto arg = std::get<0>(std::forward_as_tuple(std::forward<Args>(args)...));
109 auto mode = (arg & O_NONBLOCK) ? 1 : 0;
112 return ioctlsocket(socket, FIONBIO, &mode);
131 int flags)
noexcept -> std::streamsize {
132 std::streamsize len = 0;
133 int error = ::WSASendMsg(socket, msg, &len,
nullptr,
nullptr);
134 return (error == 0) ? len : error;
149 int flags)
noexcept -> std::streamsize {
150 std::streamsize len = 0;
151 int error = ::WSARecvMsg(socket, msg, &len,
nullptr,
nullptr);
152 return (error == 0) ? len : error;
The io::socket namespace provides a cross-platform abstraction for socket-level I/O operations.
msghdr socket_message_type
The socket message type for POSIX systems.
auto close(native_socket_type socket) noexcept -> int
Closes a socket descriptor on POSIX systems.
sockaddr sockaddr_type
The generic socket address structure for POSIX systems.
int native_socket_type
The native socket handle type for POSIX systems.
socklen_t socklen_type
The type used to represent socket-related sizes on POSIX systems.
sockaddr_storage sockaddr_storage_type
The socket address storage structure for POSIX systems.
std::span< char, std::dynamic_extent > socket_buffer_type
The socket buffer type for POSIX systems.
constexpr detail::cpo< socket::recvmsg_t > recvmsg
A customization point object that receives a message from a socket.
constexpr detail::cpo< socket::fcntl_t > fcntl
A customization point object that performs a file control operation on a socket.
constexpr detail::cpo< socket::sendmsg_t > sendmsg
A customization point object that sends a message on a socket.