From 0734e1a1cb7926f44c62db99eaa4fba87e94f308 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 10 Mar 2021 14:50:53 +0000 Subject: [PATCH] connect: erase previous unusability when retrying connect In the case that we try ipv6 that isn't routable, we get a POLLHUP, that marks the wsi as unusable (for writes, not pending reads), that's what we want. But in the case we go around and retry other dns results that are routable, we have to clear the wsi unusable flag. Otherwise we will connect and find that we can't write on the connection... --- lib/core-net/client/connect3.c | 2 ++ lib/core-net/service.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/core-net/client/connect3.c b/lib/core-net/client/connect3.c index ee08ffc54..311a4e79d 100644 --- a/lib/core-net/client/connect3.c +++ b/lib/core-net/client/connect3.c @@ -430,7 +430,9 @@ ads_known: lws_metrics_caliper_bind(wsi->cal_conn, wsi->a.context->mt_conn_tcp); #endif + wsi->socket_is_permanently_unusable = 0; m = connect(wsi->desc.sockfd, (const struct sockaddr *)psa, (unsigned int)n); + if (m == -1) { /* * Since we're nonblocking, connect not having completed is not diff --git a/lib/core-net/service.c b/lib/core-net/service.c index 5e0370521..6737f40bc 100644 --- a/lib/core-net/service.c +++ b/lib/core-net/service.c @@ -672,7 +672,7 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd, * is possible. */ - if (pollfd->revents & LWS_POLLHUP) { + if ((pollfd->revents & LWS_POLLHUP) == LWS_POLLHUP) { wsi->socket_is_permanently_unusable = 1; if (!(pollfd->revents & pollfd->events & LWS_POLLIN)) {