Commit 614b3634 authored by Max Kellermann's avatar Max Kellermann

net/SocketDescriptor: add AcceptNonBlock() overload without address

parent b234f430
......@@ -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();
......
......@@ -173,6 +173,7 @@ public:
bool Listen(int backlog);
SocketDescriptor Accept();
SocketDescriptor AcceptNonBlock() const;
SocketDescriptor AcceptNonBlock(StaticSocketAddress &address) const;
bool Connect(SocketAddress address);
......
......@@ -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));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment