diff 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
line wrap: on
line diff
--- a/seobeo/os/s_macos_edge.c	Tue Aug 04 16:49:01 2026 -0700
+++ b/seobeo/os/s_macos_edge.c	Tue Aug 04 16:49:11 2026 -0700
@@ -51,6 +51,31 @@
           kevent(kq, &client_kev, 1, NULL, 0, NULL);
         }
       } else {
+        if (h->is_sse)
+        {
+          if (evlist[i].flags & EV_EOF)
+          {
+            Seobeo_Handle_Destroy(h);
+            continue;
+          }
+          int32 read_result = Seobeo_Handle_Read(h);
+          if (read_result < 0)
+          {
+            Seobeo_Handle_Destroy(h);
+            continue;
+          }
+          if (h->read_buffer_len)
+            Seobeo_Handle_Consume(h, h->read_buffer_len);
+          struct kevent sse_kev = {
+            .ident  = h->socket,
+            .filter = EVFILT_READ,
+            .flags  = EV_ADD | EV_ONESHOT,
+            .udata  = h
+          };
+          kevent(kq, &sse_kev, 1, NULL, 0, NULL);
+          continue;
+        }
+
         // Remove from kqueue first
         struct kevent del_kev = {
           .ident  = h->socket,
@@ -59,9 +84,22 @@
         };
         kevent(kq, &del_kev, 1, NULL, 0, NULL);
 
-        // Handle request (this function destroys the handle internally)
-        // TODO: Add keep-alive support for macOS like Linux version
+        // macOS handles ordinary requests once, while SSE takes ownership.
         Seobeo_Web_ClientHandle_Request(h, args->cache, FALSE);
+        if (h->is_sse)
+        {
+          struct kevent sse_kev = {
+            .ident  = h->socket,
+            .filter = EVFILT_READ,
+            .flags  = EV_ADD | EV_ONESHOT,
+            .udata  = h
+          };
+          kevent(kq, &sse_kev, 1, NULL, 0, NULL);
+        }
+        else
+        {
+          Seobeo_Handle_Destroy(h);
+        }
       }
     }
   }