Mercurial
annotate seobeo/os/s_linux_edge.c @ 197:0106cb67d958
env var ignore.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Sat, 14 Feb 2026 16:08:47 -0800 |
| parents | a8976a008a9d |
| children |
| rev | line source |
|---|---|
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
1 #include <sys/epoll.h> |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
2 #include <netinet/tcp.h> |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
3 #include "seobeo/seobeo.h" |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
4 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
5 // TCP keep-alive settings |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
6 #define KEEP_ALIVE_IDLE_SEC 30 // Start probes after 30s idle |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
7 #define KEEP_ALIVE_INTERVAL 5 // Probe every 5 seconds |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
8 #define KEEP_ALIVE_COUNT 3 // Close after 3 failed probes |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
9 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
10 // Configure TCP keep-alive on socket (kernel handles timeout) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
11 static void configure_keep_alive(int socket) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
12 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
13 int enable = 1; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
14 setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
15 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
16 int idle = KEEP_ALIVE_IDLE_SEC; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
17 setsockopt(socket, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
18 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
19 int interval = KEEP_ALIVE_INTERVAL; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
20 setsockopt(socket, IPPROTO_TCP, TCP_KEEPINTVL, &interval, sizeof(interval)); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
21 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
22 int count = KEEP_ALIVE_COUNT; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
23 setsockopt(socket, IPPROTO_TCP, TCP_KEEPCNT, &count, sizeof(count)); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
24 } |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
25 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
26 void *Seobeo_Web_Edge_Worker(void *vargs) |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
27 { |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
28 WorkerArgs *args = vargs; |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
29 const int max_events = 64; |
|
33
c0f6c8c7829f
[Seobeo] Linux epoll. Set the client socket to be nonblocking so that it doesn't stop loading when two different threads handle different client calls. I might have problem with socket not being cleaned up properly so need to check that.
MrJuneJune <me@mrjunejune.com>
parents:
19
diff
changeset
|
30 struct epoll_event events[max_events]; |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
31 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
32 int epfd = epoll_create1(0); |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
33 if (epfd < 0) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
34 { |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
35 perror("epoll_create1"); |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
36 return NULL; |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
37 } |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
38 |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
39 struct epoll_event ev = { |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
40 .events = EPOLLIN | EPOLLET, |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
41 .data.ptr = args->srv |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
42 }; |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
43 if (epoll_ctl(epfd, EPOLL_CTL_ADD, args->srv->socket, &ev) < 0) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
44 { |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
45 perror("epoll_ctl ADD server"); |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
46 close(epfd); |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
47 return NULL; |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
48 } |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
49 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
50 while (1) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
51 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
52 int n = epoll_wait(epfd, events, max_events, -1); // Block indefinitely, kernel handles timeouts |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
53 if (n < 0) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
54 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
55 if (errno == EINTR) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
56 continue; |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
57 perror("epoll_wait"); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
58 continue; |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
59 } |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
60 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
61 for (int i = 0; i < n; i++) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
62 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
63 Seobeo_Handle *p_handle = events[i].data.ptr; |
|
33
c0f6c8c7829f
[Seobeo] Linux epoll. Set the client socket to be nonblocking so that it doesn't stop loading when two different threads handle different client calls. I might have problem with socket not being cleaned up properly so need to check that.
MrJuneJune <me@mrjunejune.com>
parents:
19
diff
changeset
|
64 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
65 // Server socket - accept new connections |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
66 if (p_handle == args->srv) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
67 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
68 while (1) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
69 { |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
65
diff
changeset
|
70 Seobeo_Handle *p_cli_handle = Seobeo_Stream_Handle_Server_Accept(args->srv); |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
71 if (!p_cli_handle) break; |
|
33
c0f6c8c7829f
[Seobeo] Linux epoll. Set the client socket to be nonblocking so that it doesn't stop loading when two different threads handle different client calls. I might have problem with socket not being cleaned up properly so need to check that.
MrJuneJune <me@mrjunejune.com>
parents:
19
diff
changeset
|
72 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
73 // Let kernel handle keep-alive timeout |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
74 configure_keep_alive(p_cli_handle->socket); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
75 |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
76 struct epoll_event client_ev = { |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
77 .events = EPOLLIN | EPOLLET, |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
78 .data.ptr = p_cli_handle |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
79 }; |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
80 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
81 if (epoll_ctl(epfd, EPOLL_CTL_ADD, p_cli_handle->socket, &client_ev) < 0) |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
82 { |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
83 perror("epoll_ctl ADD client"); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
84 Seobeo_Handle_Destroy(p_cli_handle); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
85 } |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
86 } |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
87 } |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
88 // Client socket - handle request |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
89 else |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
90 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
91 Seobeo_Handle *p_client_handle = p_handle; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
92 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
93 // Connection error or hangup - clean up |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
94 if (events[i].events & (EPOLLERR | EPOLLHUP)) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
95 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
96 epoll_ctl(epfd, EPOLL_CTL_DEL, p_client_handle->socket, NULL); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
97 Seobeo_Handle_Destroy(p_client_handle); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
98 continue; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
99 } |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
100 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
101 // Handle requests (loop for pipelined requests) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
102 boolean keep_alive = TRUE; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
103 while (keep_alive) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
104 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
105 keep_alive = Seobeo_Web_ClientHandle_Request(p_client_handle, args->cache, TRUE); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
106 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
107 // No more data in buffer, wait for next epoll event |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
108 if (keep_alive && p_client_handle->read_buffer_len == 0) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
109 break; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
110 } |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
111 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
112 // Client wants to close |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
113 if (!keep_alive) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
114 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
115 epoll_ctl(epfd, EPOLL_CTL_DEL, p_client_handle->socket, NULL); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
116 Seobeo_Handle_Destroy(p_client_handle); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
117 } |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
111
diff
changeset
|
118 // Connection stays open, kernel will timeout if idle |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
119 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
120 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
121 } |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
122 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
123 close(epfd); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
124 return NULL; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
125 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
126 |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
127 void Seobeo_Web_Edge( |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
65
diff
changeset
|
128 Seobeo_Handle *p_server_handle, |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
129 int thread_count, |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
130 Seobeo_Cache_Entry *p_html_cache) |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
131 { |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
132 pthread_attr_t attr; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
133 pthread_attr_init(&attr); |
|
33
c0f6c8c7829f
[Seobeo] Linux epoll. Set the client socket to be nonblocking so that it doesn't stop loading when two different threads handle different client calls. I might have problem with socket not being cleaned up properly so need to check that.
MrJuneJune <me@mrjunejune.com>
parents:
19
diff
changeset
|
134 pthread_attr_setstacksize(&attr, 5 * 1024 * 1024); // 5 MB |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
135 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
136 pthread_t threads[thread_count]; |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
137 for (int i = 0; i < thread_count; i++) |
|
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
138 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
139 WorkerArgs *args = malloc(sizeof(WorkerArgs)); |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
140 *args = (WorkerArgs){ p_server_handle, p_html_cache }; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
141 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
142 pthread_create(&threads[i], &attr, Seobeo_Web_Edge_Worker, args); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
143 } |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
144 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
145 // Join threads instead of detaching for proper cleanup |
|
111
48f260576059
[PostDog] Rewriting it from scratch as it is unreadable for me.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
146 for (int i = 0; i < thread_count; i++) |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
147 pthread_join(threads[i], NULL); |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
148 |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
149 pthread_attr_destroy(&attr); |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
150 } |