Skip to content

Commit

Permalink
Ignore SIGPIPE if client closes connection abruptly
Browse files Browse the repository at this point in the history
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #20678)
  • Loading branch information
lord8266 authored and paulidale committed Apr 6, 2023
1 parent f06ef16 commit f309b3f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions demos/sslecho/main.c
Expand Up @@ -14,6 +14,7 @@
#include <arpa/inet.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <signal.h>

static const int server_port = 4433;

Expand Down Expand Up @@ -151,6 +152,9 @@ int main(int argc, char **argv)
struct sockaddr_in addr;
unsigned int addr_len = sizeof(addr);

/* ignore SIGPIPE so that server can continue running when client pipe closes abruptly */
signal(SIGPIPE, SIG_IGN);

/* Splash */
printf("\nsslecho : Simple Echo Client/Server (OpenSSL 3.0.1-dev) : %s : %s\n\n", __DATE__,
__TIME__);
Expand Down Expand Up @@ -218,6 +222,8 @@ int main(int argc, char **argv)
if ((rxlen = SSL_read(ssl, rxbuf, rxcap)) <= 0) {
if (rxlen == 0) {
printf("Client closed connection\n");
} else {
printf("SSL_read returned %d\n", rxlen);
}
ERR_print_errors_fp(stderr);
break;
Expand Down

0 comments on commit f309b3f

Please sign in to comment.