From: Marco Schlumpp Date: Thu, 11 Apr 2024 14:39:22 +0000 (+0200) Subject: Indicate EPOLLRDHUP when the peer closed the connection X-Git-Tag: RELEASE-0.17.0~3 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=32a11569f0e8f291ac51c96d7b88e2b842740ca4;p=unikraft%2Flibs%2Flwip.git Indicate EPOLLRDHUP when the peer closed the connection The RDHUP event is used by nginx to reduce the amount of syscalls it has to do by knowing whether a EOF is coming up. Not setting this event will cause nginx to hang with fcgi_pass configurations. Signed-off-by: Marco Schlumpp Reviewed-by: Michalis Pappas Reviewed-by: Eduard Vintilă Reviewed-by: Maria Pană Approved-by: Razvan Deaconescu GitHub-Closes: #55 --- diff --git a/sockets.c b/sockets.c index 3af5daa..f82da50 100644 --- a/sockets.c +++ b/sockets.c @@ -45,6 +45,8 @@ #include #include #include +#include +#include static inline @@ -421,16 +423,26 @@ get_lwip_socket_events(struct lwip_sock *sock) UK_ASSERT(sock); - /* A TCP connection may be in not-connected state. Don't report it as - * readable or writeable. - */ - if ((NETCONNTYPE_GROUP(sock->conn->type) == NETCONN_TCP) && - (sock->conn->state == NETCONN_NONE) && - (!NETCONN_RECVMBOX_WAITABLE(sock->conn))) { - if (sock->errevent != 0) - events |= EPOLLERR; + if ((NETCONNTYPE_GROUP(sock->conn->type) == NETCONN_TCP)) { + /* A TCP connection may be in not-connected state. Don't report it as + * readable or writeable. + */ + if ((sock->conn->state == NETCONN_NONE) && + (!NETCONN_RECVMBOX_WAITABLE(sock->conn))) { + if (sock->errevent != 0) + events |= EPOLLERR; + + return events; + } - return events; + /* Check whether the TCP connection is in CLOSE_WAIT (= got a + * FIN packet). In that case the peer will not sent more data + * and we can tell the application that the receive buffer is + * everything we got until the EOF. + */ + if (sock->conn->pcb.tcp == NULL || + sock->conn->pcb.tcp->state == CLOSE_WAIT) + events |= EPOLLRDHUP; } if (sock->lastdata.pbuf || sock->rcvevent > 0)