From 89db1704ddb1ece2aa447f550c863ba5524e0e4d Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Fri, 23 Aug 2024 18:45:09 +0200 Subject: [PATCH] pre_open should pass along context --- src/context.c | 2 +- src/internal/internal.h | 2 +- src/libusockets.h | 2 +- src/loop.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/context.c b/src/context.c index 4b57d89..61e2f14 100644 --- a/src/context.c +++ b/src/context.c @@ -418,7 +418,7 @@ struct us_socket_t *us_socket_context_adopt_socket(int ssl, struct us_socket_con } /* For backwards compatibility, this function will be set to nullptr by default. */ -void us_socket_context_on_pre_open(int ssl, struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(LIBUS_SOCKET_DESCRIPTOR fd)) { +void us_socket_context_on_pre_open(int ssl, struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd)) { /* For this event, there is no difference between SSL and non-SSL */ context->on_pre_open = on_pre_open; } diff --git a/src/internal/internal.h b/src/internal/internal.h index 2bb4213..ce7a24c 100644 --- a/src/internal/internal.h +++ b/src/internal/internal.h @@ -130,7 +130,7 @@ struct us_socket_context_t { struct us_socket_t *iterator; struct us_socket_context_t *prev, *next; - LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(LIBUS_SOCKET_DESCRIPTOR fd); + LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd); struct us_socket_t *(*on_open)(struct us_socket_t *, int is_client, char *ip, int ip_length); struct us_socket_t *(*on_data)(struct us_socket_t *, char *data, int length); struct us_socket_t *(*on_writable)(struct us_socket_t *); diff --git a/src/libusockets.h b/src/libusockets.h index 344c68c..dde4bb6 100644 --- a/src/libusockets.h +++ b/src/libusockets.h @@ -156,7 +156,7 @@ void us_socket_context_free(int ssl, struct us_socket_context_t *context); /* Setters of various async callbacks */ void us_socket_context_on_pre_open(int ssl, struct us_socket_context_t *context, - LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(LIBUS_SOCKET_DESCRIPTOR fd)); + LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd)); void us_socket_context_on_open(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_open)(struct us_socket_t *s, int is_client, char *ip, int ip_length)); void us_socket_context_on_close(int ssl, struct us_socket_context_t *context, diff --git a/src/loop.c b/src/loop.c index 88709d0..77b7598 100644 --- a/src/loop.c +++ b/src/loop.c @@ -277,7 +277,7 @@ void us_internal_dispatch_ready_poll(struct us_poll_t *p, int error, int events) do { struct us_socket_context_t *context = us_socket_context(0, &listen_socket->s); /* See if we want to export the FD or keep it here (this event can be unset) */ - if (context->on_pre_open == 0 || context->on_pre_open(client_fd) == client_fd) { + if (context->on_pre_open == 0 || context->on_pre_open(context, client_fd) == client_fd) { /* Adopt the newly accepted socket */ us_adopt_accepted_socket(0, context,