event/ServerSocket: pass UniqueSocketDescriptor to AddFD()
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include "config/Data.hxx"
|
#include "config/Data.hxx"
|
||||||
#include "config/Option.hxx"
|
#include "config/Option.hxx"
|
||||||
#include "config/Net.hxx"
|
#include "config/Net.hxx"
|
||||||
|
#include "net/UniqueSocketDescriptor.hxx"
|
||||||
#include "system/Error.hxx"
|
#include "system/Error.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
@@ -66,7 +67,7 @@ listen_systemd_activation(ClientListener &listener)
|
|||||||
|
|
||||||
for (int i = SD_LISTEN_FDS_START, end = SD_LISTEN_FDS_START + n;
|
for (int i = SD_LISTEN_FDS_START, end = SD_LISTEN_FDS_START + n;
|
||||||
i != end; ++i)
|
i != end; ++i)
|
||||||
listener.AddFD(i);
|
listener.AddFD(UniqueSocketDescriptor(i));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -107,8 +107,8 @@ public:
|
|||||||
return ::ToString(address);
|
return ::ToString(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFD(SocketDescriptor _fd) noexcept {
|
void SetFD(UniqueSocketDescriptor _fd) noexcept {
|
||||||
SocketMonitor::Open(_fd);
|
SocketMonitor::Open(_fd.Release());
|
||||||
SocketMonitor::ScheduleRead();
|
SocketMonitor::ScheduleRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ OneServerSocket::Open()
|
|||||||
|
|
||||||
/* register in the EventLoop */
|
/* register in the EventLoop */
|
||||||
|
|
||||||
SetFD(_fd.Release());
|
SetFD(std::move(_fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerSocket::ServerSocket(EventLoop &_loop) noexcept
|
ServerSocket::ServerSocket(EventLoop &_loop) noexcept
|
||||||
@@ -291,18 +291,16 @@ ServerSocket::AddAddress(AllocatedSocketAddress &&address) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerSocket::AddFD(int _fd)
|
ServerSocket::AddFD(UniqueSocketDescriptor fd)
|
||||||
{
|
{
|
||||||
assert(_fd >= 0);
|
assert(fd.IsDefined());
|
||||||
|
|
||||||
SocketDescriptor fd(_fd);
|
|
||||||
|
|
||||||
StaticSocketAddress address = fd.GetLocalAddress();
|
StaticSocketAddress address = fd.GetLocalAddress();
|
||||||
if (!address.IsDefined())
|
if (!address.IsDefined())
|
||||||
throw MakeSocketError("Failed to get socket address");
|
throw MakeSocketError("Failed to get socket address");
|
||||||
|
|
||||||
OneServerSocket &s = AddAddress(address);
|
OneServerSocket &s = AddAddress(address);
|
||||||
s.SetFD(fd);
|
s.SetFD(std::move(fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_TCP
|
#ifdef HAVE_TCP
|
||||||
|
@@ -107,7 +107,7 @@ public:
|
|||||||
*
|
*
|
||||||
* Throws #std::runtime_error on error.
|
* Throws #std::runtime_error on error.
|
||||||
*/
|
*/
|
||||||
void AddFD(int fd);
|
void AddFD(UniqueSocketDescriptor fd);
|
||||||
|
|
||||||
bool IsEmpty() const noexcept {
|
bool IsEmpty() const noexcept {
|
||||||
return sockets.empty();
|
return sockets.empty();
|
||||||
|
Reference in New Issue
Block a user