view seobeo/tests/seobeo_server_bind_test.c @ 279:b3b547563ec7

Add Google connector service and agent wiki Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code. Co-authored-by: Copilot <[email protected]> Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 22:22:36 -0700
parents 117c4d53c9a4
children
line wrap: on
line source

#include "seobeo/seobeo.h"

#include <assert.h>
#include <dirent.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>

static int open_descriptor_count(void)
{
  DIR *directory = opendir("/proc/self/fd");
  assert(directory);
  int count = 0;
  struct dirent *entry;
  while ((entry = readdir(directory)) != NULL)
  {
    if (entry->d_name[0] != '.')
      count++;
  }
  closedir(directory);
  return count;
}

int main(void)
{
  int listener = socket(AF_INET, SOCK_STREAM, 0);
  assert(listener >= 0);

  struct sockaddr_in address = {
    .sin_family = AF_INET,
    .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
    .sin_port = 0,
  };
  assert(bind(
      listener,
      (struct sockaddr *)&address,
      sizeof(address)) == 0);
  assert(listen(listener, 1) == 0);

  socklen_t address_length = sizeof(address);
  assert(getsockname(
      listener,
      (struct sockaddr *)&address,
      &address_length) == 0);
  char port[16];
  snprintf(port, sizeof(port), "%u", ntohs(address.sin_port));

  int before = open_descriptor_count();
  Seobeo_Handle *server =
      Seobeo_Stream_Handle_Server_Create("127.0.0.1", port);
  assert(server == NULL);
  assert(open_descriptor_count() == before);

  assert(Seobeo_Stream_Handle_Server_Create(
      "127.0.0.1",
      "not-a-port") == NULL);
  close(listener);
  return 0;
}