aboutsummaryrefslogtreecommitdiffstats
path: root/src/server_socket.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-02-13 20:58:57 +0100
committerMax Kellermann <max@duempel.org>2012-02-13 21:32:42 +0100
commitf5294414004c258236a9d31ae3d3ee00ccb26717 (patch)
tree65fa29d538e55f9e429c0050ecde5797be1367d5 /src/server_socket.c
parent03664d0426cd9a10d0f222fbf68e9a43c1f84eb9 (diff)
downloadmpd-f5294414004c258236a9d31ae3d3ee00ccb26717.tar.gz
mpd-f5294414004c258236a9d31ae3d3ee00ccb26717.tar.xz
mpd-f5294414004c258236a9d31ae3d3ee00ccb26717.zip
server_socket: add method _add_fd()
Diffstat (limited to '')
-rw-r--r--src/server_socket.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/server_socket.c b/src/server_socket.c
index 58b3d234a..e4b5e3ece 100644
--- a/src/server_socket.c
+++ b/src/server_socket.c
@@ -299,6 +299,36 @@ one_socket_new(unsigned serial, const struct sockaddr *address,
return s;
}
+bool
+server_socket_add_fd(struct server_socket *ss, int fd, GError **error_r)
+{
+ assert(ss != NULL);
+ assert(ss->sockets_tail_r != NULL);
+ assert(*ss->sockets_tail_r == NULL);
+ assert(fd >= 0);
+
+ struct sockaddr_storage address;
+ socklen_t address_length;
+ if (getsockname(fd, (struct sockaddr *)&address,
+ &address_length) < 0) {
+ g_set_error(error_r, server_socket_quark(), errno,
+ "Failed to get socket address: %s",
+ g_strerror(errno));
+ return false;
+ }
+
+ struct one_socket *s = one_socket_new(ss->next_serial,
+ (struct sockaddr *)&address,
+ address_length);
+ s->parent = ss;
+ *ss->sockets_tail_r = s;
+ ss->sockets_tail_r = &s->next;
+
+ set_fd(s, fd);
+
+ return true;
+}
+
static struct one_socket *
server_socket_add_address(struct server_socket *ss,
const struct sockaddr *address,