summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e008533)
raw | patch | inline | side by side (parent: e008533)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Dec 2013 20:51:57 +0000 (21:51 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Dec 2013 20:51:57 +0000 (21:51 +0100) |
There's hardly any reasonable error condition that might happen, so this
rather simplied approach should be sufficient.
rather simplied approach should be sufficient.
src/frontend/sock.c | patch | blob | history |
diff --git a/src/frontend/sock.c b/src/frontend/sock.c
index ce4c07ccd1017247ea21d4edfaddaf139b486177..24708db5ca2bb0e6e5dcc61e5c384fe1a03148ff 100644 (file)
--- a/src/frontend/sock.c
+++ b/src/frontend/sock.c
/* XXX: make the number of threads configurable */
pthread_t handler_threads[5];
+ size_t num_threads;
if ((! sock) || (! sock->listeners_num) || (! loop) || sock->chan)
return -1;
return -1;
}
+ num_threads = SDB_STATIC_ARRAY_LEN(handler_threads);
memset(&handler_threads, 0, sizeof(handler_threads));
- /* XXX: error handling */
- for (i = 0; i < SDB_STATIC_ARRAY_LEN(handler_threads); ++i)
- pthread_create(&handler_threads[i], /* attr = */ NULL,
- connection_handler, /* arg = */ sock);
+ for (i = 0; i < num_threads; ++i) {
+ errno = 0;
+ if (pthread_create(&handler_threads[i], /* attr = */ NULL,
+ connection_handler, /* arg = */ sock)) {
+ char errbuf[1024];
+ sdb_log(SDB_LOG_ERR, "frontend: Failed to create "
+ "connection handler thread: %s",
+ sdb_strerror(errno, errbuf, sizeof(errbuf)));
+ num_threads = i;
+ break;
+ }
+ }
while (loop->do_loop) {
struct timeval timeout = { 1, 0 }; /* one second */
sdb_log(SDB_LOG_INFO, "frontend: Waiting for connection handler threads "
"to terminate");
if (! sdb_channel_shutdown(sock->chan))
- for (i = 0; i < SDB_STATIC_ARRAY_LEN(handler_threads); ++i)
+ for (i = 0; i < num_threads; ++i)
pthread_join(handler_threads[i], NULL);
/* else: we tried our best; let the operating system clean up */