diff --git a/lib/core-net/close.c b/lib/core-net/close.c index 056952b5e..851ed2fba 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -905,9 +905,19 @@ __lws_close_free_wsi_final(struct lws *wsi) 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); - if (n) - lwsl_wsi_debug(wsi, "closing: close ret %d", LWS_ERRNO); + + /* + * if this is the pt pipe, skip the actual close, + * go through the motions though so we will reach 0 open wsi + * on the pt, and trigger the pt destroy to close the pipe fds + */ + if (!lws_plat_pipe_is_fd_assocated(wsi->a.context, wsi->tsi, + wsi->desc.sockfd)) { + n = compatible_close(wsi->desc.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)) diff --git a/lib/core-net/private-lib-core-net.h b/lib/core-net/private-lib-core-net.h index 500ba7457..4e2b6a266 100644 --- a/lib/core-net/private-lib-core-net.h +++ b/lib/core-net/private-lib-core-net.h @@ -1405,6 +1405,8 @@ int lws_plat_pipe_signal(struct lws_context *ctx, int tsi); void lws_plat_pipe_close(struct lws *wsi); +int +lws_plat_pipe_is_fd_assocated(struct lws_context *cx, int tsi, lws_sockfd_type fd); void lws_addrinfo_clean(struct lws *wsi); diff --git a/lib/plat/freertos/freertos-pipe.c b/lib/plat/freertos/freertos-pipe.c index e459bf0ae..476a7d7be 100644 --- a/lib/plat/freertos/freertos-pipe.c +++ b/lib/plat/freertos/freertos-pipe.c @@ -124,3 +124,11 @@ lws_plat_pipe_close(struct lws *wsi) fd[0] = fd[1] = -1; } + +int +lws_plat_pipe_is_fd_assocated(struct lws_context *cx, int tsi, lws_sockfd_type fd) +{ + struct lws_context_per_thread *pt = &cx->pt[tsi]; + + return fd == pt->dummy_pipe_fds[0] || fd == pt->dummy_pipe_fds[1]; +} diff --git a/lib/plat/optee/network.c b/lib/plat/optee/network.c index 34f152f02..871abd9c8 100644 --- a/lib/plat/optee/network.c +++ b/lib/plat/optee/network.c @@ -49,6 +49,12 @@ lws_plat_pipe_close(struct lws *wsi) { } +int +lws_plat_pipe_is_fd_assocated(struct lws_context *cx, int tsi, lws_sockfd_type fd) +{ + return 0; +} + int lws_send_pipe_choked(struct lws *wsi) { diff --git a/lib/plat/unix/unix-pipe.c b/lib/plat/unix/unix-pipe.c index ad04acbbc..cab4bb189 100644 --- a/lib/plat/unix/unix-pipe.c +++ b/lib/plat/unix/unix-pipe.c @@ -84,10 +84,20 @@ lws_plat_pipe_close(struct lws *wsi) { struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; - if (pt->dummy_pipe_fds[0] && pt->dummy_pipe_fds[0] != -1) + if (pt->dummy_pipe_fds[0] && pt->dummy_pipe_fds[0] != -1) { close(pt->dummy_pipe_fds[0]); - if (pt->dummy_pipe_fds[1] && pt->dummy_pipe_fds[1] != -1) + pt->dummy_pipe_fds[0] = -1; + } + if (pt->dummy_pipe_fds[1] && pt->dummy_pipe_fds[1] != -1) { close(pt->dummy_pipe_fds[1]); - - pt->dummy_pipe_fds[0] = pt->dummy_pipe_fds[1] = -1; + pt->dummy_pipe_fds[1] = -1; + } +} + +int +lws_plat_pipe_is_fd_assocated(struct lws_context *cx, int tsi, lws_sockfd_type fd) +{ + struct lws_context_per_thread *pt = &cx->pt[tsi]; + + return fd == pt->dummy_pipe_fds[0] || fd == pt->dummy_pipe_fds[1]; } diff --git a/lib/plat/windows/windows-pipe.c b/lib/plat/windows/windows-pipe.c index bbfa31972..702411a53 100644 --- a/lib/plat/windows/windows-pipe.c +++ b/lib/plat/windows/windows-pipe.c @@ -125,3 +125,11 @@ lws_plat_pipe_close(struct lws *wsi) pt->dummy_pipe_fds[0] = pt->dummy_pipe_fds[1] = LWS_SOCK_INVALID; } + +int +lws_plat_pipe_is_fd_assocated(struct lws_context *cx, int tsi, lws_sockfd_type fd) +{ + struct lws_context_per_thread *pt = &cx->pt[tsi]; + + return fd == pt->dummy_pipe_fds[0] || fd == pt->dummy_pipe_fds[1]; +}