Skip to content

Commit

Permalink
event/net/ServerSocket: pass connection socket by value
Browse files Browse the repository at this point in the history
UniqueSocketDescriptor is a 32-bit class, and the reference is usually
twice as large.
  • Loading branch information
MaxKellermann committed Jan 5, 2024
1 parent d217b80 commit 07af8cc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/event/net/ServerSocket.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected:
*
* @param fd the socket owned by the callee
*/
virtual void OnAccept(UniqueSocketDescriptor &&fd,
virtual void OnAccept(UniqueSocketDescriptor fd,
SocketAddress address) noexcept = 0;
virtual void OnAcceptError(std::exception_ptr ep) noexcept = 0;

Expand Down
8 changes: 3 additions & 5 deletions src/event/net/TemplateServerSocket.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Copyright CM4all GmbH
// author: Max Kellermann <[email protected]>

#ifndef TEMPLATE_SERVER_SOCKET_HXX
#define TEMPLATE_SERVER_SOCKET_HXX
#pragma once

#include "ServerSocket.hxx"
#include "net/SocketAddress.hxx"
#include "net/UniqueSocketDescriptor.hxx"
#include "util/DeleteDisposer.hxx"
#include "util/IntrusiveList.hxx"
#include "util/PrintException.hxx"
Expand Down Expand Up @@ -65,7 +65,7 @@ public:
}

protected:
void OnAccept(UniqueSocketDescriptor &&_fd,
void OnAccept(UniqueSocketDescriptor _fd,
SocketAddress address) noexcept override {
try {
auto *c = CreateConnection(std::move(_fd), address);
Expand All @@ -86,5 +86,3 @@ private:
address, params);
}
};

#endif
2 changes: 1 addition & 1 deletion src/translation/server/Listener.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Listener::~Listener() noexcept
}

void
Listener::OnAccept(UniqueSocketDescriptor &&new_fd,
Listener::OnAccept(UniqueSocketDescriptor new_fd,
SocketAddress) noexcept
{
auto *connection = new Connection(GetEventLoop(),
Expand Down
2 changes: 1 addition & 1 deletion src/translation/server/Listener.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public:
using ServerSocket::ListenPath;

private:
void OnAccept(UniqueSocketDescriptor &&fd,
void OnAccept(UniqueSocketDescriptor fd,
SocketAddress address) noexcept override;
void OnAcceptError(std::exception_ptr ep) noexcept override;
};
Expand Down
6 changes: 3 additions & 3 deletions src/was/async/SimpleRun.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ class MultiListener final

private:
/* virtual methods from class ServerSocket */
void OnAccept(UniqueSocketDescriptor &&fd,
SocketAddress) noexcept {
void OnAccept(UniqueSocketDescriptor fd,
SocketAddress) noexcept override {
connections.Add(GetEventLoop(), std::move(fd));
}

void OnAcceptError(std::exception_ptr _error) noexcept {
void OnAcceptError(std::exception_ptr _error) noexcept override {
error = std::move(_error);
GetEventLoop().Break();
}
Expand Down

0 comments on commit 07af8cc

Please sign in to comment.