From b180604422a1444c1d61456b7247854f8ceb4680 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 10 Aug 2017 13:18:23 +0200 Subject: [PATCH] net/SocketDescriptor: implement SetNonBlocking() on Windows --- src/net/SocketDescriptor.cxx | 11 +++++++++++ src/net/SocketDescriptor.hxx | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/net/SocketDescriptor.cxx b/src/net/SocketDescriptor.cxx index 1af100bc9..9e827e00d 100644 --- a/src/net/SocketDescriptor.cxx +++ b/src/net/SocketDescriptor.cxx @@ -181,6 +181,17 @@ SocketDescriptor::GetError() : errno; } +#ifdef _WIN32 + +bool +SocketDescriptor::SetNonBlocking() noexcept +{ + u_long val = 1; + return ioctlsocket(fd, FIONBIO, &val) == 0; +} + +#endif + bool SocketDescriptor::SetOption(int level, int name, const void *value, size_t size) diff --git a/src/net/SocketDescriptor.hxx b/src/net/SocketDescriptor.hxx index bd8f8fed0..2ef7dc2f2 100644 --- a/src/net/SocketDescriptor.hxx +++ b/src/net/SocketDescriptor.hxx @@ -98,6 +98,8 @@ public: using FileDescriptor::Duplicate; using FileDescriptor::Close; #else + bool SetNonBlocking() noexcept; + /** * This method replaces FileDescriptor::Close(), using closesocket() * on Windows. FileDescriptor::Close() is not virtual, so be