diff --git a/include/libwebsockets/lws-adopt.h b/include/libwebsockets/lws-adopt.h index c44080be49..03fa5d4c61 100644 --- a/include/libwebsockets/lws-adopt.h +++ b/include/libwebsockets/lws-adopt.h @@ -75,11 +75,21 @@ typedef enum { LWS_ADOPT_RAW_SOCKET_UDP = LWS_ADOPT_SOCKET | LWS_ADOPT_FLAG_UDP, } lws_adoption_type; +#define LWS_NO_FDS_POS ((int32_t)-1) + typedef union { lws_sockfd_type sockfd; lws_filefd_type filefd; } lws_sock_file_fd_type; +typedef struct { + lws_sock_file_fd_type u; +#if defined(LWS_WITH_EVENT_LIBS) + void *evlib_desc; /* overallocated */ +#endif + int32_t pos_in_fds_table; +} lws_desc_t; + #if defined(LWS_ESP_PLATFORM) #include #endif diff --git a/lib/core-net/adopt.c b/lib/core-net/adopt.c index 0f530428a7..4b5f16a638 100644 --- a/lib/core-net/adopt.c +++ b/lib/core-net/adopt.c @@ -300,7 +300,7 @@ lws_adopt_ss_server_accept(struct lws *new_wsi) h->policy = new_wsi->a.vhost->ss_handle->policy; /* apply requested socket options */ - if (lws_plat_set_socket_options_ip(new_wsi->desc.sockfd, + if (lws_plat_set_socket_options_ip(new_wsi->desc.u.sockfd, h->policy->priority, (LCCSCF_IP_LOW_LATENCY * !!(h->policy->flags & LWSSSPOLF_ATTR_LOW_LATENCY)) | @@ -373,7 +373,7 @@ lws_adopt_descriptor_vhost2(struct lws *new_wsi, lws_adoption_type type, } #endif - new_wsi->desc = fd; + new_wsi->desc.u = fd; if (!LWS_SSL_ENABLED(new_wsi->a.vhost) || !(type & LWS_ADOPT_SOCKET)) @@ -579,7 +579,7 @@ adopt_socket_readbuf(struct lws *wsi, const char *readbuf, size_t len) if (!readbuf || len == 0) return wsi; - if (wsi->position_in_fds_table == LWS_NO_FDS_POS) + if (wsi->desc.pos_in_fds_table == LWS_NO_FDS_POS) return wsi; pt = &wsi->a.context->pt[(int)wsi->tsi]; @@ -611,7 +611,7 @@ adopt_socket_readbuf(struct lws *wsi, const char *readbuf, size_t len) * libuv won't come back and service us without a network * event, so we need to do the header service right here. */ - pfd = &pt->fds[wsi->position_in_fds_table]; + pfd = &pt->fds[wsi->desc.pos_in_fds_table]; pfd->revents |= LWS_POLLIN; lwsl_err("%s: calling service\n", __func__); if (lws_service_fd_tsi(wsi->a.context, pfd, wsi->tsi)) diff --git a/lib/core-net/client/connect.c b/lib/core-net/client/connect.c index f5ac2dcec3..1c0bd0c4cd 100644 --- a/lib/core-net/client/connect.c +++ b/lib/core-net/client/connect.c @@ -283,7 +283,7 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) wsi->user_space = NULL; wsi->pending_timeout = NO_PENDING_TIMEOUT; - wsi->position_in_fds_table = LWS_NO_FDS_POS; + wsi->desc.pos_in_fds_table = LWS_NO_FDS_POS; wsi->ocport = wsi->c_port = (uint16_t)(unsigned int)i->port; wsi->sys_tls_client_cert = i->sys_tls_client_cert; diff --git a/lib/core-net/client/connect3.c b/lib/core-net/client/connect3.c index b6433e7a80..b42507b434 100644 --- a/lib/core-net/client/connect3.c +++ b/lib/core-net/client/connect3.c @@ -90,7 +90,7 @@ lws_client_connect_check(struct lws *wsi, int *real_errno) */ #if !defined(WIN32) - if (!getsockopt(wsi->desc.sockfd, SOL_SOCKET, SO_ERROR, &e, &sl)) { + if (!getsockopt(wsi->desc.u.sockfd, SOL_SOCKET, SO_ERROR, &e, &sl)) { en = LWS_ERRNO; if (!e) { @@ -100,7 +100,7 @@ lws_client_connect_check(struct lws *wsi, int *real_errno) return LCCCR_CONNECTED; } - lwsl_wsi_notice(wsi, "getsockopt fd %d says %s", wsi->desc.sockfd, + lwsl_wsi_notice(wsi, "getsockopt fd %d says %s", wsi->desc.u.sockfd, lws_errno_describe(e, t16, sizeof(t16))); *real_errno = e; @@ -110,7 +110,7 @@ lws_client_connect_check(struct lws *wsi, int *real_errno) #else - if (!connect(wsi->desc.sockfd, (const struct sockaddr *)&wsi->sa46_peer.sa4, 0)) + if (!connect(wsi->desc.u.sockfd, (const struct sockaddr *)&wsi->sa46_peer.sa4, 0)) return LCCCR_CONNECTED; en = LWS_ERRNO; @@ -208,8 +208,8 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, if (n && /* calling back with a problem */ !wsi->dns_sorted_list.count && /* there's no results */ - !lws_socket_is_valid(wsi->desc.sockfd) && /* no attempt ongoing */ - !wsi->speculative_connect_owner.count /* no spec attempt */ ) { + !lws_socket_is_valid(wsi->desc.u.sockfd) /* no attempt ongoing */ + ) { lwsl_wsi_notice(wsi, "dns lookup failed %d", n); /* @@ -234,7 +234,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, */ if (lwsi_state(wsi) == LRS_WAITING_CONNECT && - lws_socket_is_valid(wsi->desc.sockfd)) { + lws_socket_is_valid(wsi->desc.u.sockfd)) { if (!wsi->dns_sorted_list.count && !wsi->sul_connect_timeout.list.owner) /* no dns results and no ongoing timeout for one */ @@ -343,7 +343,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, * socket and add to the fds */ - if (!lws_socket_is_valid(wsi->desc.sockfd)) { + if (!lws_socket_is_valid(wsi->desc.u.sockfd)) { if (wsi->a.context->event_loop_ops->check_client_connect_ok && wsi->a.context->event_loop_ops->check_client_connect_ok(wsi) @@ -356,17 +356,17 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, af = 0; if (wsi->unix_skt) { af = AF_UNIX; - wsi->desc.sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + wsi->desc.u.sockfd = socket(AF_UNIX, SOCK_STREAM, 0); } else #endif { af = wsi->sa46_peer.sa4.sin_family; - wsi->desc.sockfd = socket(wsi->sa46_peer.sa4.sin_family, + wsi->desc.u.sockfd = socket(wsi->sa46_peer.sa4.sin_family, SOCK_STREAM, 0); } - if (!lws_socket_is_valid(wsi->desc.sockfd)) { + if (!lws_socket_is_valid(wsi->desc.u.sockfd)) { en = LWS_ERRNO; lws_snprintf(dcce, sizeof(dcce), @@ -377,7 +377,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, goto try_next_dns_result; } - if (lws_plat_set_socket_options(wsi->a.vhost, wsi->desc.sockfd, + if (lws_plat_set_socket_options(wsi->a.vhost, wsi->desc.u.sockfd, #if defined(LWS_WITH_UNIX_SOCK) wsi->unix_skt)) { #else @@ -394,7 +394,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, } /* apply requested socket options */ - if (lws_plat_set_socket_options_ip(wsi->desc.sockfd, + if (lws_plat_set_socket_options_ip(wsi->desc.u.sockfd, wsi->c_pri, wsi->flags)) lwsl_wsi_warn(wsi, "unable to set ip options"); @@ -451,7 +451,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, _WSI_TOKEN_CLIENT_LOCALPORT); if ((iface && *iface) || (local_port && atoi(local_port))) { - m = lws_socket_bind(wsi->a.vhost, wsi, wsi->desc.sockfd, + m = lws_socket_bind(wsi->a.vhost, wsi, wsi->desc.u.sockfd, (local_port ? atoi(local_port) : 0), iface, af); if (m < 0) { lws_snprintf(dcce, sizeof(dcce), @@ -506,7 +506,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, if (lws_fi(&wsi->fic, "conn_cb_rej") || user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_CONNECTING, wsi->user_space, - (void *)(intptr_t)wsi->desc.sockfd, 0)) { + (void *)(intptr_t)wsi->desc.u.sockfd, 0)) { lwsl_wsi_info(wsi, "CONNECTION CB closed"); goto failed1; } @@ -524,7 +524,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, m = -1; else #endif - m = connect(wsi->desc.sockfd, (const struct sockaddr *)psa, + m = connect(wsi->desc.u.sockfd, (const struct sockaddr *)psa, (socklen_t)n); #if defined(LWS_WITH_CONMON) @@ -549,7 +549,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, #endif lwsl_wsi_debug(wsi, "connect: fd %d, %s", - wsi->desc.sockfd, + wsi->desc.u.sockfd, lws_errno_describe(errno_copy, t16, sizeof(t16))); if (errno_copy && @@ -649,7 +649,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, #if defined(_DEBUG) char buf[64]; #endif - if (getsockname((int)wsi->desc.sockfd, + if (getsockname((int)wsi->desc.u.sockfd, (struct sockaddr *)&wsi->sa46_local, &salen) == -1) { en = LWS_ERRNO; @@ -692,7 +692,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, lws_inform_client_conn_fail(wsi,(void *)cce, strlen(cce)); /* take care that we might be inserted in fds already */ - if (wsi->position_in_fds_table != LWS_NO_FDS_POS) + if (wsi->desc.pos_in_fds_table != LWS_NO_FDS_POS) /* do the full wsi close flow */ goto failed1; @@ -707,7 +707,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, */ { struct lws_vhost *vhost = wsi->a.vhost; - lws_sockfd_type sfd = wsi->desc.sockfd; + lws_sockfd_type sfd = wsi->desc.u.sockfd; //lws_vhost_lock(vhost); __lws_free_wsi(wsi); /* acquires vhost lock in wsi reset */ @@ -734,8 +734,8 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, /* * We are killing the socket but leaving */ - compatible_close(wsi->desc.sockfd); - wsi->desc.sockfd = LWS_SOCK_INVALID; + compatible_close(wsi->desc.u.sockfd); + wsi->desc.u.sockfd = LWS_SOCK_INVALID; try_next_dns_result: lws_sul_cancel(&wsi->sul_connect_timeout); diff --git a/lib/core-net/client/connect4.c b/lib/core-net/client/connect4.c index c34d2253be..c4dcde19e3 100644 --- a/lib/core-net/client/connect4.c +++ b/lib/core-net/client/connect4.c @@ -95,7 +95,7 @@ lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback, goto failed; wsi->c_port = (uint16_t)wsi->a.vhost->http.http_proxy_port; - n = (int)send(wsi->desc.sockfd, (char *)pt->serv_buf, + n = (int)send(wsi->desc.u.sockfd, (char *)pt->serv_buf, (unsigned int)plen, MSG_NOSIGNAL); if (n < 0) { @@ -272,9 +272,9 @@ lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback, PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, (int)wsi->a.context->timeout_secs); - assert(lws_socket_is_valid(wsi->desc.sockfd)); + assert(lws_socket_is_valid(wsi->desc.u.sockfd)); - pfd.fd = wsi->desc.sockfd; + pfd.fd = wsi->desc.u.sockfd; pfd.events = LWS_POLLIN; pfd.revents = LWS_POLLOUT; @@ -312,9 +312,9 @@ lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback, lws_set_timeout(wsi, PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, (int)wsi->a.context->timeout_secs); - assert(lws_socket_is_valid(wsi->desc.sockfd)); + assert(lws_socket_is_valid(wsi->desc.u.sockfd)); - pfd.fd = wsi->desc.sockfd; + pfd.fd = wsi->desc.u.sockfd; pfd.events = LWS_POLLIN; pfd.revents = LWS_POLLIN; diff --git a/lib/core-net/close.c b/lib/core-net/close.c index 4bc34031d2..d0d8f97fce 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -561,14 +561,14 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, lws_rops_func_fidx(wsi->role_ops, LWS_ROPS_close_via_role_protocol). close_via_role_protocol(wsi, reason)) { lwsl_wsi_info(wsi, "close_via_role took over (sockfd %d)", - wsi->desc.sockfd); + wsi->desc.u.sockfd); return; } just_kill_connection: lwsl_wsi_debug(wsi, "real just_kill_connection A: (sockfd %d)", - wsi->desc.sockfd); + wsi->desc.u.sockfd); #if defined(LWS_WITH_THREADPOOL) && defined(LWS_HAVE_PTHREAD_H) lws_threadpool_wsi_closing(wsi); @@ -671,12 +671,12 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, #endif { lwsl_info("%s: shutdown conn: %s (sk %d, state 0x%x)\n", - __func__, lws_wsi_tag(wsi), (int)(lws_intptr_t)wsi->desc.sockfd, + __func__, lws_wsi_tag(wsi), (int)(lws_intptr_t)wsi->desc.u.sockfd, lwsi_state(wsi)); if (!wsi->socket_is_permanently_unusable && - lws_socket_is_valid(wsi->desc.sockfd)) { + lws_socket_is_valid(wsi->desc.u.sockfd)) { wsi->socket_is_permanently_unusable = 1; - n = shutdown(wsi->desc.sockfd, SHUT_WR); + n = shutdown(wsi->desc.u.sockfd, SHUT_WR); } } if (n) @@ -693,7 +693,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, #if defined(LWS_WITH_CLIENT) !wsi->close_is_redirect && #endif - lws_socket_is_valid(wsi->desc.sockfd) && + lws_socket_is_valid(wsi->desc.u.sockfd) && lwsi_state(wsi) != LRS_SHUTDOWN && (context->event_loop_ops->flags & LELOF_ISPOLL)) { __lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN); @@ -707,7 +707,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, } lwsl_wsi_info(wsi, "real just_kill_connection: sockfd %d\n", - wsi->desc.sockfd); + wsi->desc.u.sockfd); #ifdef LWS_WITH_HUBBUB if (wsi->http.rw) { @@ -888,21 +888,21 @@ __lws_close_free_wsi_final(struct lws *wsi) int n; if (!wsi->shadow && - lws_socket_is_valid(wsi->desc.sockfd) && !lws_ssl_close(wsi)) { - lwsl_wsi_debug(wsi, "fd %d", wsi->desc.sockfd); - n = compatible_close(wsi->desc.sockfd); + lws_socket_is_valid(wsi->desc.u.sockfd) && !lws_ssl_close(wsi)) { + lwsl_wsi_debug(wsi, "fd %d", wsi->desc.u.sockfd); + n = compatible_close(wsi->desc.u.sockfd); if (n) lwsl_wsi_debug(wsi, "closing: close ret %d", LWS_ERRNO); __remove_wsi_socket_from_fds(wsi); - if (lws_socket_is_valid(wsi->desc.sockfd)) - delete_from_fd(wsi->a.context, wsi->desc.sockfd); + if (lws_socket_is_valid(wsi->desc.u.sockfd)) + delete_from_fd(wsi->a.context, wsi->desc.u.sockfd); #if !defined(LWS_PLAT_FREERTOS) && !defined(WIN32) && !defined(LWS_PLAT_OPTEE) delete_from_fdwsi(wsi->a.context, wsi); #endif - sanity_assert_no_sockfd_traces(wsi->a.context, wsi->desc.sockfd); + sanity_assert_no_sockfd_traces(wsi->a.context, wsi->desc.u.sockfd); } /* ... if we're closing the cancel pipe, account for it */ @@ -913,11 +913,11 @@ __lws_close_free_wsi_final(struct lws *wsi) if (pt->pipe_wsi == wsi) pt->pipe_wsi = NULL; - if (pt->dummy_pipe_fds[0] == wsi->desc.sockfd) + if (pt->dummy_pipe_fds[0] == wsi->desc.u.sockfd) pt->dummy_pipe_fds[0] = LWS_SOCK_INVALID; } - wsi->desc.sockfd = LWS_SOCK_INVALID; + wsi->desc.u.sockfd = LWS_SOCK_INVALID; #if defined(LWS_WITH_CLIENT) lws_free_set_NULL(wsi->cli_hostname_copy); diff --git a/lib/core-net/dummy-callback.c b/lib/core-net/dummy-callback.c index d36000fa73..8c0ab3a023 100644 --- a/lib/core-net/dummy-callback.c +++ b/lib/core-net/dummy-callback.c @@ -765,7 +765,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, sizeof(wsi->http.cgi->inflate_buf)) { int written; - written = (int)write(args->stdwsi[LWS_STDIN]->desc.filefd, + written = (int)write(args->stdwsi[LWS_STDIN]->desc.u.filefd, wsi->http.cgi->inflate_buf, sizeof(wsi->http.cgi->inflate_buf) - wsi->http.cgi->inflate.avail_out); @@ -808,7 +808,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, lwsl_wsi_info(wsi, "proxied %d bytes", n); if (wsi->http.cgi->post_in_expected && args->stdwsi[LWS_STDIN] && - args->stdwsi[LWS_STDIN]->desc.filefd > 0) { + args->stdwsi[LWS_STDIN]->desc.u.filefd > 0) { wsi->http.cgi->post_in_expected -= (unsigned int)n; if (!wsi->http.cgi->post_in_expected) { @@ -824,7 +824,7 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, lwsl_wsi_info(siwsi, "expected POST in end: " "closing stdin fd %d", - siwsi->desc.sockfd); + siwsi->desc.u.sockfd); /* * We don't want the child / parent relationship diff --git a/lib/core-net/network.c b/lib/core-net/network.c index f276a28dd9..2452b032c3 100644 --- a/lib/core-net/network.c +++ b/lib/core-net/network.c @@ -208,7 +208,7 @@ const char * lws_get_peer_simple(struct lws *wsi, char *name, size_t namelen) { wsi = lws_get_network_wsi(wsi); - return lws_get_peer_simple_fd(wsi->desc.sockfd, name, namelen); + return lws_get_peer_simple_fd(wsi->desc.u.sockfd, name, namelen); } #endif diff --git a/lib/core-net/output.c b/lib/core-net/output.c index 911688e4d6..51330271da 100644 --- a/lib/core-net/output.c +++ b/lib/core-net/output.c @@ -82,7 +82,7 @@ lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) if (!len || !buf) return 0; - if (!wsi->mux_substream && !lws_socket_is_valid(wsi->desc.sockfd)) + if (!wsi->mux_substream && !lws_socket_is_valid(wsi->desc.u.sockfd)) lwsl_wsi_err(wsi, "invalid sock"); /* limit sending */ @@ -253,7 +253,7 @@ lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, size_t len) if (lws_wsi_is_udp(wsi)) { socklen_t slt = sizeof(wsi->udp->sa46); - n = (int)recvfrom(wsi->desc.sockfd, (char *)buf, + n = (int)recvfrom(wsi->desc.u.sockfd, (char *)buf, #if defined(WIN32) (int) #endif @@ -261,7 +261,7 @@ lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, size_t len) sa46_sockaddr(&wsi->udp->sa46), &slt); } else #endif - n = (int)recv(wsi->desc.sockfd, (char *)buf, + n = (int)recv(wsi->desc.u.sockfd, (char *)buf, #if defined(WIN32) (int) #endif @@ -322,14 +322,14 @@ lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, size_t len) } if (lws_has_buffered_out(wsi)) - n = (int)sendto(wsi->desc.sockfd, (const char *)buf, + n = (int)sendto(wsi->desc.u.sockfd, (const char *)buf, #if defined(WIN32) (int) #endif len, 0, sa46_sockaddr(&wsi->udp->sa46_pending), sa46_socklen(&wsi->udp->sa46_pending)); else - n = (int)sendto(wsi->desc.sockfd, (const char *)buf, + n = (int)sendto(wsi->desc.u.sockfd, (const char *)buf, #if defined(WIN32) (int) #endif @@ -338,13 +338,13 @@ lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, size_t len) } else #endif if (wsi->role_ops->file_handle) - n = (int)write((int)(lws_intptr_t)wsi->desc.filefd, buf, + n = (int)write((int)(lws_intptr_t)wsi->desc.u.filefd, buf, #if defined(WIN32) (int) #endif len); else - n = (int)send(wsi->desc.sockfd, (char *)buf, + n = (int)send(wsi->desc.u.sockfd, (char *)buf, #if defined(WIN32) (int) #endif @@ -368,7 +368,7 @@ lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, size_t len) } lwsl_wsi_debug(wsi, "ERROR writing len %d to skt fd %d err %d / errno %d", - (int)(ssize_t)len, wsi->desc.sockfd, n, LWS_ERRNO); + (int)(ssize_t)len, wsi->desc.u.sockfd, n, LWS_ERRNO); return LWS_SSL_CAPABLE_ERROR; } diff --git a/lib/core-net/pollfd.c b/lib/core-net/pollfd.c index dea85aec02..1dca59fdb8 100644 --- a/lib/core-net/pollfd.c +++ b/lib/core-net/pollfd.c @@ -39,10 +39,10 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa) if (!wsi) return 0; - assert(wsi->position_in_fds_table == LWS_NO_FDS_POS || - wsi->position_in_fds_table >= 0); + assert(wsi->desc.pos_in_fds_table == LWS_NO_FDS_POS || + wsi->desc.pos_in_fds_table >= 0); - if (wsi->position_in_fds_table == LWS_NO_FDS_POS) + if (wsi->desc.pos_in_fds_table == LWS_NO_FDS_POS) return 0; if (((volatile struct lws *)wsi)->handling_pollout && @@ -69,7 +69,7 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa) context = wsi->a.context; pt = &context->pt[(int)wsi->tsi]; - assert(wsi->position_in_fds_table < (int)pt->fds_count); + assert(wsi->desc.pos_in_fds_table < (int)pt->fds_count); #if !defined(LWS_WITH_EVENT_LIBS) /* @@ -112,7 +112,7 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa) ftp->_and = _and; ftp->_or = _or; - ftp->fd_index = wsi->position_in_fds_table; + ftp->fd_index = wsi->desc.pos_in_fds_table; ftp->next = NULL; lws_pt_lock(pt, __func__); @@ -145,8 +145,8 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa) _or |= LWS_POLLHUP; #endif - pfd = &pt->fds[wsi->position_in_fds_table]; - pa->fd = wsi->desc.sockfd; + pfd = &pt->fds[wsi->desc.pos_in_fds_table]; + pa->fd = wsi->desc.u.sockfd; lwsl_wsi_debug(wsi, "fd %d events %d -> %d", pa->fd, pfd->events, (pfd->events & ~_and) | _or); pa->prev_events = pfd->events; @@ -257,7 +257,7 @@ __dump_fds(struct lws_context_per_thread *pt, const char *s) lwsl_cx_warn(pt->context, " %d: fd %d, wsi %s, pos_in_fds: %d", n + 1, pt->fds[n].fd, lws_wsi_tag(wsi), - wsi ? wsi->position_in_fds_table : -1); + (int)(wsi ? wsi->desc.pos_in_fds_table : -1)); } } #else @@ -268,7 +268,7 @@ int __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi) { #if defined(LWS_WITH_EXTERNAL_POLL) - struct lws_pollargs pa = { wsi->desc.sockfd, LWS_POLLIN, 0 }; + struct lws_pollargs pa = { wsi->desc.u.sockfd, LWS_POLLIN, 0 }; #endif struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; int ret = 0; @@ -278,7 +278,7 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi) lws_pt_assert_lock_held(pt); lwsl_wsi_debug(wsi, "tsi=%d, sock=%d, pos-in-fds=%d", - wsi->tsi, wsi->desc.sockfd, pt->fds_count); + wsi->tsi, wsi->desc.u.sockfd, pt->fds_count); if ((unsigned int)pt->fds_count >= context->fd_limit_per_thread) { lwsl_cx_err(context, "Too many fds (%d vs %d)", context->max_fds, @@ -288,9 +288,9 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi) #if !defined(_WIN32) if (!wsi->a.context->max_fds_unrelated_to_ulimit && - wsi->desc.sockfd - lws_plat_socket_offset() >= (int)context->max_fds) { + wsi->desc.u.sockfd - lws_plat_socket_offset() >= (int)context->max_fds) { lwsl_cx_err(context, "Socket fd %d is too high (%d) offset %d", - wsi->desc.sockfd, context->max_fds, + wsi->desc.u.sockfd, context->max_fds, lws_plat_socket_offset()); return 1; } @@ -303,7 +303,7 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi) #else assert(wsi->event_pipe || wsi->a.vhost); #endif - assert(lws_socket_is_valid(wsi->desc.sockfd)); + assert(lws_socket_is_valid(wsi->desc.u.sockfd)); #if defined(LWS_WITH_EXTERNAL_POLL) @@ -316,10 +316,10 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi) if (insert_wsi(context, wsi)) return -1; pt->count_conns++; - wsi->position_in_fds_table = (int)pt->fds_count; + wsi->desc.pos_in_fds_table = (int)pt->fds_count; - pt->fds[wsi->position_in_fds_table].fd = wsi->desc.sockfd; - pt->fds[wsi->position_in_fds_table].events = LWS_POLLIN; + pt->fds[wsi->desc.pos_in_fds_table].fd = wsi->desc.u.sockfd; + pt->fds[wsi->desc.pos_in_fds_table].events = LWS_POLLIN; #if defined(LWS_WITH_EXTERNAL_POLL) pa.events = pt->fds[pt->fds_count].events; #endif @@ -359,7 +359,7 @@ __remove_wsi_socket_from_fds(struct lws *wsi) { struct lws_context *context = wsi->a.context; #if defined(LWS_WITH_EXTERNAL_POLL) - struct lws_pollargs pa = { wsi->desc.sockfd, 0, 0 }; + struct lws_pollargs pa = { wsi->desc.u.sockfd, 0, 0 }; #endif struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; struct lws *end_wsi; @@ -371,9 +371,9 @@ __remove_wsi_socket_from_fds(struct lws *wsi) #if !defined(_WIN32) if (!wsi->a.context->max_fds_unrelated_to_ulimit && - wsi->desc.sockfd - lws_plat_socket_offset() > (int)context->max_fds) { + wsi->desc.u.sockfd - lws_plat_socket_offset() > (int)context->max_fds) { lwsl_wsi_err(wsi, "fd %d too high (%d)", - wsi->desc.sockfd, + wsi->desc.u.sockfd, context->max_fds); return 1; @@ -389,9 +389,9 @@ __remove_wsi_socket_from_fds(struct lws *wsi) __lws_same_vh_protocol_remove(wsi); /* the guy who is to be deleted's slot index in pt->fds */ - m = wsi->position_in_fds_table; + m = wsi->desc.pos_in_fds_table; - /* these are the only valid possibilities for position_in_fds_table */ + /* these are the only valid possibilities for pos_in_fds_table */ assert(m == LWS_NO_FDS_POS || (m >= 0 && (unsigned int)m < pt->fds_count)); if (context->event_loop_ops->io) @@ -399,7 +399,7 @@ __remove_wsi_socket_from_fds(struct lws *wsi) LWS_EV_WRITE); /* lwsl_notice("%s: wsi=%s, skt=%d, fds pos=%d, end guy pos=%d, endfd=%d\n", - __func__, lws_wsi_tag(wsi), wsi->desc.sockfd, wsi->position_in_fds_table, + __func__, lws_wsi_tag(wsi), wsi->desc.u.sockfd, wsi->desc.pos_in_fds_table, pt->fds_count, pt->fds[pt->fds_count - 1].fd); */ if (m != LWS_NO_FDS_POS) { @@ -408,7 +408,7 @@ __remove_wsi_socket_from_fds(struct lws *wsi) assert(pt->fds_count && (unsigned int)m != pt->fds_count); /* deletion guy's lws_lookup entry needs nuking */ - delete_from_fd(context, wsi->desc.sockfd); + delete_from_fd(context, wsi->desc.u.sockfd); if ((unsigned int)m != pt->fds_count - 1) { /* have the last guy take up the now vacant slot */ @@ -433,15 +433,15 @@ __remove_wsi_socket_from_fds(struct lws *wsi) pt->fds_count); // assert(0); } else - end_wsi->position_in_fds_table = m; + end_wsi->desc.pos_in_fds_table = m; } /* removed wsi has no position any more */ - wsi->position_in_fds_table = LWS_NO_FDS_POS; + wsi->desc.pos_in_fds_table = LWS_NO_FDS_POS; #if defined(LWS_WITH_EXTERNAL_POLL) /* remove also from external POLL support via protocol 0 */ - if (lws_socket_is_valid(wsi->desc.sockfd) && wsi->a.vhost && + if (lws_socket_is_valid(wsi->desc.u.sockfd) && wsi->a.vhost && wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_DEL_POLL_FD, wsi->user_space, @@ -477,7 +477,7 @@ __lws_change_pollfd(struct lws *wsi, int _and, int _or) int ret = 0; if (!wsi || (!wsi->a.protocol && !wsi->event_pipe) || - wsi->position_in_fds_table == LWS_NO_FDS_POS) + wsi->desc.pos_in_fds_table == LWS_NO_FDS_POS) return 0; context = lws_get_context(wsi); @@ -537,9 +537,9 @@ lws_callback_on_writable(struct lws *wsi) return 1; w = lws_get_network_wsi(wsi); } else - if (w->position_in_fds_table == LWS_NO_FDS_POS) { + if (w->desc.pos_in_fds_table == LWS_NO_FDS_POS) { lwsl_wsi_debug(wsi, "failed to find socket %d", - wsi->desc.sockfd); + wsi->desc.u.sockfd); return -1; } diff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h index 5dbd097d38..4e41c0620e 100644 --- a/lib/core-net/private-lib-core-net.h +++ b/lib/core-net/private-lib-core-net.h @@ -657,10 +657,6 @@ struct lws { /* lifetime members */ -#if defined(LWS_WITH_EVENT_LIBS) - void *evlib_wsi; /* overallocated */ -#endif - lws_sorted_usec_list_t sul_timeout; lws_sorted_usec_list_t sul_hrtimer; lws_sorted_usec_list_t sul_validity; @@ -746,14 +742,12 @@ struct lws { char alpn[24]; #endif - lws_sock_file_fd_type desc; /* .filefd / .sockfd */ + lws_desc_t desc; /* .filefd / .sockfd */ lws_wsi_state_t wsistate; lws_wsi_state_t wsistate_pre_close; /* ints */ -#define LWS_NO_FDS_POS (-1) - int position_in_fds_table; #if defined(LWS_WITH_CLIENT) int chunk_remaining; diff --git a/lib/core-net/route.c b/lib/core-net/route.c index c9fdc2ba29..d3fbe712ff 100644 --- a/lib/core-net/route.c +++ b/lib/core-net/route.c @@ -305,7 +305,7 @@ _lws_route_check_wsi(struct lws *wsi) wsi->unix_skt || wsi->sa46_peer.sa4.sin_family == AF_UNIX || #endif - wsi->desc.sockfd == LWS_SOCK_INVALID) + wsi->desc.u.sockfd == LWS_SOCK_INVALID) /* not a socket, cannot judge by route, or not connected, * leave it alone */ return 0; /* OK */ @@ -390,7 +390,7 @@ _lws_route_pt_close_route_users(struct lws_context_per_thread *pt, if (!wsi) continue; - if (wsi->desc.sockfd != LWS_SOCK_INVALID && + if (wsi->desc.u.sockfd != LWS_SOCK_INVALID && #if defined(LWS_WITH_UNIX_SOCK) !wsi->unix_skt && wsi->sa46_peer.sa4.sin_family != AF_UNIX && diff --git a/lib/core-net/service.c b/lib/core-net/service.c index 02e4c05e2a..c0b8516bf0 100644 --- a/lib/core-net/service.c +++ b/lib/core-net/service.c @@ -610,13 +610,13 @@ lws_service_flag_pending(struct lws_context *context, int tsi) struct lws *wsi = lws_container_of(p, struct lws, tls.dll_pending_tls); - if (wsi->position_in_fds_table >= 0) { + if (wsi->desc.pos_in_fds_table >= 0) { - pt->fds[wsi->position_in_fds_table].revents = (short)( - pt->fds[wsi->position_in_fds_table].revents | - (pt->fds[wsi->position_in_fds_table].events & + pt->fds[wsi->desc.pos_in_fds_table].revents = (short)( + pt->fds[wsi->desc.pos_in_fds_table].revents | + (pt->fds[wsi->desc.pos_in_fds_table].events & LWS_POLLIN)); - if (pt->fds[wsi->position_in_fds_table].revents & + if (pt->fds[wsi->desc.pos_in_fds_table].revents & LWS_POLLIN) /* * We're not going to remove the wsi from the diff --git a/lib/core-net/socks5-client.c b/lib/core-net/socks5-client.c index 4d7572a129..45b882a514 100644 --- a/lib/core-net/socks5-client.c +++ b/lib/core-net/socks5-client.c @@ -235,7 +235,7 @@ lws_socks5c_greet(struct lws *wsi, const char **pcce) return -1; } // lwsl_hexdump_notice(pt->serv_buf, plen); - n = (int)send(wsi->desc.sockfd, (char *)pt->serv_buf, (size_t)plen, + n = (int)send(wsi->desc.u.sockfd, (char *)pt->serv_buf, (size_t)plen, MSG_NOSIGNAL); if (n < 0) { lwsl_wsi_debug(wsi, "ERROR writing socks greeting"); @@ -268,7 +268,7 @@ lws_socks5c_handle_state(struct lws *wsi, struct lws_pollfd *pollfd, return LW5CHS_RET_BAIL3; } - n = (int)recv(wsi->desc.sockfd, (void *)pt->serv_buf, + n = (int)recv(wsi->desc.u.sockfd, (void *)pt->serv_buf, wsi->a.context->pt_serv_buf_size, 0); if (n < 0) { if (LWS_ERRNO == LWS_EAGAIN) { @@ -331,7 +331,7 @@ lws_socks5c_handle_state(struct lws *wsi, struct lws_pollfd *pollfd, PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY; socks_send: // lwsl_hexdump_notice(pt->serv_buf, len); - n = (int)send(wsi->desc.sockfd, (char *)pt->serv_buf, + n = (int)send(wsi->desc.u.sockfd, (char *)pt->serv_buf, (size_t)len, MSG_NOSIGNAL); if (n < 0) { lwsl_wsi_debug(wsi, "ERROR writing to socks proxy"); diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index 74db74f14a..91f5c3d7e7 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -1158,8 +1158,8 @@ __lws_create_event_pipes(struct lws_context *context) * etc. */ - wsi->desc.sockfd = context->pt[n].dummy_pipe_fds[0]; - // lwsl_debug("event pipe fd %d\n", wsi->desc.sockfd); + wsi->desc.u.sockfd = context->pt[n].dummy_pipe_fds[0]; + // lwsl_debug("event pipe fd %d\n", wsi->desc.u.sockfd); if (lws_wsi_inject_to_loop(pt, wsi)) goto bail; diff --git a/lib/core-net/wsi.c b/lib/core-net/wsi.c index 978d1e80c6..89fdfe0773 100644 --- a/lib/core-net/wsi.c +++ b/lib/core-net/wsi.c @@ -314,7 +314,7 @@ __lws_wsi_create_with_role(struct lws_context *context, int tsi, wsi->lc.log_cx = context->log_cx; #if defined(LWS_WITH_EVENT_LIBS) - wsi->evlib_wsi = (uint8_t *)wsi + sizeof(*wsi); + wsi->desc.evlib_desc = (uint8_t *)wsi + sizeof(*wsi); #endif wsi->a.context = context; lws_role_transition(wsi, 0, LRS_UNCONNECTED, ops); @@ -322,8 +322,8 @@ __lws_wsi_create_with_role(struct lws_context *context, int tsi, wsi->a.protocol = NULL; wsi->tsi = (char)tsi; wsi->a.vhost = NULL; - wsi->desc.sockfd = LWS_SOCK_INVALID; - wsi->position_in_fds_table = LWS_NO_FDS_POS; + wsi->desc.u.sockfd = LWS_SOCK_INVALID; + wsi->desc.pos_in_fds_table = LWS_NO_FDS_POS; #if defined(LWS_WITH_SYS_FAULT_INJECTION) lws_xos_init(&wsi->fic.xos, lws_xos(&context->fic.xos)); @@ -363,14 +363,14 @@ lws_wsi_inject_to_loop(struct lws_context_per_thread *pt, struct lws *wsi) } /* - * Take a copy of wsi->desc.sockfd before calling this, then close it + * Take a copy of wsi->desc.u.sockfd before calling this, then close it * afterwards */ int lws_wsi_extract_from_loop(struct lws *wsi) { - if (lws_socket_is_valid(wsi->desc.sockfd)) + if (lws_socket_is_valid(wsi->desc.u.sockfd)) __remove_wsi_socket_from_fds(wsi); if (!wsi->a.context->event_loop_ops->destroy_wsi && @@ -979,7 +979,7 @@ lws_get_socket_fd(struct lws *wsi) { if (!wsi) return -1; - return wsi->desc.sockfd; + return wsi->desc.u.sockfd; } @@ -1084,14 +1084,14 @@ _lws_generic_transaction_completed_active_conn(struct lws **_wsi, char take_vh_l lws_dll2_remove(&wnew->dll2_cli_txn_queue); - assert(lws_socket_is_valid(wsi->desc.sockfd)); + assert(lws_socket_is_valid(wsi->desc.u.sockfd)); __lws_change_pollfd(wsi, LWS_POLLOUT | LWS_POLLIN, 0); /* copy the fd */ wnew->desc = wsi->desc; - assert(lws_socket_is_valid(wnew->desc.sockfd)); + assert(lws_socket_is_valid(wnew->desc.u.sockfd)); /* disconnect the fd from association with old wsi */ @@ -1099,8 +1099,8 @@ _lws_generic_transaction_completed_active_conn(struct lws **_wsi, char take_vh_l return -1; sanity_assert_no_wsi_traces(wsi->a.context, wsi); - sanity_assert_no_sockfd_traces(wsi->a.context, wsi->desc.sockfd); - wsi->desc.sockfd = LWS_SOCK_INVALID; + sanity_assert_no_sockfd_traces(wsi->a.context, wsi->desc.u.sockfd); + wsi->desc.u.sockfd = LWS_SOCK_INVALID; __lws_wsi_remove_from_sul(wsi); @@ -1120,7 +1120,7 @@ _lws_generic_transaction_completed_active_conn(struct lws **_wsi, char take_vh_l /* point the fd table entry to new guy */ - assert(lws_socket_is_valid(wnew->desc.sockfd)); + assert(lws_socket_is_valid(wnew->desc.u.sockfd)); if (__insert_wsi_socket_into_fds(wsi->a.context, wnew)) return -1; diff --git a/lib/event-libs/README.md b/lib/event-libs/README.md index 5d49bec1f9..f0805abf02 100644 --- a/lib/event-libs/README.md +++ b/lib/event-libs/README.md @@ -133,14 +133,14 @@ being created to point at the over-allocation. For example for the wsi ``` #if defined(LWS_WITH_EVENT_LIBS) - void *evlib_wsi; /* overallocated */ + void *evlib_desc; /* overallocated */ #endif ``` and similarly there are `evlib_pt` and so on for those objects, usable by the event lib and opaque to everyone else. Once the event lib is selected at runtime, all of these objects are guaranteed to have the right size object at -`wsi->evlib_wsi` initialized to zeroes. +`wsi->evlib_desc` initialized to zeroes. ### Enabling event lib adoption diff --git a/lib/event-libs/glib/glib.c b/lib/event-libs/glib/glib.c index 14c779e150..a2fa39bbfc 100644 --- a/lib/event-libs/glib/glib.c +++ b/lib/event-libs/glib/glib.c @@ -33,7 +33,7 @@ #endif #define pt_to_priv_glib(_pt) ((struct lws_pt_eventlibs_glib *)(_pt)->evlib_pt) -#define wsi_to_priv_glib(_w) ((struct lws_wsi_eventlibs_glib *)(_w)->evlib_wsi) +#define wsi_to_priv_glib(_w) ((struct lws_wsi_eventlibs_glib *)(_w)->desc.evlib_desc) #define wsi_to_subclass(_w) (wsi_to_priv_glib(_w)->w_read.source) #define wsi_to_gsource(_w) ((GSource *)wsi_to_subclass(_w)) @@ -130,7 +130,7 @@ lws_glib_dispatch(GSource *src, GSourceFunc x, gpointer userData) eventfd.revents |= LWS_POLLHUP; eventfd.events = eventfd.revents; - eventfd.fd = sub->wsi->desc.sockfd; + eventfd.fd = sub->wsi->desc.u.sockfd; lwsl_wsi_debug(sub->wsi, "fd %d, events %d", eventfd.fd, eventfd.revents); @@ -277,9 +277,9 @@ elops_accept_glib(struct lws *wsi) wsi_to_subclass(wsi)->wsi = wsi; if (wsi->role_ops->file_handle) - fd = wsi->desc.filefd; + fd = wsi->desc.u.filefd; else - fd = wsi->desc.sockfd; + fd = wsi->desc.u.sockfd; wsi_to_subclass(wsi)->tag = g_source_add_unix_fd(wsi_to_gsource(wsi), fd, (GIOCondition)LWS_POLLIN); @@ -377,7 +377,7 @@ elops_io_glib(struct lws *wsi, unsigned int flags) wsipr->w_read.actual_events = (uint8_t)cond; - lwsl_wsi_debug(wsi, "fd %d, 0x%x/0x%x", wsi->desc.sockfd, + lwsl_wsi_debug(wsi, "fd %d, 0x%x/0x%x", wsi->desc.u.sockfd, flags, (int)cond); g_source_modify_unix_fd(wsi_to_gsource(wsi), wsi_to_subclass(wsi)->tag, diff --git a/lib/event-libs/libev/libev.c b/lib/event-libs/libev/libev.c index 4bdede78da..c8cd12e5ba 100644 --- a/lib/event-libs/libev/libev.c +++ b/lib/event-libs/libev/libev.c @@ -27,7 +27,7 @@ #define pt_to_priv_ev(_pt) ((struct lws_pt_eventlibs_libev *)(_pt)->evlib_pt) #define vh_to_priv_ev(_vh) ((struct lws_vh_eventlibs_libev *)(_vh)->evlib_vh) -#define wsi_to_priv_ev(_w) ((struct lws_wsi_eventlibs_libev *)(_w)->evlib_wsi) +#define wsi_to_priv_ev(_w) ((struct lws_wsi_eventlibs_libev *)(_w)->desc.evlib_desc) static void lws_ev_hrtimer_cb(struct ev_loop *loop, struct ev_timer *watcher, int revents) @@ -148,7 +148,7 @@ elops_listen_init_ev(struct lws_dll2 *d, void *user) vh_to_priv_ev(vh)->w_accept.context = context; ev_io_init(&vh_to_priv_ev(vh)->w_accept.watcher, - lws_accept_cb, wsi->desc.sockfd, EV_READ); + lws_accept_cb, wsi->desc.u.sockfd, EV_READ); ev_io_start(ptpr->io_loop, &vh_to_priv_ev(vh)->w_accept.watcher); return 0; @@ -289,9 +289,9 @@ elops_accept_ev(struct lws *wsi) int fd; if (wsi->role_ops->file_handle) - fd = wsi->desc.filefd; + fd = wsi->desc.u.filefd; else - fd = wsi->desc.sockfd; + fd = wsi->desc.u.sockfd; w->w_read.context = wsi->a.context; w->w_write.context = wsi->a.context; @@ -390,9 +390,9 @@ elops_init_vhost_listen_wsi_ev(struct lws *wsi) w->w_write.context = wsi->a.context; if (wsi->role_ops->file_handle) - fd = wsi->desc.filefd; + fd = wsi->desc.u.filefd; else - fd = wsi->desc.sockfd; + fd = wsi->desc.u.sockfd; ev_io_init(&w->w_read.watcher, lws_accept_cb, fd, EV_READ); //ev_io_init(&w->w_write.watcher, lws_accept_cb, fd, EV_WRITE); diff --git a/lib/event-libs/libevent/libevent.c b/lib/event-libs/libevent/libevent.c index b7b310ca7c..25a64b494c 100644 --- a/lib/event-libs/libevent/libevent.c +++ b/lib/event-libs/libevent/libevent.c @@ -26,7 +26,7 @@ #include "private-lib-event-libs-libevent.h" #define pt_to_priv_event(_pt) ((struct lws_pt_eventlibs_libevent *)(_pt)->evlib_pt) -#define wsi_to_priv_event(_w) ((struct lws_wsi_eventlibs_libevent *)(_w)->evlib_wsi) +#define wsi_to_priv_event(_w) ((struct lws_wsi_eventlibs_libevent *)(_w)->desc.evlib_desc) static void lws_event_hrtimer_cb(evutil_socket_t fd, short event, void *p) @@ -184,7 +184,7 @@ elops_listen_init_event(struct lws_dll2 *d, void *user) &(wsi_to_priv_event(wsi)->w_read); w_read->context = context; - w_read->watcher = event_new(ptpr->io_loop, wsi->desc.sockfd, + w_read->watcher = event_new(ptpr->io_loop, wsi->desc.u.sockfd, (EV_READ | EV_PERSIST), lws_event_cb, w_read); event_add(w_read->watcher, NULL); w_read->set = 1; @@ -273,9 +273,9 @@ elops_accept_event(struct lws *wsi) ptpr = pt_to_priv_event(pt); if (wsi->role_ops->file_handle) - fd = (evutil_socket_t)(ev_intptr_t) wsi->desc.filefd; + fd = (evutil_socket_t)(ev_intptr_t) wsi->desc.u.filefd; else - fd = wsi->desc.sockfd; + fd = wsi->desc.u.sockfd; wpr->w_read.watcher = event_new(ptpr->io_loop, fd, (EV_READ | EV_PERSIST), lws_event_cb, &wpr->w_read); @@ -425,9 +425,9 @@ elops_init_vhost_listen_wsi_event(struct lws *wsi) ptpr = pt_to_priv_event(pt); if (wsi->role_ops->file_handle) - fd = (evutil_socket_t) wsi->desc.filefd; + fd = (evutil_socket_t) wsi->desc.u.filefd; else - fd = wsi->desc.sockfd; + fd = wsi->desc.u.sockfd; w->w_read.watcher = event_new(ptpr->io_loop, fd, (EV_READ | EV_PERSIST), lws_event_cb, &w->w_read); diff --git a/lib/event-libs/libuv/libuv.c b/lib/event-libs/libuv/libuv.c index dad371aac3..6da82bcaa5 100644 --- a/lib/event-libs/libuv/libuv.c +++ b/lib/event-libs/libuv/libuv.c @@ -26,7 +26,7 @@ #include "private-lib-event-libs-libuv.h" #define pt_to_priv_uv(_pt) ((struct lws_pt_eventlibs_libuv *)(_pt)->evlib_pt) -#define wsi_to_priv_uv(_w) ((struct lws_wsi_eventlibs_libuv *)(_w)->evlib_wsi) +#define wsi_to_priv_uv(_w) ((struct lws_wsi_eventlibs_libuv *)(_w)->desc.evlib_desc) static void lws_uv_sultimer_cb(uv_timer_t *timer @@ -423,7 +423,7 @@ elops_destroy_context2_uv(struct lws_context *context) static int elops_wsi_logical_close_uv(struct lws *wsi) { - if (!lws_socket_is_valid(wsi->desc.sockfd) && + if (!lws_socket_is_valid(wsi->desc.u.sockfd) && wsi->role_ops && strcmp(wsi->role_ops->name, "raw-file") && !wsi_to_priv_uv(wsi)->w_read.pwatcher) return 0; @@ -476,14 +476,14 @@ elops_close_handle_manually_uv(struct lws *wsi) * the "manual" variant only closes the handle itself and the * related fd. handle->data is the fd. */ - h->data = (void *)(lws_intptr_t)wsi->desc.sockfd; + h->data = (void *)(lws_intptr_t)wsi->desc.u.sockfd; /* * We take responsibility to close / destroy these now. * Remove any trace from the wsi. */ - wsi->desc.sockfd = LWS_SOCK_INVALID; + wsi->desc.u.sockfd = LWS_SOCK_INVALID; wsi_to_priv_uv(wsi)->w_read.pwatcher = NULL; wsi->told_event_loop_closed = 1; @@ -512,14 +512,14 @@ elops_accept_uv(struct lws *wsi) if (wsi->role_ops->file_handle) n = uv_poll_init(pt_to_priv_uv(pt)->io_loop, w_read->pwatcher, - (int)(lws_intptr_t)wsi->desc.filefd); + (int)(lws_intptr_t)wsi->desc.u.filefd); else n = uv_poll_init_socket(pt_to_priv_uv(pt)->io_loop, - w_read->pwatcher, wsi->desc.sockfd); + w_read->pwatcher, wsi->desc.u.sockfd); if (n) { lwsl_wsi_err(wsi, "uv_poll_init failed %d, sockfd=%p", n, - (void *)(lws_intptr_t)wsi->desc.sockfd); + (void *)(lws_intptr_t)wsi->desc.u.sockfd); lws_free(w_read->pwatcher); w_read->pwatcher = NULL; return -1; @@ -617,10 +617,10 @@ elops_init_vhost_listen_wsi_uv(struct lws *wsi) return -1; n = uv_poll_init_socket(pt_to_priv_uv(pt)->io_loop, - w_read->pwatcher, wsi->desc.sockfd); + w_read->pwatcher, wsi->desc.u.sockfd); if (n) { lwsl_wsi_err(wsi, "uv_poll_init failed %d, sockfd=%p", n, - (void *)(lws_intptr_t)wsi->desc.sockfd); + (void *)(lws_intptr_t)wsi->desc.u.sockfd); return -1; } diff --git a/lib/event-libs/sdevent/sdevent.c b/lib/event-libs/sdevent/sdevent.c index 0c7ddaec89..79f42922d9 100644 --- a/lib/event-libs/sdevent/sdevent.c +++ b/lib/event-libs/sdevent/sdevent.c @@ -4,7 +4,7 @@ #include "private-lib-event-libs-sdevent.h" #define pt_to_priv_sd(_pt) ((struct lws_pt_eventlibs_sdevent *)(_pt)->evlib_pt) -#define wsi_to_priv_sd(_w) ((struct lws_wsi_watcher_sdevent *)(_w)->evlib_wsi) +#define wsi_to_priv_sd(_w) ((struct lws_wsi_watcher_sdevent *)(_w)->desc.evlib_desc) struct lws_pt_eventlibs_sdevent { struct lws_context_per_thread *pt; @@ -221,7 +221,7 @@ init_vhost_listen_wsi_sd(struct lws *wsi) sd_event_add_io(pt_to_priv_sd(pt)->io_loop, &wsi_to_priv_sd(wsi)->source, - wsi->desc.sockfd, + wsi->desc.u.sockfd, wsi_to_priv_sd(wsi)->events, sock_accept_handler, wsi); @@ -340,14 +340,14 @@ sock_accept_sd(struct lws *wsi) if (wsi->role_ops->file_handle) sd_event_add_io(pt_to_priv_sd(pt)->io_loop, &wsi_to_priv_sd(wsi)->source, - wsi->desc.filefd, + wsi->desc.u.filefd, wsi_to_priv_sd(wsi)->events, sock_accept_handler, wsi); else sd_event_add_io(pt_to_priv_sd(pt)->io_loop, &wsi_to_priv_sd(wsi)->source, - wsi->desc.sockfd, + wsi->desc.u.sockfd, wsi_to_priv_sd(wsi)->events, sock_accept_handler, wsi); diff --git a/lib/event-libs/uloop/uloop.c b/lib/event-libs/uloop/uloop.c index be9046c757..4aa05971e3 100644 --- a/lib/event-libs/uloop/uloop.c +++ b/lib/event-libs/uloop/uloop.c @@ -26,7 +26,7 @@ #include "private-lib-event-libs-uloop.h" #define pt_to_priv_uloop(_pt) ((struct lws_pt_eventlibs_uloop *)(_pt)->evlib_pt) -#define wsi_to_priv_uloop(_w) ((struct lws_wsi_eventlibs_uloop *)(_w)->evlib_wsi) +#define wsi_to_priv_uloop(_w) ((struct lws_wsi_eventlibs_uloop *)(_w)->desc.evlib_desc) static void lws_uloop_hrtimer_cb(struct uloop_timeout *ti) @@ -101,7 +101,7 @@ lws_uloop_cb(struct uloop_fd *ufd, unsigned int revents) struct lws_context_per_thread *pt; struct lws_pollfd eventfd; - eventfd.fd = wu->wsi->desc.sockfd; + eventfd.fd = wu->wsi->desc.u.sockfd; eventfd.events = 0; eventfd.revents = 0; @@ -139,7 +139,7 @@ elops_listen_init_uloop(struct lws_dll2 *d, void *user) struct lws_wsi_eventlibs_uloop *wu = wsi_to_priv_uloop(wsi); wu->wsi = wsi; - wu->fd.fd = wsi->desc.sockfd; + wu->fd.fd = wsi->desc.u.sockfd; wu->fd.cb = lws_uloop_cb; uloop_fd_add(&wu->fd, ULOOP_READ); wu->actual_events = ULOOP_READ; @@ -176,7 +176,7 @@ elops_accept_uloop(struct lws *wsi) struct lws_wsi_eventlibs_uloop *wu = wsi_to_priv_uloop(wsi); wu->wsi = wsi; - wu->fd.fd = wsi->desc.sockfd; + wu->fd.fd = wsi->desc.u.sockfd; wu->fd.cb = lws_uloop_cb; uloop_fd_add(&wu->fd, ULOOP_READ); wu->actual_events = ULOOP_READ; @@ -272,7 +272,7 @@ elops_init_vhost_listen_wsi_uloop(struct lws *wsi) wu = wsi_to_priv_uloop(wsi); wu->wsi = wsi; - wu->fd.fd = wsi->desc.sockfd; + wu->fd.fd = wsi->desc.u.sockfd; wu->fd.cb = lws_uloop_cb; uloop_fd_add(&wu->fd, ULOOP_READ); diff --git a/lib/plat/freertos/freertos-fds.c b/lib/plat/freertos/freertos-fds.c index a638309603..7ecf6036cd 100644 --- a/lib/plat/freertos/freertos-fds.c +++ b/lib/plat/freertos/freertos-fds.c @@ -51,10 +51,10 @@ lws_plat_change_pollfd(struct lws_context *context, int insert_wsi(const struct lws_context *context, struct lws *wsi) { - assert(context->lws_lookup[wsi->desc.sockfd - + assert(context->lws_lookup[wsi->desc.u.sockfd - lws_plat_socket_offset()] == 0); - context->lws_lookup[wsi->desc.sockfd - \ + context->lws_lookup[wsi->desc.u.sockfd - \ lws_plat_socket_offset()] = wsi; return 0; diff --git a/lib/plat/freertos/freertos-sockets.c b/lib/plat/freertos/freertos-sockets.c index 56d80069c2..8773a4257c 100644 --- a/lib/plat/freertos/freertos-sockets.c +++ b/lib/plat/freertos/freertos-sockets.c @@ -56,9 +56,9 @@ lws_send_pipe_choked(struct lws *wsi) return 1; FD_ZERO(&writefds); - FD_SET(wsi_eff->desc.sockfd, &writefds); + FD_SET(wsi_eff->desc.u.sockfd, &writefds); - n = select(wsi_eff->desc.sockfd + 1, NULL, &writefds, NULL, &tv); + n = select(wsi_eff->desc.u.sockfd + 1, NULL, &writefds, NULL, &tv); if (n < 0) return 1; /* choked */ diff --git a/lib/plat/optee/private-lib-plat-optee.h b/lib/plat/optee/private-lib-plat-optee.h index 9fb570fa05..4f0bf70736 100644 --- a/lib/plat/optee/private-lib-plat-optee.h +++ b/lib/plat/optee/private-lib-plat-optee.h @@ -42,9 +42,9 @@ #define compatible_close(x) close(x) #define lws_plat_socket_offset() (0) #define wsi_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] -#define insert_wsi(A,B) assert(A->lws_lookup[B->desc.sockfd - \ +#define insert_wsi(A,B) assert(A->lws_lookup[B->desc.u.sockfd - \ lws_plat_socket_offset()] == 0); \ - A->lws_lookup[B->desc.sockfd - \ + A->lws_lookup[B->desc.u.sockfd - \ lws_plat_socket_offset()] = B #define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 diff --git a/lib/plat/unix/unix-fds.c b/lib/plat/unix/unix-fds.c index d6cd64d2ed..4039b56ff0 100644 --- a/lib/plat/unix/unix-fds.c +++ b/lib/plat/unix/unix-fds.c @@ -41,7 +41,7 @@ wsi_from_fd(const struct lws_context *context, int fd) done = &p[context->max_fds]; while (p != done) { - if (*p && (*p)->desc.sockfd == fd) + if (*p && (*p)->desc.u.sockfd == fd) return *p; p++; } @@ -106,7 +106,7 @@ sanity_assert_no_sockfd_traces(const struct lws_context *context, /* confirm the sfd not already in use */ - while (p != done && (!*p || (*p)->desc.sockfd != sfd)) + while (p != done && (!*p || (*p)->desc.u.sockfd != sfd)) p++; if (p == done) @@ -129,10 +129,10 @@ insert_wsi(const struct lws_context *context, struct lws *wsi) return 0; if (!context->max_fds_unrelated_to_ulimit) { - assert(context->lws_lookup[wsi->desc.sockfd - + assert(context->lws_lookup[wsi->desc.u.sockfd - lws_plat_socket_offset()] == 0); - context->lws_lookup[wsi->desc.sockfd - \ + context->lws_lookup[wsi->desc.u.sockfd - \ lws_plat_socket_offset()] = wsi; return 0; @@ -145,7 +145,7 @@ insert_wsi(const struct lws_context *context, struct lws *wsi) /* confirm fd isn't already in use by a wsi */ - if (sanity_assert_no_sockfd_traces(context, wsi->desc.sockfd)) + if (sanity_assert_no_sockfd_traces(context, wsi->desc.u.sockfd)) return 0; p = context->lws_lookup; @@ -189,7 +189,7 @@ delete_from_fd(const struct lws_context *context, int fd) /* find the match */ - while (p != done && (!*p || (*p)->desc.sockfd != fd)) + while (p != done && (!*p || (*p)->desc.u.sockfd != fd)) p++; if (p != done) @@ -197,7 +197,7 @@ delete_from_fd(const struct lws_context *context, int fd) #if defined(_DEBUG) p = context->lws_lookup; - while (p != done && (!*p || (*p)->desc.sockfd != fd)) + while (p != done && (!*p || (*p)->desc.u.sockfd != fd)) p++; if (p != done) { diff --git a/lib/plat/unix/unix-sockets.c b/lib/plat/unix/unix-sockets.c index f259a4a8e5..cad0d3646c 100644 --- a/lib/plat/unix/unix-sockets.c +++ b/lib/plat/unix/unix-sockets.c @@ -77,7 +77,7 @@ lws_send_pipe_choked(struct lws *wsi) ) return 1; - fds.fd = wsi_eff->desc.sockfd; + fds.fd = wsi_eff->desc.u.sockfd; fds.events = POLLOUT; fds.revents = 0; diff --git a/lib/plat/unix/unix-spawn.c b/lib/plat/unix/unix-spawn.c index 1c68d45bf6..37ae90332b 100644 --- a/lib/plat/unix/unix-spawn.c +++ b/lib/plat/unix/unix-spawn.c @@ -396,7 +396,7 @@ lws_spawn_piped(const struct lws_spawn_piped_info *i) /* read side is 0, stdin we want the write side, others read */ - lsp->stdwsi[n]->desc.sockfd = lsp->pipe_fds[n][n == 0]; + lsp->stdwsi[n]->desc.u.sockfd = lsp->pipe_fds[n][n == 0]; if (fcntl(lsp->pipe_fds[n][n == 0], F_SETFL, O_NONBLOCK) < 0) { lwsl_err("%s: setting NONBLOCK failed\n", __func__); goto bail2; @@ -438,9 +438,9 @@ lws_spawn_piped(const struct lws_spawn_piped_info *i) goto bail3; lwsl_info("%s: fds in %d, out %d, err %d\n", __func__, - lsp->stdwsi[LWS_STDIN]->desc.sockfd, - lsp->stdwsi[LWS_STDOUT]->desc.sockfd, - lsp->stdwsi[LWS_STDERR]->desc.sockfd); + lsp->stdwsi[LWS_STDIN]->desc.u.sockfd, + lsp->stdwsi[LWS_STDOUT]->desc.u.sockfd, + lsp->stdwsi[LWS_STDERR]->desc.u.sockfd); /* we are ready with the redirection pipes... do the (v)fork */ #if defined(__sun) || !defined(LWS_HAVE_VFORK) || !defined(LWS_HAVE_EXECVPE) diff --git a/lib/plat/windows/windows-fds.c b/lib/plat/windows/windows-fds.c index 05a6620874..e2457c8baa 100644 --- a/lib/plat/windows/windows-fds.c +++ b/lib/plat/windows/windows-fds.c @@ -34,7 +34,7 @@ wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd) int n = 0; for (n = 0; n < context->fd_hashtable[h].length; n++) - if (context->fd_hashtable[h].wsi[n]->desc.sockfd == fd) + if (context->fd_hashtable[h].wsi[n]->desc.u.sockfd == fd) return context->fd_hashtable[h].wsi[n]; return NULL; @@ -43,7 +43,7 @@ wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd) int insert_wsi(struct lws_context *context, struct lws *wsi) { - int h = LWS_FD_HASH(wsi->desc.sockfd); + int h = LWS_FD_HASH(wsi->desc.u.sockfd); if (context->fd_hashtable[h].length == (getdtablesize() - 1)) { lwsl_err("hash table overflow\n"); @@ -62,7 +62,7 @@ delete_from_fd(struct lws_context *context, lws_sockfd_type fd) int n = 0; for (n = 0; n < context->fd_hashtable[h].length; n++) - if (context->fd_hashtable[h].wsi[n]->desc.sockfd == fd) { + if (context->fd_hashtable[h].wsi[n]->desc.u.sockfd == fd) { while (n < context->fd_hashtable[h].length) { context->fd_hashtable[h].wsi[n] = context->fd_hashtable[h].wsi[n + 1]; diff --git a/lib/plat/windows/windows-sockets.c b/lib/plat/windows/windows-sockets.c index 9e8ce26560..397b4270a3 100644 --- a/lib/plat/windows/windows-sockets.c +++ b/lib/plat/windows/windows-sockets.c @@ -265,7 +265,7 @@ lws_plat_check_connection_error(struct lws *wsi) int optVal; int optLen = sizeof(int); - if (getsockopt(wsi->desc.sockfd, SOL_SOCKET, SO_ERROR, + if (getsockopt(wsi->desc.u.sockfd, SOL_SOCKET, SO_ERROR, (char*)&optVal, &optLen) != SOCKET_ERROR && optVal && optVal != LWS_EALREADY && optVal != LWS_EINPROGRESS && optVal != LWS_EWOULDBLOCK && optVal != WSAEINVAL) { diff --git a/lib/plat/windows/windows-spawn.c b/lib/plat/windows/windows-spawn.c index a7c0322e38..66227e2a91 100644 --- a/lib/plat/windows/windows-spawn.c +++ b/lib/plat/windows/windows-spawn.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2020 Andy Green + * Copyright (C) 2010 - 2022 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -92,7 +92,7 @@ lws_create_basic_wsi(struct lws_context *context, int tsi, lws_role_transition(new_wsi, 0, LRS_ESTABLISHED, ops); new_wsi->hdr_parsing_completed = 0; - new_wsi->position_in_fds_table = LWS_NO_FDS_POS; + new_wsi->desc.pos_in_fds_table = LWS_NO_FDS_POS; /* * these can only be set once the protocol is known @@ -102,7 +102,7 @@ lws_create_basic_wsi(struct lws_context *context, int tsi, */ new_wsi->user_space = NULL; - new_wsi->desc.sockfd = LWS_SOCK_INVALID; + new_wsi->desc.u.sockfd = LWS_SOCK_INVALID; return new_wsi; } @@ -127,7 +127,7 @@ lws_spawn_piped_destroy(struct lws_spawn_piped **_lsp) if (lsp->stdwsi[n]) { lwsl_notice("%s: closing stdwsi %d\n", __func__, n); wsi = lsp->stdwsi[n]; - lsp->stdwsi[n]->desc.filefd = NULL; + lsp->stdwsi[n]->desc.u.filefd = NULL; lsp->stdwsi[n] = NULL; lws_set_timeout(wsi, 1, LWS_TO_KILL_SYNC); } @@ -270,18 +270,18 @@ windows_pipe_poll_hack(lws_sorted_usec_list_t *sul) NULL, NULL)) { lwsl_notice("%s: stdout pipe errored\n", __func__); - CloseHandle(lsp->stdwsi[LWS_STDOUT]->desc.filefd); + CloseHandle(lsp->stdwsi[LWS_STDOUT]->desc.u.filefd); lsp->pipe_fds[LWS_STDOUT][0] = NULL; - lsp->stdwsi[LWS_STDOUT]->desc.filefd = NULL; + lsp->stdwsi[LWS_STDOUT]->desc.u.filefd = NULL; lsp->stdwsi[LWS_STDOUT] = NULL; lws_set_timeout(wsi, 1, LWS_TO_KILL_SYNC); if (lsp->stdwsi[LWS_STDIN]) { lwsl_notice("%s: closing stdin from stdout close\n", __func__); - CloseHandle(lsp->stdwsi[LWS_STDIN]->desc.filefd); + CloseHandle(lsp->stdwsi[LWS_STDIN]->desc.u.filefd); wsi = lsp->stdwsi[LWS_STDIN]; - lsp->stdwsi[LWS_STDIN]->desc.filefd = NULL; + lsp->stdwsi[LWS_STDIN]->desc.u.filefd = NULL; lsp->stdwsi[LWS_STDIN] = NULL; lsp->pipe_fds[LWS_STDIN][1] = NULL; lws_set_timeout(wsi, 1, LWS_TO_KILL_SYNC); @@ -309,12 +309,12 @@ windows_pipe_poll_hack(lws_sorted_usec_list_t *sul) NULL, NULL)) { lwsl_notice("%s: stderr pipe errored\n", __func__); - CloseHandle(wsi1->desc.filefd); + CloseHandle(wsi1->desc.u.filefd); /* * Assume is stderr still extant on entry, lsp can't * have been destroyed by stdout/stdin processing */ - lsp->stdwsi[LWS_STDERR]->desc.filefd = NULL; + lsp->stdwsi[LWS_STDERR]->desc.u.filefd = NULL; lsp->stdwsi[LWS_STDERR] = NULL; lsp->pipe_fds[LWS_STDERR][0] = NULL; lws_set_timeout(wsi1, 1, LWS_TO_KILL_SYNC); @@ -423,7 +423,7 @@ lws_spawn_piped(const struct lws_spawn_piped_info *i) lsp->stdwsi[n]->a.protocol = pcol; lsp->stdwsi[n]->a.opaque_user_data = i->opaque; - lsp->stdwsi[n]->desc.filefd = lsp->pipe_fds[n][!n]; + lsp->stdwsi[n]->desc.u.filefd = lsp->pipe_fds[n][!n]; lsp->stdwsi[n]->file_desc = 1; lwsl_debug("%s: lsp stdwsi %p: pipe idx %d -> fd %d / %d\n", @@ -435,7 +435,7 @@ lws_spawn_piped(const struct lws_spawn_piped_info *i) /* read side is 0, stdin we want the write side, others read */ - lsp->stdwsi[n]->desc.filefd = lsp->pipe_fds[n][!!(n == 0)]; + lsp->stdwsi[n]->desc.u.filefd = lsp->pipe_fds[n][!!(n == 0)]; if (fcntl(lsp->pipe_fds[n][!!(n == 0)], F_SETFL, O_NONBLOCK) < 0) { lwsl_err("%s: setting NONBLOCK failed\n", __func__); goto bail2; @@ -451,9 +451,9 @@ lws_spawn_piped(const struct lws_spawn_piped_info *i) } lwsl_notice("%s: pipe handles in %p, out %p, err %p\n", __func__, - lsp->stdwsi[LWS_STDIN]->desc.sockfd, - lsp->stdwsi[LWS_STDOUT]->desc.sockfd, - lsp->stdwsi[LWS_STDERR]->desc.sockfd); + lsp->stdwsi[LWS_STDIN]->desc.u.sockfd, + lsp->stdwsi[LWS_STDOUT]->desc.u.sockfd, + lsp->stdwsi[LWS_STDERR]->desc.u.sockfd); /* * Windows nonblocking pipe handling is a mess that is unable diff --git a/lib/roles/dbus/dbus.c b/lib/roles/dbus/dbus.c index 34457925f8..c6a1e20abc 100644 --- a/lib/roles/dbus/dbus.c +++ b/lib/roles/dbus/dbus.c @@ -81,7 +81,7 @@ __lws_shadow_wsi(struct lws_dbus_ctx *ctx, DBusWatch *w, int fd, int create_ok) lwsl_info("%s: creating shadow wsi\n", __func__); - wsi->desc.sockfd = fd; + wsi->desc.u.sockfd = fd; lws_role_transition(wsi, 0, LRS_ESTABLISHED, &role_ops_dbus); wsi->a.protocol = ctx->vh->protocols; wsi->shadow = 1; @@ -116,7 +116,7 @@ __lws_shadow_wsi_destroy(struct lws_dbus_ctx *ctx, struct lws *wsi) if (__remove_wsi_socket_from_fds(wsi)) { lwsl_err("%s: unable to remove %d from fds\n", __func__, - wsi->desc.sockfd); + wsi->desc.u.sockfd); return 1; } diff --git a/lib/roles/h2/http2.c b/lib/roles/h2/http2.c index 50cdccec43..d9cd59c311 100644 --- a/lib/roles/h2/http2.c +++ b/lib/roles/h2/http2.c @@ -399,7 +399,7 @@ lws_h2_issue_preface(struct lws *wsi) if (h2n->sent_preface) return 1; - lwsl_debug("%s: %s: fd %d\n", __func__, lws_wsi_tag(wsi), (int)wsi->desc.sockfd); + lwsl_debug("%s: %s: fd %d\n", __func__, lws_wsi_tag(wsi), (int)wsi->desc.u.sockfd); if (lws_issue_raw(wsi, (uint8_t *)preface, strlen(preface)) != (int)strlen(preface)) diff --git a/lib/roles/http/client/client-http.c b/lib/roles/http/client/client-http.c index 465b4f0fd7..a9c1fcd75e 100644 --- a/lib/roles/http/client/client-http.c +++ b/lib/roles/http/client/client-http.c @@ -107,7 +107,7 @@ lws_http_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) goto bail3; } - n = (int)recv(wsi->desc.sockfd, sb, context->pt_serv_buf_size, 0); + n = (int)recv(wsi->desc.u.sockfd, sb, context->pt_serv_buf_size, 0); if (n < 0) { if (LWS_ERRNO == LWS_EAGAIN) { lwsl_debug("Proxy read EAGAIN... retrying\n"); @@ -278,7 +278,7 @@ lws_http_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) lwsl_info("%s: HANDSHAKE2: %s: sending headers " "(wsistate 0x%lx), w sock %d\n", __func__, lws_wsi_tag(wsi), - (unsigned long)wsi->wsistate, wsi->desc.sockfd); + (unsigned long)wsi->wsistate, wsi->desc.u.sockfd); n = lws_ssl_capable_write(wsi, (unsigned char *)sb, lws_ptr_diff_size_t(p, sb)); switch (n) { diff --git a/lib/roles/http/parsers.c b/lib/roles/http/parsers.c index 220f9cf821..d593d3a7dd 100644 --- a/lib/roles/http/parsers.c +++ b/lib/roles/http/parsers.c @@ -128,7 +128,7 @@ __lws_header_table_reset(struct lws *wsi, int autoservice) time(&ah->assigned); - if (wsi->position_in_fds_table != LWS_NO_FDS_POS && + if (wsi->desc.pos_in_fds_table != LWS_NO_FDS_POS && lws_buflist_next_segment_len(&wsi->buflist, NULL) && autoservice) { lwsl_debug("%s: service on readbuf ah\n", __func__); @@ -138,7 +138,7 @@ __lws_header_table_reset(struct lws *wsi, int autoservice) * Unlike a normal connect, we have the headers already * (or the first part of them anyway) */ - pfd = &pt->fds[wsi->position_in_fds_table]; + pfd = &pt->fds[wsi->desc.pos_in_fds_table]; pfd->revents |= LWS_POLLIN; lwsl_err("%s: calling service\n", __func__); lws_service_fd_tsi(wsi->a.context, pfd, wsi->tsi); @@ -396,7 +396,7 @@ int __lws_header_table_detach(struct lws *wsi, int autoservice) #endif /* clients acquire the ah and then insert themselves in fds table... */ - if (wsi->position_in_fds_table != LWS_NO_FDS_POS) { + if (wsi->desc.pos_in_fds_table != LWS_NO_FDS_POS) { lwsl_info("%s: Enabling %s POLLIN\n", __func__, lws_wsi_tag(wsi)); /* he has been stuck waiting for an ah, but now his wait is diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index b93fb861f0..21d7613777 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -319,7 +319,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a) lwsl_debug("%s: lws_socket_bind says %d\n", __func__, is); } - wsi->desc.sockfd = sockfd; + wsi->desc.u.sockfd = sockfd; wsi->a.protocol = a->vhost->protocols; lws_vhost_bind_wsi(a->vhost, wsi); wsi->listener = 1; @@ -342,7 +342,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a) #if defined(WIN32) && defined(TCP_FASTOPEN) if (a->vhost->fo_listen_queue) { int optval = 1; - if (setsockopt(wsi->desc.sockfd, IPPROTO_TCP, + if (setsockopt(wsi->desc.u.sockfd, IPPROTO_TCP, TCP_FASTOPEN, (const char*)&optval, sizeof(optval)) < 0) { int error = LWS_ERRNO; @@ -355,14 +355,14 @@ _lws_vhost_init_server_af(struct vh_sock_args *a) if (a->vhost->fo_listen_queue) { int qlen = a->vhost->fo_listen_queue; - if (setsockopt(wsi->desc.sockfd, SOL_TCP, TCP_FASTOPEN, + if (setsockopt(wsi->desc.u.sockfd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen))) lwsl_warn("%s: TCP_FASTOPEN failed\n", __func__); } #endif #endif - n = listen(wsi->desc.sockfd, LWS_SOMAXCONN); + n = listen(wsi->desc.u.sockfd, LWS_SOMAXCONN); if (n < 0) { lwsl_err("listen failed with error %d\n", LWS_ERRNO); lws_dll2_remove(&wsi->listen_list); diff --git a/lib/roles/listen/ops-listen.c b/lib/roles/listen/ops-listen.c index a4bbaa3ce1..cdcea19e7f 100644 --- a/lib/roles/listen/ops-listen.c +++ b/lib/roles/listen/ops-listen.c @@ -166,8 +166,8 @@ rops_handle_POLLIN_listen(struct lws_context_per_thread *pt, struct lws *wsi, */ } while (pt->fds_count < context->fd_limit_per_thread - 1 && - wsi->position_in_fds_table != LWS_NO_FDS_POS && - lws_poll_listen_fd(&pt->fds[wsi->position_in_fds_table]) > 0); + wsi->desc.pos_in_fds_table != LWS_NO_FDS_POS && + lws_poll_listen_fd(&pt->fds[wsi->desc.pos_in_fds_table]) > 0); return LWS_HPI_RET_HANDLED; } diff --git a/lib/roles/netlink/ops-netlink.c b/lib/roles/netlink/ops-netlink.c index fa3bf29a2f..da8b5d134b 100644 --- a/lib/roles/netlink/ops-netlink.c +++ b/lib/roles/netlink/ops-netlink.c @@ -90,7 +90,7 @@ rops_handle_POLLIN_netlink(struct lws_context_per_thread *pt, struct lws *wsi, msg.msg_iov = &iov; msg.msg_iovlen = 1; - n = (unsigned int)recvmsg(wsi->desc.sockfd, &msg, 0); + n = (unsigned int)recvmsg(wsi->desc.u.sockfd, &msg, 0); if ((int)n < 0) { lwsl_cx_notice(cx, "recvmsg failed"); return LWS_HPI_RET_PLEASE_CLOSE_ME; @@ -513,13 +513,13 @@ rops_pt_init_destroy_netlink(struct lws_context *context, if (!wsi) goto bail; - wsi->desc.sockfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); - if (wsi->desc.sockfd == LWS_SOCK_INVALID) { + wsi->desc.u.sockfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + if (wsi->desc.u.sockfd == LWS_SOCK_INVALID) { lwsl_cx_err(context, "unable to open netlink"); goto bail1; } - lws_plat_set_nonblocking(wsi->desc.sockfd); + lws_plat_set_nonblocking(wsi->desc.u.sockfd); __lws_lc_tag(context, &context->lcg[LWSLCG_VHOST], &wsi->lc, "netlink"); @@ -534,7 +534,7 @@ rops_pt_init_destroy_netlink(struct lws_context *context, ; if (lws_fi(&context->fic, "netlink_bind") || - bind(wsi->desc.sockfd, (struct sockaddr*)&sanl, sizeof(sanl)) < 0) { + bind(wsi->desc.u.sockfd, (struct sockaddr*)&sanl, sizeof(sanl)) < 0) { lwsl_cx_warn(context, "netlink bind failed"); ret = 0; /* some systems deny access, just ignore */ goto bail2; @@ -577,7 +577,7 @@ rops_pt_init_destroy_netlink(struct lws_context *context, msg.msg_name = &sanl; msg.msg_namelen = sizeof(sanl); - n = (int)sendmsg(wsi->desc.sockfd, (struct msghdr *)&msg, 0); + n = (int)sendmsg(wsi->desc.u.sockfd, (struct msghdr *)&msg, 0); if (n < 0) { lwsl_cx_notice(context, "rt dump req failed... permissions? errno %d", LWS_ERRNO); @@ -596,7 +596,7 @@ rops_pt_init_destroy_netlink(struct lws_context *context, bail2: __lws_lc_untag(wsi->a.context, &wsi->lc); - compatible_close(wsi->desc.sockfd); + compatible_close(wsi->desc.u.sockfd); bail1: lws_free(wsi); bail: diff --git a/lib/roles/pipe/ops-pipe.c b/lib/roles/pipe/ops-pipe.c index ad54a04fa9..a492856adb 100644 --- a/lib/roles/pipe/ops-pipe.c +++ b/lib/roles/pipe/ops-pipe.c @@ -32,10 +32,10 @@ rops_handle_POLLIN_pipe(struct lws_context_per_thread *pt, struct lws *wsi, eventfd_t value; int n; - n = eventfd_read(wsi->desc.sockfd, &value); + n = eventfd_read(wsi->desc.u.sockfd, &value); if (n < 0) { lwsl_notice("%s: eventfd read %d bailed errno %d\n", __func__, - wsi->desc.sockfd, LWS_ERRNO); + wsi->desc.u.sockfd, LWS_ERRNO); return LWS_HPI_RET_PLEASE_CLOSE_ME; } #elif !defined(WIN32) && !defined(_WIN32) @@ -47,7 +47,7 @@ rops_handle_POLLIN_pipe(struct lws_context_per_thread *pt, struct lws *wsi, * We really don't care about the number of bytes, but coverity * thinks we should. */ - n = (int)read(wsi->desc.sockfd, s, sizeof(s)); + n = (int)read(wsi->desc.u.sockfd, s, sizeof(s)); (void)n; if (n < 0) return LWS_HPI_RET_PLEASE_CLOSE_ME; @@ -55,7 +55,7 @@ rops_handle_POLLIN_pipe(struct lws_context_per_thread *pt, struct lws *wsi, char s[100]; int n; - n = recv(wsi->desc.sockfd, s, sizeof(s), 0); + n = recv(wsi->desc.u.sockfd, s, sizeof(s), 0); if (n == SOCKET_ERROR) return LWS_HPI_RET_PLEASE_CLOSE_ME; #endif diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index 37fbd34dcd..fe567c6bed 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -1478,11 +1478,11 @@ rops_service_flag_pending_ws(struct lws_context *context, int tsi) * not flowcontrolled, fake their POLLIN status */ wsi = pt->ws.rx_draining_ext_list; - while (wsi && wsi->position_in_fds_table != LWS_NO_FDS_POS) { - pt->fds[wsi->position_in_fds_table].revents = - (short)((short)pt->fds[wsi->position_in_fds_table].revents | - (short)(pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN)); - if (pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN) + while (wsi && wsi->desc.pos_in_fds_table != LWS_NO_FDS_POS) { + pt->fds[wsi->desc.pos_in_fds_table].revents = + (short)((short)pt->fds[wsi->desc.pos_in_fds_table].revents | + (short)(pt->fds[wsi->desc.pos_in_fds_table].events & LWS_POLLIN)); + if (pt->fds[wsi->desc.pos_in_fds_table].revents & LWS_POLLIN) forced = 1; wsi = wsi->ws->rx_draining_ext_list; diff --git a/lib/system/dhcpclient/dhcpc4.c b/lib/system/dhcpclient/dhcpc4.c index 9d2d27f2eb..6c4308ab0f 100644 --- a/lib/system/dhcpclient/dhcpc4.c +++ b/lib/system/dhcpclient/dhcpc4.c @@ -91,7 +91,7 @@ lws_dhcpc4_prep(uint8_t *start, unsigned int bufsiz, lws_dhcpc_req_t *r, int op) p += 0x1c - 3; - if (lws_plat_ifname_to_hwaddr(r->wsi_raw->desc.sockfd, + if (lws_plat_ifname_to_hwaddr(r->wsi_raw->desc.u.sockfd, (const char *)&r[1], r->is.mac, 6) < 0) return -1; @@ -181,7 +181,7 @@ callback_dhcpc4(struct lws *wsi, enum lws_callback_reasons reason, void *user, /* set up our network interface as offered */ - if (lws_plat_ifconfig(r->wsi_raw->desc.sockfd, &r->is)) + if (lws_plat_ifconfig(r->wsi_raw->desc.u.sockfd, &r->is)) /* * Problem setting the IP... maybe something * transient like racing with NetworkManager? @@ -254,7 +254,7 @@ callback_dhcpc4(struct lws *wsi, enum lws_callback_reasons reason, void *user, m = lws_plat_rawudp_broadcast(p, rawdisc4, LWS_ARRAY_SIZE(rawdisc4), (size_t)(n + 28), - r->wsi_raw->desc.sockfd, + r->wsi_raw->desc.u.sockfd, (const char *)&r[1]); if (m < 0) lwsl_err("%s: Failed to write dhcp client req: " @@ -312,8 +312,8 @@ lws_dhcpc4_retry_conn(struct lws_sorted_usec_list *sul) } /* force the network if up */ - lws_plat_if_up((const char *)&r[1], r->wsi_raw->desc.sockfd, 0); - lws_plat_if_up((const char *)&r[1], r->wsi_raw->desc.sockfd, 1); + lws_plat_if_up((const char *)&r[1], r->wsi_raw->desc.u.sockfd, 0); + lws_plat_if_up((const char *)&r[1], r->wsi_raw->desc.u.sockfd, 1); r->wsi_raw->user_space = r; r->wsi_raw->user_space_externally_allocated = 1; diff --git a/lib/tls/mbedtls/mbedtls-client.c b/lib/tls/mbedtls/mbedtls-client.c index 187e860537..fec20c7ea5 100644 --- a/lib/tls/mbedtls/mbedtls-client.c +++ b/lib/tls/mbedtls/mbedtls-client.c @@ -166,7 +166,7 @@ lws_ssl_client_bio_create(struct lws *wsi) SSL_set_verify(wsi->tls.ssl, fl, NULL); #endif - SSL_set_fd(wsi->tls.ssl, (int)wsi->desc.sockfd); + SSL_set_fd(wsi->tls.ssl, (int)wsi->desc.u.sockfd); if (wsi->sys_tls_client_cert) { lws_system_blob_t *b = lws_system_get_blob(wsi->a.context, diff --git a/lib/tls/mbedtls/mbedtls-ssl.c b/lib/tls/mbedtls/mbedtls-ssl.c index 5fe92205a9..5a55dd5c1d 100644 --- a/lib/tls/mbedtls/mbedtls-ssl.c +++ b/lib/tls/mbedtls/mbedtls-ssl.c @@ -315,11 +315,11 @@ __lws_tls_shutdown(struct lws *wsi) { int n = SSL_shutdown(wsi->tls.ssl); - lwsl_debug("SSL_shutdown=%d for fd %d\n", n, wsi->desc.sockfd); + lwsl_debug("SSL_shutdown=%d for fd %d\n", n, wsi->desc.u.sockfd); switch (n) { case 1: /* successful completion */ - (void)shutdown(wsi->desc.sockfd, SHUT_WR); + (void)shutdown(wsi->desc.u.sockfd, SHUT_WR); return LWS_SSL_CAPABLE_DONE; case 0: /* needs a retry */ diff --git a/lib/tls/openssl/openssl-client.c b/lib/tls/openssl/openssl-client.c index f8a64f15d8..e58644c4e8 100644 --- a/lib/tls/openssl/openssl-client.c +++ b/lib/tls/openssl/openssl-client.c @@ -371,7 +371,7 @@ lws_ssl_client_bio_create(struct lws *wsi) #endif #endif /* USE_WOLFSSL */ - wsi->tls.client_bio = BIO_new_socket((int)(lws_intptr_t)wsi->desc.sockfd, + wsi->tls.client_bio = BIO_new_socket((int)(lws_intptr_t)wsi->desc.u.sockfd, BIO_NOCLOSE); SSL_set_bio(wsi->tls.ssl, wsi->tls.client_bio, wsi->tls.client_bio); diff --git a/lib/tls/openssl/openssl-ssl.c b/lib/tls/openssl/openssl-ssl.c index cf4d2b8c6e..404ad0aa62 100644 --- a/lib/tls/openssl/openssl-ssl.c +++ b/lib/tls/openssl/openssl-ssl.c @@ -541,10 +541,10 @@ __lws_tls_shutdown(struct lws *wsi) #endif ERR_clear_error(); n = SSL_shutdown(wsi->tls.ssl); - lwsl_debug("SSL_shutdown=%d for fd %d\n", n, wsi->desc.sockfd); + lwsl_debug("SSL_shutdown=%d for fd %d\n", n, wsi->desc.u.sockfd); switch (n) { case 1: /* successful completion */ - n = shutdown(wsi->desc.sockfd, SHUT_WR); + n = shutdown(wsi->desc.u.sockfd, SHUT_WR); return LWS_SSL_CAPABLE_DONE; case 0: /* needs a retry */ diff --git a/lib/tls/tls-network.c b/lib/tls/tls-network.c index 4d6ab95e7a..8419386b6a 100644 --- a/lib/tls/tls-network.c +++ b/lib/tls/tls-network.c @@ -1,7 +1,7 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2019 Andy Green + * Copyright (C) 2010 - 2022 Andy Green * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -40,12 +40,12 @@ lws_tls_fake_POLLIN_for_buffered(struct lws_context_per_thread *pt) struct lws *wsi = lws_container_of(p, struct lws, tls.dll_pending_tls); - if (wsi->position_in_fds_table >= 0) { + if (wsi->desc.pos_in_fds_table >= 0) { - pt->fds[wsi->position_in_fds_table].revents = (short) - (pt->fds[wsi->position_in_fds_table].revents | - (pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN)); - ret |= pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN; + pt->fds[wsi->desc.pos_in_fds_table].revents = (short) + (pt->fds[wsi->desc.pos_in_fds_table].revents | + (pt->fds[wsi->desc.pos_in_fds_table].events & LWS_POLLIN)); + ret |= pt->fds[wsi->desc.pos_in_fds_table].revents & LWS_POLLIN; } } lws_end_foreach_dll_safe(p, p1); diff --git a/lib/tls/tls-server.c b/lib/tls/tls-server.c index 05055f7ec0..41319f6943 100644 --- a/lib/tls/tls-server.c +++ b/lib/tls/tls-server.c @@ -191,7 +191,7 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd, char f * something to read... */ - s = recv(wsi->desc.sockfd, (char *)pt->serv_buf, + s = recv(wsi->desc.u.sockfd, (char *)pt->serv_buf, context->pt_serv_buf_size, MSG_PEEK); /* * We have LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT.. @@ -325,7 +325,7 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd, char f case LWS_SSL_CAPABLE_ERROR: lws_tls_restrict_return_handshake(wsi); lwsl_info("%s: SSL_accept failed socket %u: %d\n", - __func__, wsi->desc.sockfd, n); + __func__, wsi->desc.u.sockfd, n); wsi->socket_is_permanently_unusable = 1; goto fail;