Mercurial
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/seobeo/tests/seobeo_server_stop_test.c Wed Aug 05 09:19:41 2026 -0700 @@ -0,0 +1,62 @@ +#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; +}