MEDIUM: connection: centralize handling of nolinger in fd management
Right now we see many places doing their own setsockopt(SO_LINGER).
Better only do it just before the close() in fd_delete(). For this
we add a new flag on the file descriptor, indicating if it's safe or
not to linger. If not (eg: after a connect()), then the setsockopt()
call is automatically performed before a close().
The flag automatically turns to safe when receiving a read0.
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 2b6fbc7..c1b0d7b 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -475,6 +475,7 @@
conn->flags |= CO_FL_SEND_PROXY;
conn_ctrl_init(conn); /* registers the FD */
+ fdtab[fd].linger_risk = 1; /* close hard if needed */
conn_sock_want_send(conn); /* for connect status */
if (conn_xprt_init(conn) < 0) {