summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 13c1b08)
raw | patch | inline | side by side (parent: 13c1b08)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 20 Oct 2013 14:54:12 +0000 (16:54 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 20 Oct 2013 14:54:12 +0000 (16:54 +0200) |
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 9b650dd35c241354e32d96a962708864c37c5a27..8e2bc59dbf53d771d3eb6da298e97b8d5a46ab2f 100644 (file)
--- a/src/frontend/sock.c
+++ b/src/frontend/sock.c
} /* sdb_fe_sock_add_listener */
int
-sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock)
+sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock, sdb_fe_loop_t *loop)
{
sdb_channel_t *chan;
fd_set sockets;
/* XXX: make the number of threads configurable */
pthread_t handler_threads[5];
- if ((! sock) || (! sock->listeners_num))
+ if ((! sock) || (! sock->listeners_num) || (! loop))
return -1;
FD_ZERO(&sockets);
pthread_create(&handler_threads[i], /* attr = */ NULL,
connection_handler, /* arg = */ chan);
- while (42) {
+ while (loop->do_loop) {
fd_set ready = sockets;
int n;
}
}
}
+
+ for (i = 0; i < SDB_STATIC_ARRAY_LEN(handler_threads); ++i)
+ pthread_cancel(handler_threads[i]);
+ for (i = 0; i < SDB_STATIC_ARRAY_LEN(handler_threads); ++i)
+ pthread_join(handler_threads[i], NULL);
return 0;
} /* sdb_fe_sock_listen_and_server */
index 1951614e7ba5362cdd6eb4bfd1dc380b54832a08..ba33d13c194ff575774108ac5bf1af4cc7954b2c 100644 (file)
extern "C" {
#endif
+/* manage a front-end listener loop */
+typedef struct {
+ _Bool do_loop;
+} sdb_fe_loop_t;
+#define SDB_FE_LOOP_INIT { 1 }
+
/*
* sdb_fe_socket_t:
* A front-end socket accepting connections from clients.
/*
* sdb_fe_sock_listen_and_serve:
- * Listen on the specified socket and serve client requests.
+ * Listen on the specified socket and serve client requests. The loop
+ * terminates on error or when the loop condition turns to false.
*
* Returns:
* - 0 on success
* - a negative value else
*/
int
-sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock);
+sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock, sdb_fe_loop_t *loop);
#ifdef __cplusplus
} /* extern "C" */