1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

pipe: only pt destroy pipe close should close pipe fds

https://github.com/warmcat/libwebsockets/issues/2873
This commit is contained in:
Andy Green 2024-09-25 08:38:15 +01:00
parent 38677d36e5
commit b486c2b545
6 changed files with 51 additions and 7 deletions

View file

@ -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))

View file

@ -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);

View file

@ -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];
}

View file

@ -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)
{

View file

@ -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];
}

View file

@ -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];
}