From: Sebastian Harl Date: Fri, 25 Oct 2013 15:50:17 +0000 (+0200) Subject: socket frontend: Split connection accepting into its own function. X-Git-Tag: sysdb-0.1.0~336^2~36 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=748bf089e36d56076583a8466052505fc786dba9;p=sysdb.git socket frontend: Split connection accepting into its own function. --- diff --git a/src/frontend/sock.c b/src/frontend/sock.c index 12690d8..3662a26 100644 --- a/src/frontend/sock.c +++ b/src/frontend/sock.c @@ -324,6 +324,31 @@ connection_handler(void *data) return NULL; } /* connection_handler */ +static int +accept_connection(sdb_fe_socket_t *sock, listener_t *listener) +{ + sdb_object_t *obj; + + /* the X's will be replaced with the accepted file descriptor + * when initializing the object */ + obj = sdb_object_create(CONN_FD_PREFIX CONN_FD_PLACEHOLDER, + connection_type, listener->sock_fd); + if (! obj) + return -1; + + if (sdb_llist_append(sock->open_connections, obj)) { + sdb_log(SDB_LOG_ERR, "frontend: Failed to append " + "connection %s to list of open connections", + obj->name); + sdb_object_deref(obj); + return -1; + } + + /* hand ownership over to the list */ + sdb_object_deref(obj); + return 0; +} /* accept_connection */ + /* * public API */ @@ -471,28 +496,9 @@ sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock, sdb_fe_loop_t *loop) for (i = 0; i < sock->listeners_num; ++i) { listener_t *listener = sock->listeners + i; - - if (FD_ISSET(listener->sock_fd, &ready)) { - sdb_object_t *obj; - - /* the X's will be replaced with the accepted file descriptor - * when initializing the object */ - obj = sdb_object_create(CONN_FD_PREFIX CONN_FD_PLACEHOLDER, - connection_type, listener->sock_fd); - if (! obj) + if (FD_ISSET(listener->sock_fd, &ready)) + if (accept_connection(sock, listener)) continue; - - if (sdb_llist_append(sock->open_connections, obj)) { - sdb_log(SDB_LOG_ERR, "frontend: Failed to append " - "connection %s to list of open connections", - obj->name); - sdb_object_deref(obj); - continue; - } - - /* hand ownership over to the list */ - sdb_object_deref(obj); - } } iter = sdb_llist_get_iter(sock->open_connections);