comparison seobeo/os/s_macos_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/event.h>
2 #include "seobeo/seobeo.h"
3
4
5 void *Seobeo_Web_Edge_Worker(void *vargs)
6 {
7 WorkerArgs *args = vargs;
8 struct kevent evlist[64];
9 while (1) {
10 int ne = kevent(args->evfd, NULL, 0, evlist, 64, NULL);
11 if (ne < 0) continue;
12 for (int i = 0; i < ne; i++) {
13 Seobeo_PHandle h = evlist[i].udata;
14 if (h == args->srv) {
15 Seobeo_PHandle cli =
16 Seobeo_Stream_Handle_Accept(args->srv);
17 if (!cli) continue;
18 struct kevent kev = {
19 .ident = cli->socket,
20 .filter = EVFILT_READ,
21 .flags = EV_ADD,
22 .udata = cli
23 };
24 kevent(args->evfd, &kev, 1, NULL, 0, NULL);
25 } else {
26 Seobeo_Web_HandleClientRequest(h, args->cache);
27 struct kevent kev = {
28 .ident = h->socket,
29 .filter = EVFILT_READ,
30 .flags = EV_DELETE,
31 };
32 kevent(args->evfd, &kev, 1, NULL, 0, NULL);
33 Seobeo_Handle_Destroy(h);
34 }
35 }
36 }
37 return NULL;
38 }
39
40 void Seobeo_Web_Edge(
41 Seobeo_PHandle p_server_handle,
42 int thread_count,
43 Dowa_PHashMap p_html_cache)
44 {
45 int kq = kqueue();
46 struct kevent kev = {
47 .ident = p_server_handle->socket,
48 .filter = EVFILT_READ,
49 .flags = EV_ADD,
50 .udata = p_server_handle
51 };
52 kevent(kq, &kev, 1, NULL, 0, NULL);
53
54 pthread_attr_t attr;
55 pthread_attr_init(&attr);
56 pthread_attr_setstacksize(&attr, 100 * 1024 * 1024); // 100 MB
57
58 pthread_t threads[thread_count];
59 WorkerArgs args = { p_server_handle, p_html_cache, kq };
60 for (int i = 0; i < thread_count; i++)
61 {
62 pthread_create(&threads[i], NULL,
63 Seobeo_Web_Edge_Worker, &args);
64 }
65 for (int i = 0; i < thread_count; i++)
66 {
67 pthread_join(threads[i], NULL);
68 }
69 return;
70 }