SIGPIPE shall be ignored in most network-related cases.
[BearSSL] / samples / server_basic.c
index fdd801e..92c7d42 100644 (file)
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <stdint.h>
 #include <errno.h>
+#include <signal.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -278,6 +279,11 @@ main(int argc, char *argv[])
        }
        port = argv[1];
 
+       /*
+        * Ignore SIGPIPE to avoid crashing in case of abrupt socket close.
+        */
+       signal(SIGPIPE, SIG_IGN);
+
        /*
         * Open the server socket.
         */