view seobeo/tests/seobeo_server_stop_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 1f9877b637e9
children
line wrap: on
line source

#include "seobeo/seobeo.h"

#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>

typedef struct {
  char port[16];
  int result;
} Server_Context;

static int Reserve_Port(void)
{
  int socket_fd = socket(AF_INET, SOCK_STREAM, 0);
  assert(socket_fd >= 0);
  struct sockaddr_in address = {
    .sin_family = AF_INET,
    .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
    .sin_port = 0,
  };
  assert(bind(
      socket_fd,
      (struct sockaddr *)&address,
      sizeof(address)) == 0);
  socklen_t length = sizeof(address);
  assert(getsockname(
      socket_fd,
      (struct sockaddr *)&address,
      &length) == 0);
  int port = ntohs(address.sin_port);
  close(socket_fd);
  return port;
}

static void *Run_Server(void *p_context)
{
  Server_Context *p_server = p_context;
  p_server->result = Seobeo_Web_Server_Start_On(
      "127.0.0.1",
      "seobeo/tests",
      p_server->port,
      SEOBEO_MODE_EDGE,
      1);
  return NULL;
}

int main(void)
{
  Server_Context context = {0};
  snprintf(context.port, sizeof(context.port), "%d", Reserve_Port());
  pthread_t thread;
  assert(pthread_create(&thread, NULL, Run_Server, &context) == 0);
  usleep(200000);
  Seobeo_Web_Server_Stop();
  assert(pthread_join(thread, NULL) == 0);
  assert(context.result == 0);
  printf("Seobeo server stop test passed\n");
  return 0;
}