event/ServerSocket: pass UniqueSocketDescriptor by value
Passing it by value is actually smaller (32 bit) than the rvalue reference (64 bit pointer), and it ensures that the object is consumed after the call returns, no matter how the methods are implemented.
This commit is contained in:
parent
5fd2b7cc79
commit
0ff4350352
@ -24,6 +24,7 @@
|
|||||||
#include "config/ConfigGlobal.hxx"
|
#include "config/ConfigGlobal.hxx"
|
||||||
#include "config/ConfigOption.hxx"
|
#include "config/ConfigOption.hxx"
|
||||||
#include "net/SocketAddress.hxx"
|
#include "net/SocketAddress.hxx"
|
||||||
|
#include "net/UniqueSocketDescriptor.hxx"
|
||||||
#include "event/ServerSocket.hxx"
|
#include "event/ServerSocket.hxx"
|
||||||
#include "system/Error.hxx"
|
#include "system/Error.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
@ -50,7 +51,7 @@ public:
|
|||||||
:ServerSocket(_loop), partition(_partition) {}
|
:ServerSocket(_loop), partition(_partition) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnAccept(UniqueSocketDescriptor &&fd,
|
void OnAccept(UniqueSocketDescriptor fd,
|
||||||
SocketAddress address, int uid) override {
|
SocketAddress address, int uid) override {
|
||||||
client_new(GetEventLoop(), partition,
|
client_new(GetEventLoop(), partition,
|
||||||
std::move(fd), address, uid);
|
std::move(fd), address, uid);
|
||||||
|
@ -97,7 +97,7 @@ public:
|
|||||||
std::list<ClientMessage> messages;
|
std::list<ClientMessage> messages;
|
||||||
|
|
||||||
Client(EventLoop &loop, Partition &partition,
|
Client(EventLoop &loop, Partition &partition,
|
||||||
UniqueSocketDescriptor &&fd, int uid, int num);
|
UniqueSocketDescriptor fd, int uid, int num);
|
||||||
|
|
||||||
~Client() {
|
~Client() {
|
||||||
if (FullyBufferedSocket::IsDefined())
|
if (FullyBufferedSocket::IsDefined())
|
||||||
@ -239,7 +239,7 @@ client_manager_init();
|
|||||||
|
|
||||||
void
|
void
|
||||||
client_new(EventLoop &loop, Partition &partition,
|
client_new(EventLoop &loop, Partition &partition,
|
||||||
UniqueSocketDescriptor &&fd, SocketAddress address, int uid);
|
UniqueSocketDescriptor fd, SocketAddress address, int uid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a printf-like formatted string to the client.
|
* Write a printf-like formatted string to the client.
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
static constexpr char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n";
|
static constexpr char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n";
|
||||||
|
|
||||||
Client::Client(EventLoop &_loop, Partition &_partition,
|
Client::Client(EventLoop &_loop, Partition &_partition,
|
||||||
UniqueSocketDescriptor &&_fd, int _uid, int _num)
|
UniqueSocketDescriptor _fd, int _uid, int _num)
|
||||||
:FullyBufferedSocket(_fd.Release(), _loop,
|
:FullyBufferedSocket(_fd.Release(), _loop,
|
||||||
16384, client_max_output_buffer_size),
|
16384, client_max_output_buffer_size),
|
||||||
timeout_event(_loop, BIND_THIS_METHOD(OnTimeout)),
|
timeout_event(_loop, BIND_THIS_METHOD(OnTimeout)),
|
||||||
@ -56,7 +56,7 @@ Client::Client(EventLoop &_loop, Partition &_partition,
|
|||||||
|
|
||||||
void
|
void
|
||||||
client_new(EventLoop &loop, Partition &partition,
|
client_new(EventLoop &loop, Partition &partition,
|
||||||
UniqueSocketDescriptor &&fd, SocketAddress address, int uid)
|
UniqueSocketDescriptor fd, SocketAddress address, int uid)
|
||||||
{
|
{
|
||||||
static unsigned int next_client_num;
|
static unsigned int next_client_num;
|
||||||
const auto remote = ToString(address);
|
const auto remote = ToString(address);
|
||||||
|
@ -117,7 +117,7 @@ public:
|
|||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnAccept(UniqueSocketDescriptor &&fd,
|
virtual void OnAccept(UniqueSocketDescriptor fd,
|
||||||
SocketAddress address, int uid) = 0;
|
SocketAddress address, int uid) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ HttpdClient::SendResponse()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpdClient::HttpdClient(HttpdOutput &_httpd, UniqueSocketDescriptor &&_fd,
|
HttpdClient::HttpdClient(HttpdOutput &_httpd, UniqueSocketDescriptor _fd,
|
||||||
EventLoop &_loop,
|
EventLoop &_loop,
|
||||||
bool _metadata_supported)
|
bool _metadata_supported)
|
||||||
:BufferedSocket(_fd.Release(), _loop),
|
:BufferedSocket(_fd.Release(), _loop),
|
||||||
|
@ -132,7 +132,7 @@ public:
|
|||||||
* @param httpd the HTTP output device
|
* @param httpd the HTTP output device
|
||||||
* @param _fd the socket file descriptor
|
* @param _fd the socket file descriptor
|
||||||
*/
|
*/
|
||||||
HttpdClient(HttpdOutput &httpd, UniqueSocketDescriptor &&_fd,
|
HttpdClient(HttpdOutput &httpd, UniqueSocketDescriptor _fd,
|
||||||
EventLoop &_loop,
|
EventLoop &_loop,
|
||||||
bool _metadata_supported);
|
bool _metadata_supported);
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ public:
|
|||||||
return HasClients();
|
return HasClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddClient(UniqueSocketDescriptor &&fd);
|
void AddClient(UniqueSocketDescriptor fd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a client from the httpd_output.clients linked list.
|
* Removes a client from the httpd_output.clients linked list.
|
||||||
@ -257,7 +257,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
virtual void RunDeferred() override;
|
virtual void RunDeferred() override;
|
||||||
|
|
||||||
void OnAccept(UniqueSocketDescriptor &&fd,
|
void OnAccept(UniqueSocketDescriptor fd,
|
||||||
SocketAddress address, int uid) override;
|
SocketAddress address, int uid) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ HttpdOutput::Unbind()
|
|||||||
* HttpdOutput.clients linked list.
|
* HttpdOutput.clients linked list.
|
||||||
*/
|
*/
|
||||||
inline void
|
inline void
|
||||||
HttpdOutput::AddClient(UniqueSocketDescriptor &&fd)
|
HttpdOutput::AddClient(UniqueSocketDescriptor fd)
|
||||||
{
|
{
|
||||||
auto *client = new HttpdClient(*this, std::move(fd), GetEventLoop(),
|
auto *client = new HttpdClient(*this, std::move(fd), GetEventLoop(),
|
||||||
!encoder->ImplementsTag());
|
!encoder->ImplementsTag());
|
||||||
@ -151,7 +151,7 @@ HttpdOutput::RunDeferred()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
HttpdOutput::OnAccept(UniqueSocketDescriptor &&fd,
|
HttpdOutput::OnAccept(UniqueSocketDescriptor fd,
|
||||||
SocketAddress address, gcc_unused int uid)
|
SocketAddress address, gcc_unused int uid)
|
||||||
{
|
{
|
||||||
/* the listener socket has become readable - a client has
|
/* the listener socket has become readable - a client has
|
||||||
|
Loading…
Reference in New Issue
Block a user