Skip to content

Commit a2e42c7

Browse files
committed
net: tcp: Wake pending threads if non-blocking connect fails
If a thread was sleeping in poll(), monitoring POLLIN only, it should still be notified if an asynchronous connection, triggered by non-blocking connect(), failed. Currently that's not the case. In result the application would never know whether the connection was successful or not and would be stuck with a disconnected socket that would not report anything with poll(). This was not an issue if POLLOUT was monitored as well, because POLLOUT sets up a connect semaphore that was reset in case of errors. POLLIN however only monitors the recv fifo, which was not waken up in such case. Fix this by canceling any pending waits on recv fifo and recv condition variable. Signed-off-by: Robert Lubos <[email protected]>
1 parent e2d6af1 commit a2e42c7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

subsys/net/lib/sockets/sockets_inet.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ static void zsock_connected_cb(struct net_context *ctx, int status, void *user_d
359359
if (status < 0) {
360360
ctx->user_data = INT_TO_POINTER(-status);
361361
sock_set_error(ctx);
362+
363+
/* Wake pending threads, if any. */
364+
k_fifo_cancel_wait(&ctx->recv_q);
365+
(void)k_condvar_signal(&ctx->cond.recv);
362366
}
363367
}
364368

0 commit comments

Comments
 (0)