Skip to content
Snippets Groups Projects
Commit 287ee6e4 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

When a callback event is handled, get remote_addr

Prevents weird issues with getting remote address.
parent 4391ca75
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #1874 passed
......@@ -1120,6 +1120,8 @@ js_handle_events(JSContext *cx, js_callback_t *cb, volatile int *terminated)
jsrefcount rc;
JSBool ret = JS_TRUE;
BOOL input_locked = FALSE;
js_socket_private_t* jssp;
socklen_t slen;
#ifdef PREFER_POLL
struct pollfd *fds;
nfds_t sc;
......@@ -1372,6 +1374,12 @@ js_handle_events(JSContext *cx, js_callback_t *cb, volatile int *terminated)
if (input_locked)
js_do_lock_input(cx, FALSE);
}
if (ev->type == JS_EVENT_SOCKET_CONNECT) {
if ((jssp = (js_socket_private_t*)JS_GetPrivate(cx, ev->cx)) != NULL) {
slen=sizeof(ev->data.connect.sock);
getpeername(ev->data.connect.sock, &jssp->remote_addr.addr, &slen);
}
}
ret = JS_CallFunction(cx, ev->cx, ev->cb, 0, NULL, &rval);
......
......@@ -2091,6 +2091,10 @@ js_install_event(JSContext *cx, uintN argc, jsval *arglist, BOOL once)
return(JS_FALSE);
}
/*
* NOTE: If you allow a thisObj here, you'll need to deal with js_GetClassPrivate
* in js_internal.c where the object is assumed to be a socket.
*/
if (argc != 2) {
JS_ReportError(cx, "js.on() and js.once() require exactly two parameters");
return JS_FALSE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment