Skip to content

Commit

Permalink
pre_open should pass along context
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Aug 23, 2024
1 parent a7829b9 commit 89db170
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
2 changes: 1 addition & 1 deletion src/libusockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 89db170

Please sign in to comment.