summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-08-11 09:02:10 +0200
committerMax Kellermann <max@musicpd.org>2017-08-11 09:07:35 +0200
commit614b3634d49b98748866fe9ad024eb98133ea4fb (patch)
tree5a13427ada10728dda8cea05c0aab544bfac56ba /src/net
parentb234f4307f454c044e0c35cd0a838457c8e02040 (diff)
net/SocketDescriptor: add AcceptNonBlock() overload without address
Diffstat (limited to 'src/net')
-rw-r--r--src/net/SocketDescriptor.cxx14
-rw-r--r--src/net/SocketDescriptor.hxx1
-rw-r--r--src/net/UniqueSocketDescriptor.hxx7
3 files changed, 22 insertions, 0 deletions
diff --git a/src/net/SocketDescriptor.cxx b/src/net/SocketDescriptor.cxx
index 146149af0..97f83cdd9 100644
--- a/src/net/SocketDescriptor.cxx
+++ b/src/net/SocketDescriptor.cxx
@@ -69,6 +69,20 @@ SocketDescriptor::Accept()
}
SocketDescriptor
+SocketDescriptor::AcceptNonBlock() const
+{
+#ifdef HAVE_ACCEPT4
+ int connection_fd = ::accept4(Get(), nullptr, nullptr,
+ SOCK_CLOEXEC|SOCK_NONBLOCK);
+#else
+ int connection_fd = ::accept(Get(), nullptr, nullptr);
+ if (connection_fd >= 0)
+ SocketDescriptor(connection_fd).SetNonBlocking();
+#endif
+ return SocketDescriptor(connection_fd);
+}
+
+SocketDescriptor
SocketDescriptor::AcceptNonBlock(StaticSocketAddress &address) const
{
address.SetMaxSize();
diff --git a/src/net/SocketDescriptor.hxx b/src/net/SocketDescriptor.hxx
index bc2d86d16..d42f36fe9 100644
--- a/src/net/SocketDescriptor.hxx
+++ b/src/net/SocketDescriptor.hxx
@@ -173,6 +173,7 @@ public:
bool Listen(int backlog);
SocketDescriptor Accept();
+ SocketDescriptor AcceptNonBlock() const;
SocketDescriptor AcceptNonBlock(StaticSocketAddress &address) const;
bool Connect(SocketAddress address);
diff --git a/src/net/UniqueSocketDescriptor.hxx b/src/net/UniqueSocketDescriptor.hxx
index 750198855..0ad529e97 100644
--- a/src/net/UniqueSocketDescriptor.hxx
+++ b/src/net/UniqueSocketDescriptor.hxx
@@ -79,6 +79,13 @@ public:
/**
* @return an "undefined" instance on error
*/
+ UniqueSocketDescriptor AcceptNonBlock() const {
+ return UniqueSocketDescriptor(SocketDescriptor::AcceptNonBlock());
+ }
+
+ /**
+ * @return an "undefined" instance on error
+ */
UniqueSocketDescriptor AcceptNonBlock(StaticSocketAddress &address) const {
return UniqueSocketDescriptor(SocketDescriptor::AcceptNonBlock(address));
}