diff seobeo/tests/seobeo_sigpipe_test.c @ 223:0e7b9464248d hg-web

[hg-web] Add browser route regression coverage
author MrJuneJune <me@mrjunejune.com>
date Sun, 02 Aug 2026 10:07:40 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/seobeo/tests/seobeo_sigpipe_test.c	Sun Aug 02 10:07:40 2026 -0700
@@ -0,0 +1,36 @@
+#include "seobeo/seobeo.h"
+
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+
+int main(void)
+{
+  Seobeo_Handle *server =
+      Seobeo_Stream_Handle_Server_Create("127.0.0.1", "0");
+  if (!server)
+    return 1;
+
+  raise(SIGPIPE);
+  Seobeo_Handle_Destroy(server);
+
+  int sockets[2];
+  if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0)
+    return 1;
+
+  Seobeo_Handle handle = {0};
+  handle.socket = sockets[0];
+  handle.write_buffer_capacity = 64;
+  handle.write_buffer = malloc(handle.write_buffer_capacity);
+  if (!handle.write_buffer)
+    return 1;
+
+  close(sockets[1]);
+  if (Seobeo_Handle_Queue(&handle, (const uint8 *)"closed", 6) != 0)
+    return 1;
+
+  int result = Seobeo_Handle_Flush(&handle);
+  close(sockets[0]);
+  free(handle.write_buffer);
+  return result < 0 ? 0 : 1;
+}