annotate seobeo/os/s_macos_edge.c @ 265:056790c4fb0d

add role-aware Epi assistant prompts Add verified June knowledge, guest/member/admin Copilot profiles, profile-isolated session recovery, animated Epi greetings, and a single authoritative runtime config workflow for inference. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Fri, 07 Aug 2026 10:50:30 -0700
parents 1f9877b637e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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/event.h>
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2 #include "seobeo/seobeo.h"
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
3
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
4
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
5 void *Seobeo_Web_Edge_Worker(void *vargs)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
6 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
7 WorkerArgs *args = vargs;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
8 struct kevent evlist[64];
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: 33
diff changeset
9
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: 33
diff changeset
10 // Each thread creates its own kqueue to avoid race conditions
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: 33
diff changeset
11 int kq = kqueue();
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: 33
diff changeset
12 if (kq < 0) {
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: 33
diff changeset
13 perror("kqueue");
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: 33
diff changeset
14 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: 33
diff changeset
15 }
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: 33
diff changeset
16
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: 33
diff changeset
17 // Add server socket to this thread's kqueue
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: 33
diff changeset
18 struct kevent kev = {
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: 33
diff changeset
19 .ident = args->srv->socket,
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: 33
diff changeset
20 .filter = EVFILT_READ,
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: 33
diff changeset
21 .flags = EV_ADD,
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: 33
diff changeset
22 .udata = 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: 33
diff changeset
23 };
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: 33
diff changeset
24 kevent(kq, &kev, 1, NULL, 0, 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: 33
diff changeset
25
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
26 while (!Seobeo_Web_Server_Is_Stopping())
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
27 {
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
28 struct timespec timeout = {
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
29 .tv_nsec = 250 * 1000 * 1000,
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
30 };
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
31 int ne = kevent(kq, NULL, 0, evlist, 64, &timeout);
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: 33
diff changeset
32 if (ne < 0) {
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: 33
diff changeset
33 if (errno == EINTR) continue;
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: 33
diff changeset
34 perror("kevent");
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: 33
diff changeset
35 continue;
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: 33
diff changeset
36 }
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
37
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
38 for (int i = 0; i < ne; i++)
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
39 {
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
40 Seobeo_Handle *h = evlist[i].udata;
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
41 if (h == args->srv)
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
42 {
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: 33
diff changeset
43 // Accept new connections in a loop (for edge-triggered behavior)
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: 33
diff changeset
44 while (1) {
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
45 Seobeo_Handle *cli = Seobeo_Stream_Handle_Server_Accept(args->srv);
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: 33
diff changeset
46 if (!cli) 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
47
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: 33
diff changeset
48 struct kevent client_kev = {
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: 33
diff changeset
49 .ident = cli->socket,
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: 33
diff changeset
50 .filter = EVFILT_READ,
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: 33
diff changeset
51 .flags = EV_ADD | EV_ONESHOT,
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: 33
diff changeset
52 .udata = cli
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: 33
diff changeset
53 };
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: 33
diff changeset
54 kevent(kq, &client_kev, 1, NULL, 0, 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: 33
diff changeset
55 }
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: 33
diff changeset
56 } else {
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
57 if (h->is_sse)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
58 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
59 if (evlist[i].flags & EV_EOF)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
60 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
61 Seobeo_Handle_Destroy(h);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
62 continue;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
63 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
64 int32 read_result = Seobeo_Handle_Read(h);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
65 if (read_result < 0)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
66 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
67 Seobeo_Handle_Destroy(h);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
68 continue;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
69 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
70 if (h->read_buffer_len)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
71 Seobeo_Handle_Consume(h, h->read_buffer_len);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
72 struct kevent sse_kev = {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
73 .ident = h->socket,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
74 .filter = EVFILT_READ,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
75 .flags = EV_ADD | EV_ONESHOT,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
76 .udata = h
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
77 };
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
78 kevent(kq, &sse_kev, 1, NULL, 0, NULL);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
79 continue;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
80 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
81
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: 33
diff changeset
82 // Remove from kqueue first
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: 33
diff changeset
83 struct kevent del_kev = {
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: 33
diff changeset
84 .ident = h->socket,
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
85 .filter = EVFILT_READ,
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: 33
diff changeset
86 .flags = EV_DELETE,
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
87 };
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: 33
diff changeset
88 kevent(kq, &del_kev, 1, NULL, 0, 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: 33
diff changeset
89
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
90 // macOS handles ordinary requests once, while SSE takes ownership.
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 71
diff changeset
91 Seobeo_Web_ClientHandle_Request(h, args->cache, FALSE);
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
92 if (h->is_sse)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
93 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
94 struct kevent sse_kev = {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
95 .ident = h->socket,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
96 .filter = EVFILT_READ,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
97 .flags = EV_ADD | EV_ONESHOT,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
98 .udata = h
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
99 };
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
100 kevent(kq, &sse_kev, 1, NULL, 0, NULL);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
101 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
102 else
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
103 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
104 Seobeo_Handle_Destroy(h);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
105 }
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
106 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
107 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
108 }
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: 33
diff changeset
109
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: 33
diff changeset
110 close(kq);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
111 return NULL;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
112 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
113
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
114 void Seobeo_Web_Edge(
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
115 Seobeo_Handle *p_server_handle,
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
116 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
117 Seobeo_Cache_Entry *p_html_cache)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
118 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
119 pthread_attr_t attr;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
120 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
121 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
122
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
123 pthread_t threads[thread_count];
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
124 for (int i = 0; i < thread_count; i++)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
125 {
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
126 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: 33
diff changeset
127 *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
128
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: 33
diff changeset
129 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
130 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
131 for (int i = 0; i < thread_count; i++)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
132 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
133 pthread_join(threads[i], NULL);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
134 }
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: 33
diff changeset
135
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: 33
diff changeset
136 pthread_attr_destroy(&attr);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
137 return;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
138 }