21 #include "../../string_func.h"
22 #include "../../3rdparty/fmt/format.h"
25 #include "../../safeguards.h"
42 return this->
error == WSAEWOULDBLOCK;
46 return this->
error == EWOULDBLOCK || this->
error == EAGAIN;
57 return this->
error == WSAECONNRESET;
59 return this->
error == ECONNRESET;
70 return this->
error == WSAEWOULDBLOCK;
72 return this->
error == EINPROGRESS;
85 if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, this->
error,
86 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer,
static_cast<DWORD
>(std::size(buffer)),
nullptr) == 0) {
87 this->
message.assign(fmt::format(
"Unknown error {}", this->
error));
97 static std::mutex mutex;
98 std::lock_guard<std::mutex> guard(mutex);
111 return this->
error != 0;
136 u_long nonblocking = 1;
137 return ioctlsocket(d, FIONBIO, &nonblocking) == 0;
138 #elif defined __EMSCRIPTEN__
142 return ioctl(d, FIONBIO, &nonblocking) == 0;
153 #ifdef __EMSCRIPTEN__
158 return setsockopt(d, IPPROTO_TCP, TCP_NODELAY, (
const char *)&flags,
sizeof(flags)) == 0;
172 return setsockopt(d, SOL_SOCKET, SO_REUSEADDR, (
const char *)&reuse_port,
sizeof(reuse_port)) == 0;
175 return setsockopt(d, SOL_SOCKET, SO_REUSEPORT, &reuse_port,
sizeof(reuse_port)) == 0;
187 socklen_t len =
sizeof(err);
188 getsockopt(d, SOL_SOCKET, SO_ERROR, (
char *)&err, &len);