annotate seobeo/os/s_linux_edge.c @ 63:fff1b048dda6

[Postdog] Fixed a problem where string did not wrap.
author June Park <parkjune1995@gmail.com>
date Tue, 23 Dec 2025 14:00:37 -0800
parents ea9ef388ab97
children ecb6ee6a22c3
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/epoll.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
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
5 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
6 {
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
7 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
8 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
9 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
10
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
11 // Each thread creates its own epoll 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: 36
diff changeset
12 int epfd = epoll_create1(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: 36
diff changeset
13 if (epfd < 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: 36
diff changeset
14 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
15 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
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: 36
diff changeset
17
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
18 // Add server socket to this thread's epoll
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
19 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
20 .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
21 .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
22 };
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
23 if (epoll_ctl(epfd, EPOLL_CTL_ADD, args->srv->socket, &ev) < 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: 36
diff changeset
24 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
25 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
26 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
27 }
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
28
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 while (1) {
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
30 int n = epoll_wait(epfd, events, max_events, -1);
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 if (n < 0) {
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 if (errno == EINTR) 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
33 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
34 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
35 }
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
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
37 for (int i = 0; i < n; i++) {
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
38 Seobeo_PHandle phandle = 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
39
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
40 if (phandle == 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: 36
diff changeset
41 // Accept all pending connections (edge-triggered mode)
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
42 while (1) {
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
43 Seobeo_PHandle p_cli_handle = Seobeo_Stream_Handle_Server_Accept(args->srv);
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
44 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
45
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
46 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
47 .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
48 .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
49 };
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
50 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
51 {
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
52 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
53 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
54 }
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
55 }
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
56 } else {
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
57 // Remove from epoll 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: 36
diff changeset
58 epoll_ctl(epfd, EPOLL_CTL_DEL, phandle->socket, 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
59
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
60 // Handle request (this function destroys the handle internally)
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
61 Seobeo_Web_HandleClientRequest(phandle, args->cache);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
62 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
63 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
64 }
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
65
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
66 close(epfd);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
67 return NULL;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
68 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
69
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
70 void Seobeo_Web_Edge(
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
71 Seobeo_PHandle 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
72 int thread_count,
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
73 Dowa_PHashMap p_html_cache)
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
74 {
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
75 pthread_attr_t attr;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
76 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
77 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
78
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
79 pthread_t threads[thread_count];
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
80 for (int i = 0; i < thread_count; i++) {
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
81 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
82 *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
83
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
84 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
85 }
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
86
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
87 // Join threads instead of detaching for proper cleanup
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
88 for (int i = 0; i < thread_count; i++) {
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
89 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
90 }
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
91
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
92 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
93 }
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
94
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
95
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
96 void Seobeo_Web_Edge_2(Seobeo_PHandle p_handle_server, Dowa_PHashMap cache)
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
97 {
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
98 const int MAX_EVENTS = 1024;
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
99 struct epoll_event events[MAX_EVENTS];
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
100 char keybuf[32];
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
101
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
102 int epfd = epoll_create1(0);
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
103 if (epfd < 0)
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
104 {
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
105 perror("epoll_create1");
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
106 return;
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
107 }
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
108
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
109 struct epoll_event 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
110 .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
111 .data.fd = p_handle_server->socket
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
112 };
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
113 if (epoll_ctl(epfd, EPOLL_CTL_ADD, p_handle_server->socket, &ev) < 0)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
114 {
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
115 perror("epoll_ctl ADD server");
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
116 close(epfd);
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
117 return;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
118 }
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
119
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
120 Dowa_PHashMap handles = Dowa_HashMap_Create(1024);
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
121 snprintf(keybuf, sizeof(keybuf), "%d", p_handle_server->socket);
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 Dowa_HashMap_Push_Value(handles, keybuf, p_handle_server, sizeof(p_handle_server));
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
123
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
124 while (1) {
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
125 int n = epoll_wait(epfd, events, MAX_EVENTS, -1);
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
126 if (n < 0)
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 {
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
128 if (errno == EINTR) 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
129 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
130 break;
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
131 }
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
132
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
133 for (int i = 0; i < n; i++)
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
134 {
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
135 int fd = events[i].data.fd;
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
136
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
137 if (fd == p_handle_server->socket)
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
138 {
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
139 while (1)
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
140 {
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
141 Seobeo_PHandle p_handle_client = Seobeo_Stream_Handle_Server_Accept(p_handle_server);
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
142 if (!p_handle_client) break;
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
143
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 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
145 .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
146 .data.fd = p_handle_client->socket
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
147 };
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
148 if (epoll_ctl(epfd, EPOLL_CTL_ADD, p_handle_client->socket, &client_ev) < 0)
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
149 {
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 perror("epoll_ctl ADD client");
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
151 Seobeo_Handle_Destroy(p_handle_client);
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
152 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
153 }
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
154
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
155 snprintf(keybuf, sizeof(keybuf), "%d", p_handle_client->socket);
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
156 if (p_handle_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
157 Dowa_HashMap_Push_Value_With_Type_NoCopy(handles, keybuf, p_handle_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
158 sizeof(p_handle_client), DOWA_HASH_MAP_TYPE_HASHMAP);
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
159 }
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
160 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
161 }
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
162
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
163 snprintf(keybuf, sizeof(keybuf), "%d", fd);
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
164 Seobeo_PHandle p_handle_client = Dowa_HashMap_Get(handles, keybuf);
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
165 if (!p_handle_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
166 {
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
167 // might happen if client closed between event and lookup
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
168 epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
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
169 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
170 }
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
171
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
172 // Remove from epoll
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
173 epoll_ctl(epfd, EPOLL_CTL_DEL, fd, 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
174
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
175 // Handle request (this function destroys the handle internally)
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
176 Seobeo_Web_HandleClientRequest(p_handle_client, 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
177
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
178 // Remove from hashmap (handle is already destroyed by HandleClientRequest)
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
179 Dowa_HashMap_Pop_Key(handles, keybuf);
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
180 }
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
181 }
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
182
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
183 close(epfd);
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
184 Dowa_HashMap_Destroy(handles);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
185 }
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
186