This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 4824e803efa24967aed7caef6b977e78c8b2c1df Author: Marco Casaroli <[email protected]> AuthorDate: Mon Nov 2 11:13:43 2026 +0100 netutils/webserver: Do not die of SIGPIPE when a client closes. The web server sends the response with send(), and the directory listing with write(). When the client closed the connection, a send to it fails with EPIPE. A send to a stream socket whose peer is gone also raises SIGPIPE, and with CONFIG_SIG_SIGPIPE_ACTION the default action ends the server task: the server stops for all clients. Send with MSG_NOSIGNAL, also for the directory listing. The error ends only the connection, as before. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- netutils/webserver/httpd.c | 8 ++++---- netutils/webserver/httpd_dirlist.c | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/netutils/webserver/httpd.c b/netutils/webserver/httpd.c index 45e5908ba..a1d06eb0a 100644 --- a/netutils/webserver/httpd.c +++ b/netutils/webserver/httpd.c @@ -352,7 +352,7 @@ static int send_chunk(struct httpd_state *pstate, const char *buf, int len) do { httpd_dumpbuffer("Outgoing chunk", buf, len); - ret = send(pstate->ht_sockfd, buf, len, 0); + ret = send(pstate->ht_sockfd, buf, len, MSG_NOSIGNAL); if (ret < 0) { return ERROR; @@ -870,7 +870,7 @@ int httpd_send_datachunk(int sockfd, void *data, int len, bool chunked) int chunked_info_len = snprintf(chunked_info, HTTPD_MAX_CHUNKEDLEN, "%X\r\n", len); - ret = send(sockfd, chunked_info, chunked_info_len, 0); + ret = send(sockfd, chunked_info, chunked_info_len, MSG_NOSIGNAL); DEBUGASSERT(ret == chunked_info_len); } #endif @@ -886,7 +886,7 @@ int httpd_send_datachunk(int sockfd, void *data, int len, bool chunked) data = &len; } - ret = send(sockfd, data, len, 0); + ret = send(sockfd, data, len, MSG_NOSIGNAL); DEBUGASSERT(ret == len); } @@ -897,7 +897,7 @@ int httpd_send_datachunk(int sockfd, void *data, int len, bool chunked) { if (chunked) { - ret = send(sockfd, "\r\n", 2, 0); + ret = send(sockfd, "\r\n", 2, MSG_NOSIGNAL); DEBUGASSERT(ret == 2); } } diff --git a/netutils/webserver/httpd_dirlist.c b/netutils/webserver/httpd_dirlist.c index b77d68e4e..93d2d7a0a 100644 --- a/netutils/webserver/httpd_dirlist.c +++ b/netutils/webserver/httpd_dirlist.c @@ -28,6 +28,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/socket.h> #include <sys/utsname.h> #include <limits.h> #include <unistd.h> @@ -170,7 +171,7 @@ ssize_t httpd_dirlist(int outfd, FAR struct httpd_fs_file *file) path, path); } - ret = write(outfd, tmp, strlen(tmp)); + ret = send(outfd, tmp, strlen(tmp), MSG_NOSIGNAL); if (-1 == ret) { @@ -234,7 +235,7 @@ ssize_t httpd_dirlist(int outfd, FAR struct httpd_fs_file *file) ); } - ret = write(outfd, tmp, strlen(tmp)); + ret = send(outfd, tmp, strlen(tmp), MSG_NOSIGNAL); if (-1 == ret) { @@ -257,7 +258,7 @@ errout_with_hdr: info.machine, BOARD_NAME); - ret = write(outfd, tmp, strlen(tmp)); + ret = send(outfd, tmp, strlen(tmp), MSG_NOSIGNAL); if (-1 != ret) {
