diff options
author | rofl0r <rofl0r@users.noreply.github.com> | 2020-09-16 01:05:58 +0100 |
---|---|---|
committer | rofl0r <rofl0r@users.noreply.github.com> | 2020-09-16 01:05:58 +0100 |
commit | 7d33fc8e8a8802f8962f612510d252bbbe465757 (patch) | |
tree | 339696bf23d58f406d87ce6619e37564b1a30576 | |
parent | a5890b621b0985b807865e56f9d230cdd3b6b070 (diff) |
listen_fds: use sblist
-rw-r--r-- | src/child.c | 16 | ||||
-rw-r--r-- | src/sock.c | 4 | ||||
-rw-r--r-- | src/sock.h | 4 |
3 files changed, 12 insertions, 12 deletions
diff --git a/src/child.c b/src/child.c index b220da3..bec0ca3 100644 --- a/src/child.c +++ b/src/child.c @@ -37,7 +37,7 @@ #include "mypoll.h" #include <pthread.h> -static vector_t listen_fds; +static sblist* listen_fds; struct client { union sockaddr_union addr; @@ -82,7 +82,7 @@ void child_main_loop (void) union sockaddr_union cliaddr_storage; struct sockaddr *cliaddr = (void*) &cliaddr_storage; socklen_t clilen = sizeof(cliaddr_storage); - int nfds = vector_length(listen_fds); + int nfds = sblist_getsize(listen_fds); pollfd_struct *fds = safecalloc(nfds, sizeof *fds); ssize_t i; int ret, listenfd, was_full = 0; @@ -92,7 +92,7 @@ void child_main_loop (void) childs = sblist_new(sizeof (struct child*), config->maxclients); for (i = 0; i < nfds; i++) { - int *fd = (int *) vector_getentry(listen_fds, i, NULL); + int *fd = sblist_get(listen_fds, i); fds[i].fd = *fd; fds[i].events |= MYPOLL_READ; } @@ -259,7 +259,7 @@ int child_listening_sockets(vector_t listen_addrs, uint16_t port) assert (port > 0); if (listen_fds == NULL) { - listen_fds = vector_create(); + listen_fds = sblist_new(sizeof(int), 16); if (listen_fds == NULL) { log_message (LOG_ERR, "Could not create the list " "of listening fds"); @@ -299,14 +299,14 @@ int child_listening_sockets(vector_t listen_addrs, uint16_t port) void child_close_sock (void) { - ssize_t i; + size_t i; - for (i = 0; i < vector_length(listen_fds); i++) { - int *fd = (int *) vector_getentry(listen_fds, i, NULL); + for (i = 0; i < sblist_getsize(listen_fds); i++) { + int *fd = sblist_get(listen_fds, i); close (*fd); } - vector_delete(listen_fds); + sblist_free(listen_fds); listen_fds = NULL; } @@ -277,7 +277,7 @@ static int listen_on_one_socket(struct addrinfo *ad) * Upon success, the listen-fds are added to the listen_fds list * and 0 is returned. Upon error, -1 is returned. */ -int listen_sock (const char *addr, uint16_t port, vector_t listen_fds) +int listen_sock (const char *addr, uint16_t port, sblist* listen_fds) { struct addrinfo hints, *result, *rp; char portstr[6]; @@ -315,7 +315,7 @@ int listen_sock (const char *addr, uint16_t port, vector_t listen_fds) continue; } - vector_append (listen_fds, &listenfd, sizeof(int)); + sblist_add (listen_fds, &listenfd); /* success */ ret = 0; @@ -29,7 +29,7 @@ #define MAXLINE (1024 * 4) #include "common.h" -#include "vector.h" +#include "sblist.h" union sockaddr_union { struct sockaddr_in v4; @@ -37,7 +37,7 @@ union sockaddr_union { }; extern int opensock (const char *host, int port, const char *bind_to); -extern int listen_sock (const char *addr, uint16_t port, vector_t listen_fds); +extern int listen_sock (const char *addr, uint16_t port, sblist* listen_fds); extern int socket_nonblocking (int sock); extern int socket_blocking (int sock); |