aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-15 22:53:14 +0100
committerMax Kellermann <max@duempel.org>2013-01-15 22:53:14 +0100
commit0c6072c4e4e442433f3b19c26d8332219a4666a1 (patch)
treebe5637582384154abb51ecd114f50ef2ed30c4a8 /src
parent8917264110fb684ef1fa87fdab14dd78902e8bba (diff)
downloadmpd-0c6072c4e4e442433f3b19c26d8332219a4666a1.tar.gz
mpd-0c6072c4e4e442433f3b19c26d8332219a4666a1.tar.xz
mpd-0c6072c4e4e442433f3b19c26d8332219a4666a1.zip
ServerSocket: move more code to methods
Diffstat (limited to '')
-rw-r--r--src/ServerSocket.cxx49
1 files changed, 30 insertions, 19 deletions
diff --git a/src/ServerSocket.cxx b/src/ServerSocket.cxx
index 3a3a4a528..3a709e140 100644
--- a/src/ServerSocket.cxx
+++ b/src/ServerSocket.cxx
@@ -97,6 +97,8 @@ struct OneServerSocket {
char *ToString() const;
void SetFD(int fd);
+
+ void Accept();
};
struct server_socket {
@@ -169,31 +171,40 @@ get_remote_uid(int fd)
#endif
}
+inline void
+OneServerSocket::Accept()
+{
+ struct sockaddr_storage peer_address;
+ size_t peer_address_length = sizeof(peer_address);
+ int peer_fd =
+ accept_cloexec_nonblock(fd, (struct sockaddr*)&peer_address,
+ &peer_address_length);
+ if (peer_fd < 0) {
+ const SocketErrorMessage msg;
+ g_warning("accept() failed: %s", (const char *)msg);
+ return;
+ }
+
+ if (socket_keepalive(peer_fd)) {
+ const SocketErrorMessage msg;
+ g_warning("Could not set TCP keepalive option: %s",
+ (const char *)msg);
+ }
+
+ parent.callback(peer_fd,
+ (const struct sockaddr*)&peer_address,
+ peer_address_length, get_remote_uid(peer_fd),
+ parent.callback_ctx);
+}
+
static gboolean
server_socket_in_event(G_GNUC_UNUSED GIOChannel *source,
G_GNUC_UNUSED GIOCondition condition,
gpointer data)
{
- OneServerSocket *s = (OneServerSocket *)data;
-
- struct sockaddr_storage address;
- size_t address_length = sizeof(address);
- int fd = accept_cloexec_nonblock(s->fd, (struct sockaddr*)&address,
- &address_length);
- if (fd >= 0) {
- if (socket_keepalive(fd)) {
- const SocketErrorMessage msg;
- g_warning("Could not set TCP keepalive option: %s",
- (const char *)msg);
- }
- s->parent.callback(fd, (const struct sockaddr*)&address,
- address_length, get_remote_uid(fd),
- s->parent.callback_ctx);
- } else {
- const SocketErrorMessage msg;
- g_warning("accept() failed: %s", (const char *)msg);
- }
+ OneServerSocket &s = *(OneServerSocket *)data;
+ s.Accept();
return true;
}