comparison seobeo/os/s_macos_edge.c @ 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.
author MrJuneJune <me@mrjunejune.com>
date Fri, 10 Oct 2025 06:59:32 -0700
parents 875bb6e10db7
children ea9ef388ab97
comparison
equal deleted inserted replaced
32:08a465eec50b 33:c0f6c8c7829f
4 4
5 void *Seobeo_Web_Edge_Worker(void *vargs) 5 void *Seobeo_Web_Edge_Worker(void *vargs)
6 { 6 {
7 WorkerArgs *args = vargs; 7 WorkerArgs *args = vargs;
8 struct kevent evlist[64]; 8 struct kevent evlist[64];
9 while (1) { 9 while (1)
10 {
10 int ne = kevent(args->evfd, NULL, 0, evlist, 64, NULL); 11 int ne = kevent(args->evfd, NULL, 0, evlist, 64, NULL);
11 if (ne < 0) continue; 12 if (ne < 0) continue;
12 for (int i = 0; i < ne; i++) { 13
14 for (int i = 0; i < ne; i++)
15 {
13 Seobeo_PHandle h = evlist[i].udata; 16 Seobeo_PHandle h = evlist[i].udata;
14 if (h == args->srv) { 17 if (h == args->srv)
18 {
15 Seobeo_PHandle cli = 19 Seobeo_PHandle cli =
16 Seobeo_Stream_Handle_Server_Accept(args->srv); 20 Seobeo_Stream_Handle_Server_Accept(args->srv);
21
17 if (!cli) continue; 22 if (!cli) continue;
18 struct kevent kev = { 23 struct kevent kev = {
19 .ident = cli->socket, 24 .ident = cli->socket,
20 .filter = EVFILT_READ, 25 .filter = EVFILT_READ,
21 .flags = EV_ADD | EV_ONESHOT, 26 .flags = EV_ADD | EV_ONESHOT,
53 }; 58 };
54 kevent(kq, &kev, 1, NULL, 0, NULL); 59 kevent(kq, &kev, 1, NULL, 0, NULL);
55 60
56 pthread_attr_t attr; 61 pthread_attr_t attr;
57 pthread_attr_init(&attr); 62 pthread_attr_init(&attr);
58 pthread_attr_setstacksize(&attr, 100 * 1024 * 1024); // 100 MB 63 pthread_attr_setstacksize(&attr, 5 * 1024 * 1024); // 5 MB
59 64
60 pthread_t threads[thread_count]; 65 pthread_t threads[thread_count];
61 for (int i = 0; i < thread_count; i++) 66 for (int i = 0; i < thread_count; i++)
62 { 67 {
63 WorkerArgs *args = malloc(sizeof(WorkerArgs)); 68 WorkerArgs *args = malloc(sizeof(WorkerArgs));