comparison seobeo/tests/seobeo_server_stop_test.c @ 260:1f9877b637e9

Add Copilot-powered cyberpunk JRPG chat Integrate the production JRPG chat with Seobeo streaming, Deita persistence, and a Bazel-managed Copilot SDK and LiteLLM inference stack. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <mrjunejune@users.noreply.github.com>
date Wed, 05 Aug 2026 09:19:41 -0700
parents
children
comparison
equal deleted inserted replaced
259:667156fcd3e3 260:1f9877b637e9
1 #include "seobeo/seobeo.h"
2
3 #include <assert.h>
4 #include <pthread.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/socket.h>
8 #include <unistd.h>
9
10 typedef struct {
11 char port[16];
12 int result;
13 } Server_Context;
14
15 static int Reserve_Port(void)
16 {
17 int socket_fd = socket(AF_INET, SOCK_STREAM, 0);
18 assert(socket_fd >= 0);
19 struct sockaddr_in address = {
20 .sin_family = AF_INET,
21 .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
22 .sin_port = 0,
23 };
24 assert(bind(
25 socket_fd,
26 (struct sockaddr *)&address,
27 sizeof(address)) == 0);
28 socklen_t length = sizeof(address);
29 assert(getsockname(
30 socket_fd,
31 (struct sockaddr *)&address,
32 &length) == 0);
33 int port = ntohs(address.sin_port);
34 close(socket_fd);
35 return port;
36 }
37
38 static void *Run_Server(void *p_context)
39 {
40 Server_Context *p_server = p_context;
41 p_server->result = Seobeo_Web_Server_Start_On(
42 "127.0.0.1",
43 "seobeo/tests",
44 p_server->port,
45 SEOBEO_MODE_EDGE,
46 1);
47 return NULL;
48 }
49
50 int main(void)
51 {
52 Server_Context context = {0};
53 snprintf(context.port, sizeof(context.port), "%d", Reserve_Port());
54 pthread_t thread;
55 assert(pthread_create(&thread, NULL, Run_Server, &context) == 0);
56 usleep(200000);
57 Seobeo_Web_Server_Stop();
58 assert(pthread_join(thread, NULL) == 0);
59 assert(context.result == 0);
60 printf("Seobeo server stop test passed\n");
61 return 0;
62 }