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:
parent
82c97d4022
commit
b05e95ec87
6 changed files with 51 additions and 7 deletions
|
@ -881,9 +881,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))
|
||||
|
|
|
@ -1326,6 +1326,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);
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue