comparison seobeo/os/s_macos_edge.c @ 257:609d3c6aff4e

[seobeo] Add persistent SSE streams Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Tue, 04 Aug 2026 16:49:11 -0700
parents a8976a008a9d
children 1f9877b637e9
comparison
equal deleted inserted replaced
256:30c2196d03d4 257:609d3c6aff4e
49 .udata = cli 49 .udata = cli
50 }; 50 };
51 kevent(kq, &client_kev, 1, NULL, 0, NULL); 51 kevent(kq, &client_kev, 1, NULL, 0, NULL);
52 } 52 }
53 } else { 53 } else {
54 if (h->is_sse)
55 {
56 if (evlist[i].flags & EV_EOF)
57 {
58 Seobeo_Handle_Destroy(h);
59 continue;
60 }
61 int32 read_result = Seobeo_Handle_Read(h);
62 if (read_result < 0)
63 {
64 Seobeo_Handle_Destroy(h);
65 continue;
66 }
67 if (h->read_buffer_len)
68 Seobeo_Handle_Consume(h, h->read_buffer_len);
69 struct kevent sse_kev = {
70 .ident = h->socket,
71 .filter = EVFILT_READ,
72 .flags = EV_ADD | EV_ONESHOT,
73 .udata = h
74 };
75 kevent(kq, &sse_kev, 1, NULL, 0, NULL);
76 continue;
77 }
78
54 // Remove from kqueue first 79 // Remove from kqueue first
55 struct kevent del_kev = { 80 struct kevent del_kev = {
56 .ident = h->socket, 81 .ident = h->socket,
57 .filter = EVFILT_READ, 82 .filter = EVFILT_READ,
58 .flags = EV_DELETE, 83 .flags = EV_DELETE,
59 }; 84 };
60 kevent(kq, &del_kev, 1, NULL, 0, NULL); 85 kevent(kq, &del_kev, 1, NULL, 0, NULL);
61 86
62 // Handle request (this function destroys the handle internally) 87 // macOS handles ordinary requests once, while SSE takes ownership.
63 // TODO: Add keep-alive support for macOS like Linux version
64 Seobeo_Web_ClientHandle_Request(h, args->cache, FALSE); 88 Seobeo_Web_ClientHandle_Request(h, args->cache, FALSE);
89 if (h->is_sse)
90 {
91 struct kevent sse_kev = {
92 .ident = h->socket,
93 .filter = EVFILT_READ,
94 .flags = EV_ADD | EV_ONESHOT,
95 .udata = h
96 };
97 kevent(kq, &sse_kev, 1, NULL, 0, NULL);
98 }
99 else
100 {
101 Seobeo_Handle_Destroy(h);
102 }
65 } 103 }
66 } 104 }
67 } 105 }
68 106
69 close(kq); 107 close(kq);