summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cebacbd)
raw | patch | inline | side by side (parent: cebacbd)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 26 Oct 2013 12:05:42 +0000 (14:05 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 26 Oct 2013 12:05:42 +0000 (14:05 +0200) |
Also, cleaned up listener handling a bit.
src/frontend/sock.c | patch | blob | history | |
src/include/frontend/sock.h | patch | blob | history |
diff --git a/src/frontend/sock.c b/src/frontend/sock.c
index 9fba695b6ef44c6e4ed79a933dafc93ba725128e..27a1b679c2815f17932cd3845383ff7649a9d502 100644 (file)
--- a/src/frontend/sock.c
+++ b/src/frontend/sock.c
if (listener->sock_fd >= 0)
close(listener->sock_fd);
+ listener->sock_fd = -1;
if (listener->address)
free(listener->address);
return listener;
} /* listener_create */
+static int
+listener_listen(listener_t *listener)
+{
+ assert(listener);
+
+ if (listen(listener->sock_fd, /* backlog = */ 32)) {
+ char buf[1024];
+ sdb_log(SDB_LOG_ERR, "frontend: Failed to listen on socket %s: %s",
+ listener->address, sdb_strerror(errno, buf, sizeof(buf)));
+ return -1;
+ }
+ return 0;
+} /* listener_listen */
+
+static void
+listener_close(listener_t *listener)
+{
+ assert(listener);
+
+ if (listener->sock_fd < 0)
+ return;
+
+ close(listener->sock_fd);
+ listener->sock_fd = -1;
+} /* listener_close */
+
/*
* private data types
*/
for (i = 0; i < sock->listeners_num; ++i) {
listener_t *listener = sock->listeners + i;
- if (listen(listener->sock_fd, /* backlog = */ 32)) {
- char buf[1024];
- sdb_log(SDB_LOG_ERR, "frontend: Failed to listen on socket %s: %s",
- listener->address, sdb_strerror(errno, buf, sizeof(buf)));
+ if (listener_listen(listener))
return -1;
- }
FD_SET(listener->sock_fd, &sockets);
if (listener->sock_fd > max_listen_fd)
sdb_llist_iter_destroy(iter);
}
+ for (i = 0; i < sock->listeners_num; ++i)
+ listener_close(sock->listeners + i);
+
sdb_log(SDB_LOG_INFO, "frontend: Waiting for connection handler threads "
"to terminate");
if (! sdb_channel_shutdown(sock->chan))
index ba33d13c194ff575774108ac5bf1af4cc7954b2c..6ab8ccadbf9ebb4ebee101a2701e9e43d57cb296 100644 (file)
/*
* sdb_fe_sock_listen_and_serve:
* Listen on the specified socket and serve client requests. The loop
- * terminates on error or when the loop condition turns to false.
+ * terminates on error or when the loop condition turns to false. All
+ * listening sockets will be closed at that time.
*
* Returns:
* - 0 on success