aboutsummaryrefslogtreecommitdiffstats
path: root/src/event
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-30 13:20:27 +0100
committerMax Kellermann <max@duempel.org>2013-01-30 14:16:04 +0100
commitfa51db449fdb9558a4cb4542a86437ac9dd3ddbd (patch)
tree7ecc27850e582fc6b4233bd316dcb079d0702341 /src/event
parentcb9a05ac77034fdcefc0d574e768afe0a1b86327 (diff)
downloadmpd-fa51db449fdb9558a4cb4542a86437ac9dd3ddbd.tar.gz
mpd-fa51db449fdb9558a4cb4542a86437ac9dd3ddbd.tar.xz
mpd-fa51db449fdb9558a4cb4542a86437ac9dd3ddbd.zip
ServerSocket: replace callback with virtual method
Diffstat (limited to 'src/event')
-rw-r--r--src/event/ServerSocket.cxx19
-rw-r--r--src/event/ServerSocket.hxx10
2 files changed, 12 insertions, 17 deletions
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<OneServerSocket> 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