listen_fds: use sblist

This commit is contained in:
rofl0r 2020-09-16 01:05:58 +01:00
parent a5890b621b
commit 7d33fc8e8a
3 changed files with 12 additions and 12 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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);