Commit a6da535d91d9c84c3735b59d55d667d22230e78c

Thomas de Grivel 2024-08-08T12:16:37

httpd: require modules

diff --git a/lib/kc3/0.1/httpd.kc3 b/lib/kc3/0.1/httpd.kc3
index c00df36..2021a66 100644
--- a/lib/kc3/0.1/httpd.kc3
+++ b/lib/kc3/0.1/httpd.kc3
@@ -1,15 +1,26 @@
 defmodule HTTPd do
 
+  require File
+  require Socket
+  require Socket.Buf
+  require Str
+  require HTTP
+  require HTTP.Request
+  require HTTP.Response
+  
   def root_dir = "./public"
 
   def server = fn (host, port) {
     socket = Socket.listen(host, port)
     puts("KC3 HTTPd: listening on #{host}:#{port}")
-    while true do
-      client = Socket.Buf.accept(socket)
-      server_client(client)
-      Socket.Buf.close(client)
-    end
+    acceptor = HTTPd.fn () {
+      while true do
+        client = Socket.Buf.accept(socket)
+        server_client(client)
+        Socket.Buf.close(client)
+      end
+    }
+    acceptor();
     Socket.close(socket)
   }