net/SocketDescriptor: add AcceptNonBlock() overload without address
This commit is contained in:
parent
b234f4307f
commit
614b3634d4
@ -68,6 +68,20 @@ SocketDescriptor::Accept()
|
||||
: Undefined();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -173,6 +173,7 @@ public:
|
||||
bool Listen(int backlog);
|
||||
|
||||
SocketDescriptor Accept();
|
||||
SocketDescriptor AcceptNonBlock() const;
|
||||
SocketDescriptor AcceptNonBlock(StaticSocketAddress &address) const;
|
||||
|
||||
bool Connect(SocketAddress address);
|
||||
|
@ -76,6 +76,13 @@ public:
|
||||
return fd == other.fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an "undefined" instance on error
|
||||
*/
|
||||
UniqueSocketDescriptor AcceptNonBlock() const {
|
||||
return UniqueSocketDescriptor(SocketDescriptor::AcceptNonBlock());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an "undefined" instance on error
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user