From fa51db449fdb9558a4cb4542a86437ac9dd3ddbd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Jan 2013 13:20:27 +0100 Subject: ServerSocket: replace callback with virtual method --- src/event/ServerSocket.cxx | 19 +++++++------------ src/event/ServerSocket.hxx | 10 +++++----- 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'src/event') diff --git a/src/event/ServerSocket.cxx b/src/event/ServerSocket.cxx index ea2f07e38..d444933a0 100644 --- a/src/event/ServerSocket.cxx +++ b/src/event/ServerSocket.cxx @@ -54,7 +54,7 @@ #define DEFAULT_PORT 6600 class OneServerSocket final : private SocketMonitor { - const ServerSocket &parent; + ServerSocket &parent; const unsigned serial; @@ -64,7 +64,7 @@ class OneServerSocket final : private SocketMonitor { struct sockaddr *address; public: - OneServerSocket(EventLoop &_loop, const ServerSocket &_parent, + OneServerSocket(EventLoop &_loop, ServerSocket &_parent, unsigned _serial, const struct sockaddr *_address, size_t _address_length) @@ -176,10 +176,9 @@ OneServerSocket::Accept() (const char *)msg); } - parent.callback(peer_fd, - (const struct sockaddr*)&peer_address, - peer_address_length, get_remote_uid(peer_fd), - parent.callback_ctx); + parent.OnAccept(peer_fd, + (const sockaddr &)peer_address, + peer_address_length, get_remote_uid(peer_fd)); } bool @@ -213,12 +212,8 @@ OneServerSocket::Open(GError **error_r) return true; } -ServerSocket::ServerSocket(EventLoop &_loop, - server_socket_callback_t _callback, - void *_callback_ctx) - :loop(_loop), - callback(_callback), callback_ctx(_callback_ctx), - next_serial(1) {} +ServerSocket::ServerSocket(EventLoop &_loop) + :loop(_loop), next_serial(1) {} /* this is just here to allow the OneServerSocket forward declaration */ diff --git a/src/event/ServerSocket.hxx b/src/event/ServerSocket.hxx index bfa4d3f3b..ec922d97f 100644 --- a/src/event/ServerSocket.hxx +++ b/src/event/ServerSocket.hxx @@ -41,16 +41,12 @@ class ServerSocket { EventLoop &loop; - server_socket_callback_t callback; - void *callback_ctx; - std::forward_list sockets; unsigned next_serial; public: - ServerSocket(EventLoop &_loop, - server_socket_callback_t _callback, void *_callback_ctx); + ServerSocket(EventLoop &_loop); ~ServerSocket(); private: @@ -112,6 +108,10 @@ public: bool Open(GError **error_r); void Close(); + +protected: + virtual void OnAccept(int fd, const sockaddr &address, + size_t address_length, int uid) = 0; }; #endif -- cgit v1.2.3