static int aio_worker_cleanup(void) { size_t i; s_running = 0; for(i = 0; i < MAX_THREAD; i++) thread_destroy(s_threads[i]); aio_socket_clean(); return 0; }
void hls_server_test(const char* ip, int port) { aio_socket_init(1); http_server_init(); void* http = http_server_create(ip, port); http_server_set_handler(http, hls_server_onhttp, http); // http process while(aio_socket_process(1000) >= 0) { } http_server_destroy(http); http_server_cleanup(); aio_socket_clean(); }
int main(int argc, char* argv[]) { char c; int cpu = system_getcpucount(); socket_t server; aio_socket_t aioserver; memset(s_buffer, 'A', sizeof(s_buffer)-1); aio_socket_init(cpu); s_thpool = thread_pool_create(cpu, cpu, cpu*2); while(cpu > 0) { thread_pool_push(s_thpool, AIOWorker, NULL); --cpu; } server = Listen(50000); aioserver = aio_socket_create(server, 1); aio_socket_accept(aioserver, OnAccept, aioserver); printf("server listen at: %d\n", 50000); for(c = getchar(); 'q' != c; c = getchar()) { switch(c) { case 'c': // close socket aio_socket_destroy(aioserver); break; default: printf("unknown command.\nc : close socket\n"); } } aio_socket_destroy(aioserver); thread_pool_destroy(s_thpool); aio_socket_clean(); return 0; }
int main(int argc, char* argv[]) { #if defined(OS_LINUX) /* ignore pipe signal */ struct sigaction sa; sa.sa_handler = SIG_IGN; sigaction(SIGCHLD, &sa, 0); sigaction(SIGPIPE, &sa, 0); #endif int port = 554; for(int i=1; i<argc; i++) { if(streq(argv[i], "--port") && i+1<argc) { port = atoi(argv[++i]); } } size_t cpu = system_getcpucount(); g_thpool = thread_pool_create(cpu, cpu, cpu*4); aio_socket_init(cpu * 2); for(size_t i=0; i<cpu * 2; i++) thread_pool_push(g_thpool, AioWorker, NULL); // start worker // start server StartTcpServer(NULL, port); StartUdpServer(NULL, port); for(int c = getchar(); 'q' != c ; c = getchar()) { } aio_socket_destroy(s_tcp); aio_socket_clean(); thread_pool_destroy(g_thpool); return 0; }