From 41a914b3508816f35ff1db2de02a666efef45dde Mon Sep 17 00:00:00 2001 From: yrutschle Date: Sat, 17 Apr 2021 21:29:38 +0200 Subject: [PATCH] alloc_cnx returns cnx pointer instead of simple error code --- collection.c | 6 +++--- collection.h | 2 +- sslh-select.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/collection.c b/collection.c index 58405ba..ccb768c 100644 --- a/collection.c +++ b/collection.c @@ -61,11 +61,11 @@ int collection_add_fd(cnx_collection* collection, struct connection* cnx, int fd } /* Allocates a connection and inits it with specified file descriptor */ -int collection_alloc_cnx_from_fd(struct cnx_collection* collection, int fd) +struct connection* collection_alloc_cnx_from_fd(struct cnx_collection* collection, int fd) { struct connection* cnx = malloc(sizeof(*cnx)); - if (!cnx) return -1; + if (!cnx) return NULL; init_cnx(cnx); cnx->q[0].fd = fd; @@ -74,7 +74,7 @@ int collection_alloc_cnx_from_fd(struct cnx_collection* collection, int fd) gap_set(collection->fd2cnx, fd, cnx); - return 0; + return cnx; } /* Remove a connection from the collection */ diff --git a/collection.h b/collection.h index ac91268..f44b270 100644 --- a/collection.h +++ b/collection.h @@ -7,7 +7,7 @@ typedef struct cnx_collection cnx_collection; cnx_collection* collection_init(void); void collection_destroy(cnx_collection* collection); -int collection_alloc_cnx_from_fd(cnx_collection* collection, int fd); +struct connection* collection_alloc_cnx_from_fd(cnx_collection* collection, int fd); int collection_add_fd(cnx_collection* collection, struct connection* cnx, int fd); /* Remove a connection from the collection */ diff --git a/sslh-select.c b/sslh-select.c index 29e9d93..9ccea2b 100644 --- a/sslh-select.c +++ b/sslh-select.c @@ -113,8 +113,8 @@ static int accept_new_connection(int listen_socket, struct cnx_collection *colle return -1; } - res = collection_alloc_cnx_from_fd(collection, in_socket); - if (res == -1) { + struct connection* cnx = collection_alloc_cnx_from_fd(collection, in_socket); + if (!cnx) { close(in_socket); return -1; }