From e5e6f2945977f551ec6958df7ab1892086551896 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Mon, 19 Feb 2024 18:56:51 +1100 Subject: tcp: Don't store errnos in socket pool If tcp_sock_refill_pool() gets an error opening new sockets, it stores the negative errno of that error in the socket pool. This isn't especially useful: * It's inconsistent with the initial state of the pool (all -1) * It's inconsistent with the state of an entry that was valid and was then consumed (also -1) * By the time we did anything with this error code, it's now far removed from the situation in which the error occurred, making it difficult to report usefully We now have error reporting closer to when failures happen on the refill paths, so just leave a pool slot we can't fill as -1. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- tcp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tcp.c b/tcp.c index 40a79b4..7be8355 100644 --- a/tcp.c +++ b/tcp.c @@ -3039,11 +3039,15 @@ int tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af) int i; for (i = 0; i < TCP_SOCK_POOL_SIZE; i++) { + int fd; + if (pool[i] >= 0) continue; - if ((pool[i] = tcp_conn_new_sock(c, af)) < 0) - return pool[i]; + if ((fd = tcp_conn_new_sock(c, af)) < 0) + return fd; + + pool[i] = fd; } return 0; -- cgit v1.2.3