Mercurial
view seobeo/tests/seobeo_server_stop_test.c @ 262:0f45474c1b1a
Add cyberpunk JRPG blog browser
Show the latest posts in the JRPG preview and render the full blog archive and sanitized post details in the Inspect modal.
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <mrjunejune@users.noreply.github.com> |
|---|---|
| date | Thu, 06 Aug 2026 04:08:45 -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; }