view seobeo/tests/seobeo_sigpipe_test.c @ 232:7edad9623498 hg-web

[hg-web] Close joined feature branch
author MrJuneJune <me@mrjunejune.com>
date Sun, 02 Aug 2026 16:50:48 -0700
parents 0e7b9464248d
children
line wrap: on
line source

#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;
}