alloc_cnx returns cnx pointer instead of simple error code

This commit is contained in:
yrutschle 2021-04-17 21:29:38 +02:00
parent a487ad4cbe
commit 41a914b350
3 changed files with 6 additions and 6 deletions

View File

@ -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 */

View File

@ -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 */

View File

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