Skip to content

Commit 86097c4

Browse files
authored
on_pre_open: add ip to the handler (#251)
1 parent ae52d1e commit 86097c4

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ struct us_socket_t *us_socket_context_adopt_socket(int ssl, struct us_socket_con
418418
}
419419

420420
/* For backwards compatibility, this function will be set to nullptr by default. */
421-
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)) {
421+
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, char *ip, int ip_length)) {
422422
/* For this event, there is no difference between SSL and non-SSL */
423423
context->on_pre_open = on_pre_open;
424424
}

src/internal/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct us_socket_context_t {
130130
struct us_socket_t *iterator;
131131
struct us_socket_context_t *prev, *next;
132132

133-
LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd);
133+
LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd, char *ip, int ip_length);
134134
struct us_socket_t *(*on_open)(struct us_socket_t *, int is_client, char *ip, int ip_length);
135135
struct us_socket_t *(*on_data)(struct us_socket_t *, char *data, int length);
136136
struct us_socket_t *(*on_writable)(struct us_socket_t *);

src/libusockets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void us_socket_context_free(int ssl, struct us_socket_context_t *context);
159159

160160
/* Setters of various async callbacks */
161161
void us_socket_context_on_pre_open(int ssl, struct us_socket_context_t *context,
162-
LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd));
162+
LIBUS_SOCKET_DESCRIPTOR (*on_pre_open)(struct us_socket_context_t *context, LIBUS_SOCKET_DESCRIPTOR fd, char *ip, int ip_length));
163163
void us_socket_context_on_open(int ssl, struct us_socket_context_t *context,
164164
struct us_socket_t *(*on_open)(struct us_socket_t *s, int is_client, char *ip, int ip_length));
165165
void us_socket_context_on_close(int ssl, struct us_socket_context_t *context,

src/loop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void us_internal_dispatch_ready_poll(struct us_poll_t *p, int error, int events)
277277
do {
278278
struct us_socket_context_t *context = us_socket_context(0, &listen_socket->s);
279279
/* See if we want to export the FD or keep it here (this event can be unset) */
280-
if (context->on_pre_open == 0 || context->on_pre_open(context, client_fd) == client_fd) {
280+
if (context->on_pre_open == 0 || context->on_pre_open(context, client_fd, bsd_addr_get_ip(&addr), bsd_addr_get_ip_length(&addr)) == client_fd) {
281281

282282
/* Adopt the newly accepted socket */
283283
us_adopt_accepted_socket(0, context,

0 commit comments

Comments
 (0)