diff options
author | Max Kellermann <max@musicpd.org> | 2017-11-10 20:43:14 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-11-10 20:43:14 +0100 |
commit | 0ff4350352e58bcd633b328871a423665143dfd9 (patch) | |
tree | 1c0f7627c1e2b417e2998cae3c784d3899c0769f | |
parent | 5fd2b7cc796ffa5003604a0ed55da8e79b8307a5 (diff) |
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.
-rw-r--r-- | src/Listen.cxx | 3 | ||||
-rw-r--r-- | src/client/Client.hxx | 4 | ||||
-rw-r--r-- | src/client/ClientNew.cxx | 4 | ||||
-rw-r--r-- | src/event/ServerSocket.hxx | 2 | ||||
-rw-r--r-- | src/output/plugins/httpd/HttpdClient.cxx | 2 | ||||
-rw-r--r-- | src/output/plugins/httpd/HttpdClient.hxx | 2 | ||||
-rw-r--r-- | src/output/plugins/httpd/HttpdInternal.hxx | 4 | ||||
-rw-r--r-- | src/output/plugins/httpd/HttpdOutputPlugin.cxx | 4 |
8 files changed, 13 insertions, 12 deletions
diff --git a/src/Listen.cxx b/src/Listen.cxx index 3faccc954..987737f9f 100644 --- a/src/Listen.cxx +++ b/src/Listen.cxx @@ -24,6 +24,7 @@ #include "config/ConfigGlobal.hxx" #include "config/ConfigOption.hxx" #include "net/SocketAddress.hxx" +#include "net/UniqueSocketDescriptor.hxx" #include "event/ServerSocket.hxx" #include "system/Error.hxx" #include "util/RuntimeError.hxx" @@ -50,7 +51,7 @@ public: :ServerSocket(_loop), partition(_partition) {} private: - void OnAccept(UniqueSocketDescriptor &&fd, + void OnAccept(UniqueSocketDescriptor fd, SocketAddress address, int uid) override { client_new(GetEventLoop(), partition, std::move(fd), address, uid); diff --git a/src/client/Client.hxx b/src/client/Client.hxx index 19ceb75c7..5efe45af5 100644 --- a/src/client/Client.hxx +++ b/src/client/Client.hxx @@ -97,7 +97,7 @@ public: std::list<ClientMessage> messages; Client(EventLoop &loop, Partition &partition, - UniqueSocketDescriptor &&fd, int uid, int num); + UniqueSocketDescriptor fd, int uid, int num); ~Client() { if (FullyBufferedSocket::IsDefined()) @@ -239,7 +239,7 @@ client_manager_init(); void 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. diff --git a/src/client/ClientNew.cxx b/src/client/ClientNew.cxx index ce097e1df..5cfcf750f 100644 --- a/src/client/ClientNew.cxx +++ b/src/client/ClientNew.cxx @@ -42,7 +42,7 @@ static constexpr char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n"; Client::Client(EventLoop &_loop, Partition &_partition, - UniqueSocketDescriptor &&_fd, int _uid, int _num) + UniqueSocketDescriptor _fd, int _uid, int _num) :FullyBufferedSocket(_fd.Release(), _loop, 16384, client_max_output_buffer_size), timeout_event(_loop, BIND_THIS_METHOD(OnTimeout)), @@ -56,7 +56,7 @@ Client::Client(EventLoop &_loop, Partition &_partition, void client_new(EventLoop &loop, Partition &partition, - UniqueSocketDescriptor &&fd, SocketAddress address, int uid) + UniqueSocketDescriptor fd, SocketAddress address, int uid) { static unsigned int next_client_num; const auto remote = ToString(address); diff --git a/src/event/ServerSocket.hxx b/src/event/ServerSocket.hxx index 9e44143e3..7c69225b3 100644 --- a/src/event/ServerSocket.hxx +++ b/src/event/ServerSocket.hxx @@ -117,7 +117,7 @@ public: void Close(); protected: - virtual void OnAccept(UniqueSocketDescriptor &&fd, + virtual void OnAccept(UniqueSocketDescriptor fd, SocketAddress address, int uid) = 0; }; diff --git a/src/output/plugins/httpd/HttpdClient.cxx b/src/output/plugins/httpd/HttpdClient.cxx index 7a55af198..4380b89ee 100644 --- a/src/output/plugins/httpd/HttpdClient.cxx +++ b/src/output/plugins/httpd/HttpdClient.cxx @@ -186,7 +186,7 @@ HttpdClient::SendResponse() return true; } -HttpdClient::HttpdClient(HttpdOutput &_httpd, UniqueSocketDescriptor &&_fd, +HttpdClient::HttpdClient(HttpdOutput &_httpd, UniqueSocketDescriptor _fd, EventLoop &_loop, bool _metadata_supported) :BufferedSocket(_fd.Release(), _loop), diff --git a/src/output/plugins/httpd/HttpdClient.hxx b/src/output/plugins/httpd/HttpdClient.hxx index 3c1049622..9a59de71a 100644 --- a/src/output/plugins/httpd/HttpdClient.hxx +++ b/src/output/plugins/httpd/HttpdClient.hxx @@ -132,7 +132,7 @@ public: * @param httpd the HTTP output device * @param _fd the socket file descriptor */ - HttpdClient(HttpdOutput &httpd, UniqueSocketDescriptor &&_fd, + HttpdClient(HttpdOutput &httpd, UniqueSocketDescriptor _fd, EventLoop &_loop, bool _metadata_supported); diff --git a/src/output/plugins/httpd/HttpdInternal.hxx b/src/output/plugins/httpd/HttpdInternal.hxx index 5e6a39dbe..48e0aae2c 100644 --- a/src/output/plugins/httpd/HttpdInternal.hxx +++ b/src/output/plugins/httpd/HttpdInternal.hxx @@ -206,7 +206,7 @@ public: return HasClients(); } - void AddClient(UniqueSocketDescriptor &&fd); + void AddClient(UniqueSocketDescriptor fd); /** * Removes a client from the httpd_output.clients linked list. @@ -257,7 +257,7 @@ public: private: virtual void RunDeferred() override; - void OnAccept(UniqueSocketDescriptor &&fd, + void OnAccept(UniqueSocketDescriptor fd, SocketAddress address, int uid) override; }; diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index 95e3edaab..526ef8ce6 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -118,7 +118,7 @@ HttpdOutput::Unbind() * HttpdOutput.clients linked list. */ inline void -HttpdOutput::AddClient(UniqueSocketDescriptor &&fd) +HttpdOutput::AddClient(UniqueSocketDescriptor fd) { auto *client = new HttpdClient(*this, std::move(fd), GetEventLoop(), !encoder->ImplementsTag()); @@ -151,7 +151,7 @@ HttpdOutput::RunDeferred() } void -HttpdOutput::OnAccept(UniqueSocketDescriptor &&fd, +HttpdOutput::OnAccept(UniqueSocketDescriptor fd, SocketAddress address, gcc_unused int uid) { /* the listener socket has become readable - a client has |