diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 03c37c26..5e3f50eb 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -131,9 +131,10 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context, lwsl_info("insert_wsi_socket_into_fds: wsi=%p, sock=%d, fds pos=%d\n", wsi, wsi->sock, context->fds_count); + struct libwebsocket_pollargs pa = {wsi->sock, POLLIN, 0 }; context->protocols[0].callback(context, wsi, LWS_CALLBACK_LOCK_POLL, - wsi->user_space, (void *)(long)wsi->sock, 0); + wsi->user_space, (void *) &pa, 0); context->lws_lookup[wsi->sock] = wsi; wsi->position_in_fds_table = context->fds_count; @@ -144,11 +145,11 @@ insert_wsi_socket_into_fds(struct libwebsocket_context *context, /* external POLL support via protocol 0 */ context->protocols[0].callback(context, wsi, LWS_CALLBACK_ADD_POLL_FD, - wsi->user_space, (void *)(long)wsi->sock, POLLIN); + wsi->user_space, (void *) &pa, 0); context->protocols[0].callback(context, wsi, LWS_CALLBACK_UNLOCK_POLL, - wsi->user_space, (void *)(long)wsi->sock, 0); + wsi->user_space, (void *)&pa, 0); return 0; } @@ -158,11 +159,12 @@ remove_wsi_socket_from_fds(struct libwebsocket_context *context, struct libwebsocket *wsi) { int m; + struct libwebsocket_pollargs pa = { wsi->sock, 0, 0}; if (!--context->fds_count) { context->protocols[0].callback(context, wsi, LWS_CALLBACK_LOCK_POLL, - wsi->user_space, (void *)(long)wsi->sock, 0); + wsi->user_space, (void *) &pa, 0); goto do_ext; } @@ -177,7 +179,7 @@ remove_wsi_socket_from_fds(struct libwebsocket_context *context, context->protocols[0].callback(context, wsi, LWS_CALLBACK_LOCK_POLL, - wsi->user_space, (void *)(long)wsi->sock, 0); + wsi->user_space, (void *)&pa, 0); m = wsi->position_in_fds_table; /* replace the contents for this */ @@ -197,15 +199,14 @@ remove_wsi_socket_from_fds(struct libwebsocket_context *context, do_ext: /* remove also from external POLL support via protocol 0 */ - if (wsi->sock) + if (wsi->sock) { context->protocols[0].callback(context, wsi, LWS_CALLBACK_DEL_POLL_FD, wsi->user_space, - (void *)(long)wsi->sock, 0); - + (void *) &pa, 0); + } context->protocols[0].callback(context, wsi, - LWS_CALLBACK_UNLOCK_POLL, - wsi->user_space, (void *)(long)wsi->sock, 0); - + LWS_CALLBACK_UNLOCK_POLL, + wsi->user_space, (void *) &pa, 0); return 0; } @@ -1455,25 +1456,22 @@ lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or) int tid; int sampled_ppoll_tid; #endif + struct libwebsocket_pollargs pa; + + pa.fd = wsi->sock; context->protocols[0].callback(context, wsi, LWS_CALLBACK_LOCK_POLL, - wsi->user_space, (void *)(long)wsi->sock, 0); + wsi->user_space, (void *) &pa, 0); - events = context->fds[wsi->position_in_fds_table].events; + pa.prev_events = events = context->fds[wsi->position_in_fds_table].events; - context->fds[wsi->position_in_fds_table].events = (events & ~_and) | _or; + pa.events = context->fds[wsi->position_in_fds_table].events = (events & ~_and) | _or; - /* external POLL support via protocol 0 */ - if (_and) - context->protocols[0].callback(context, wsi, - LWS_CALLBACK_CLEAR_MODE_POLL_FD, - wsi->user_space, (void *)(long)wsi->sock, _and); + context->protocols[0].callback(context, wsi, + LWS_CALLBACK_CHANGE_MODE_POLL_FD, + wsi->user_space, (void *) &pa, 0); - if (_or) - context->protocols[0].callback(context, wsi, - LWS_CALLBACK_SET_MODE_POLL_FD, - wsi->user_space, (void *)(long)wsi->sock, _or); #ifdef LWS_HAS_PPOLL /* @@ -1497,7 +1495,7 @@ lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or) context->protocols[0].callback(context, wsi, LWS_CALLBACK_UNLOCK_POLL, - wsi->user_space, (void *)(long)wsi->sock, 0); + wsi->user_space, (void *) &pa, 0); }