net/ServerSocket: pass UniqueSocketDescriptor&& to OnAccept()
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "Page.hxx"
|
||||
#include "IcyMetaDataServer.hxx"
|
||||
#include "net/SocketError.hxx"
|
||||
#include "net/UniqueSocketDescriptor.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -185,10 +186,10 @@ HttpdClient::SendResponse()
|
||||
return true;
|
||||
}
|
||||
|
||||
HttpdClient::HttpdClient(HttpdOutput &_httpd, SocketDescriptor _fd,
|
||||
HttpdClient::HttpdClient(HttpdOutput &_httpd, UniqueSocketDescriptor &&_fd,
|
||||
EventLoop &_loop,
|
||||
bool _metadata_supported)
|
||||
:BufferedSocket(_fd, _loop),
|
||||
:BufferedSocket(_fd.Release(), _loop),
|
||||
httpd(_httpd),
|
||||
state(REQUEST),
|
||||
queue_size(0),
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
class UniqueSocketDescriptor;
|
||||
class HttpdOutput;
|
||||
|
||||
class HttpdClient final
|
||||
@@ -131,7 +132,8 @@ public:
|
||||
* @param httpd the HTTP output device
|
||||
* @param _fd the socket file descriptor
|
||||
*/
|
||||
HttpdClient(HttpdOutput &httpd, SocketDescriptor _fd, EventLoop &_loop,
|
||||
HttpdClient(HttpdOutput &httpd, UniqueSocketDescriptor &&_fd,
|
||||
EventLoop &_loop,
|
||||
bool _metadata_supported);
|
||||
|
||||
/**
|
||||
|
||||
@@ -206,7 +206,7 @@ public:
|
||||
return HasClients();
|
||||
}
|
||||
|
||||
void AddClient(SocketDescriptor fd);
|
||||
void AddClient(UniqueSocketDescriptor &&fd);
|
||||
|
||||
/**
|
||||
* Removes a client from the httpd_output.clients linked list.
|
||||
@@ -257,7 +257,8 @@ public:
|
||||
private:
|
||||
virtual void RunDeferred() override;
|
||||
|
||||
void OnAccept(int fd, SocketAddress address, int uid) override;
|
||||
void OnAccept(UniqueSocketDescriptor &&fd,
|
||||
SocketAddress address, int uid) override;
|
||||
};
|
||||
|
||||
extern const class Domain httpd_output_domain;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "encoder/EncoderInterface.hxx"
|
||||
#include "encoder/EncoderPlugin.hxx"
|
||||
#include "encoder/EncoderList.hxx"
|
||||
#include "net/UniqueSocketDescriptor.hxx"
|
||||
#include "net/SocketAddress.hxx"
|
||||
#include "net/ToString.hxx"
|
||||
#include "Page.hxx"
|
||||
@@ -118,9 +119,9 @@ HttpdOutput::Unbind()
|
||||
* HttpdOutput.clients linked list.
|
||||
*/
|
||||
inline void
|
||||
HttpdOutput::AddClient(SocketDescriptor fd)
|
||||
HttpdOutput::AddClient(UniqueSocketDescriptor &&fd)
|
||||
{
|
||||
auto *client = new HttpdClient(*this, fd, GetEventLoop(),
|
||||
auto *client = new HttpdClient(*this, std::move(fd), GetEventLoop(),
|
||||
!encoder->ImplementsTag());
|
||||
clients.push_front(*client);
|
||||
|
||||
@@ -151,7 +152,8 @@ HttpdOutput::RunDeferred()
|
||||
}
|
||||
|
||||
void
|
||||
HttpdOutput::OnAccept(int fd, SocketAddress address, gcc_unused int uid)
|
||||
HttpdOutput::OnAccept(UniqueSocketDescriptor &&fd,
|
||||
SocketAddress address, gcc_unused int uid)
|
||||
{
|
||||
/* the listener socket has become readable - a client has
|
||||
connected */
|
||||
@@ -163,7 +165,7 @@ HttpdOutput::OnAccept(int fd, SocketAddress address, gcc_unused int uid)
|
||||
const char *progname = "mpd";
|
||||
|
||||
struct request_info req;
|
||||
request_init(&req, RQ_FILE, fd, RQ_DAEMON, progname, 0);
|
||||
request_init(&req, RQ_FILE, fd.Get(), RQ_DAEMON, progname, 0);
|
||||
|
||||
fromhost(&req);
|
||||
|
||||
@@ -172,7 +174,6 @@ HttpdOutput::OnAccept(int fd, SocketAddress address, gcc_unused int uid)
|
||||
FormatWarning(httpd_output_domain,
|
||||
"libwrap refused connection (libwrap=%s) from %s",
|
||||
progname, hostaddr.c_str());
|
||||
close_socket(fd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -184,9 +185,7 @@ HttpdOutput::OnAccept(int fd, SocketAddress address, gcc_unused int uid)
|
||||
|
||||
/* can we allow additional client */
|
||||
if (open && (clients_max == 0 || clients.size() < clients_max))
|
||||
AddClient(SocketDescriptor(fd));
|
||||
else
|
||||
close_socket(fd);
|
||||
AddClient(std::move(fd));
|
||||
}
|
||||
|
||||
PagePtr
|
||||
|
||||
Reference in New Issue
Block a user