From: Sebastian Harl Date: Mon, 21 Apr 2014 18:22:22 +0000 (+0200) Subject: frontend: Added sdb_fe_sock_clear_listeners(). X-Git-Tag: sysdb-0.1.0~104 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=822c6c9f5e9a0482c568371eb9da5e55426c1c15;p=sysdb.git frontend: Added sdb_fe_sock_clear_listeners(). This function may be used to shut down and clear all listeners associated with a socket object without affecting any open connections. --- diff --git a/src/frontend/sock.c b/src/frontend/sock.c index 7cfdb7c..90aeab1 100644 --- a/src/frontend/sock.c +++ b/src/frontend/sock.c @@ -274,6 +274,20 @@ listener_create(sdb_fe_socket_t *sock, const char *address) return listener; } /* listener_create */ +static void +socket_clear(sdb_fe_socket_t *sock) +{ + size_t i; + + assert(sock); + for (i = 0; i < sock->listeners_num; ++i) + listener_destroy(sock->listeners + i); + if (sock->listeners) + free(sock->listeners); + sock->listeners = NULL; + sock->listeners_num = 0; +} /* socket_clear */ + static void socket_close(sdb_fe_socket_t *sock) { @@ -423,17 +437,10 @@ sdb_fe_sock_create(void) void sdb_fe_sock_destroy(sdb_fe_socket_t *sock) { - size_t i; - if (! sock) return; - for (i = 0; i < sock->listeners_num; ++i) { - listener_destroy(sock->listeners + i); - } - if (sock->listeners) - free(sock->listeners); - sock->listeners = NULL; + socket_clear(sock); sdb_llist_destroy(sock->open_connections); sock->open_connections = NULL; @@ -454,6 +461,15 @@ sdb_fe_sock_add_listener(sdb_fe_socket_t *sock, const char *address) return 0; } /* sdb_fe_sock_add_listener */ +void +sdb_fe_sock_clear_listeners(sdb_fe_socket_t *sock) +{ + if (! sock) + return; + + socket_clear(sock); +} /* sdb_fe_sock_clear_listeners */ + int sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock, sdb_fe_loop_t *loop) { diff --git a/src/include/frontend/sock.h b/src/include/frontend/sock.h index 7d1fd7a..2b93a6f 100644 --- a/src/include/frontend/sock.h +++ b/src/include/frontend/sock.h @@ -83,6 +83,14 @@ sdb_fe_sock_destroy(sdb_fe_socket_t *sock); int sdb_fe_sock_add_listener(sdb_fe_socket_t *sock, const char *address); +/* + * sdb_fe_sock_clear_listeners: + * Shut down all listeners from the socket object and clear the list of + * listeners. All open connections will not be affected by this. + */ +void +sdb_fe_sock_clear_listeners(sdb_fe_socket_t *sock); + /* * sdb_fe_sock_listen_and_serve: * Listen on the specified socket and serve client requests. The loop