Mercurial
comparison seobeo/os/s_linux_edge.c @ 7:114cad94008f
[Seobeo] Updated to support thread and edge server calls.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Mon, 29 Sep 2025 17:00:38 -0700 |
| parents | |
| children | fb2cff495a60 |
comparison
equal
deleted
inserted
replaced
| 6:1e61008b9980 | 7:114cad94008f |
|---|---|
| 1 #include <sys/epoll.h> | |
| 2 #include "seobeo/seobeo.h" | |
| 3 | |
| 4 | |
| 5 void *Seobeo_Web_Edge_Worker(void *vargs) | |
| 6 { | |
| 7 WorkerArgs *args = vargs; | |
| 8 struct epoll_event events[64]; | |
| 9 while (1) { | |
| 10 int n = epoll_wait(args->evfd, events, 64, -1); | |
| 11 if (n < 0) continue; | |
| 12 for (int i = 0; i < n; i++) { | |
| 13 Seobeo_PHandle h = events[i].data.ptr; | |
| 14 if (h == args->srv) { | |
| 15 // new connection | |
| 16 Seobeo_PHandle cli = | |
| 17 Seobeo_Stream_Handle_Accept(args->srv); | |
| 18 if (!cli) continue; | |
| 19 struct epoll_event ev = { | |
| 20 .events = EPOLLIN, | |
| 21 .data.ptr = cli | |
| 22 }; | |
| 23 epoll_ctl(args->evfd, EPOLL_CTL_ADD, | |
| 24 cli->socket, &ev); | |
| 25 } else { | |
| 26 // client ready | |
| 27 Seobeo_Web_HandleClientRequest(h, args->cache); | |
| 28 epoll_ctl(args->evfd, EPOLL_CTL_DEL, | |
| 29 h->socket, NULL); | |
| 30 Seobeo_Handle_Destroy(h); | |
| 31 } | |
| 32 } | |
| 33 } | |
| 34 return NULL; | |
| 35 } | |
| 36 | |
| 37 void Seobeo_Web_Edge( | |
| 38 Seobeo_PHandle p_server_handle, | |
| 39 int thread_count, | |
| 40 Dowa_PHashMap p_html_cache) | |
| 41 { | |
| 42 int epfd = epoll_create1(0); | |
| 43 struct epoll_event ev = { | |
| 44 .events = EPOLLIN, | |
| 45 .data.ptr = p_server_handle | |
| 46 }; | |
| 47 epoll_ctl(epfd, EPOLL_CTL_ADD, | |
| 48 p_server_handle->socket, &ev); | |
| 49 | |
| 50 pthread_attr_t attr; | |
| 51 pthread_attr_init(&attr); | |
| 52 pthread_attr_setstacksize(&attr, 100 * 1024 * 1024); // 100 MB | |
| 53 | |
| 54 pthread_t threads[thread_count]; | |
| 55 WorkerArgs args = { p_server_handle, p_html_cache, epfd }; | |
| 56 for (int i = 0; i < thread_count; i++) | |
| 57 { | |
| 58 pthread_create(&threads[i], NULL, | |
| 59 Seobeo_Web_Edge_Worker, &args); | |
| 60 } | |
| 61 for (int i = 0; i < thread_count; i++) | |
| 62 { | |
| 63 pthread_join(threads[i], NULL); | |
| 64 } | |
| 65 return; | |
| 66 } |