Commit b8d85769f14f64932bd339a6f233bd67210aaef3

Baptiste 2024-08-11T20:13:47

corrected test

diff --git a/test/http/07_event_echo.kc3 b/test/http/07_event_echo.kc3
index d0614da..7421de4 100644
--- a/test/http/07_event_echo.kc3
+++ b/test/http/07_event_echo.kc3
@@ -1,30 +1,40 @@
-timeout = %Time{tv_sec: (Sw) 300}
+timeout = %Time{tv_sec: (Sw) 30}
 event_base = HTTP.Event.base_new()
 socket = Socket.listen("0.0.0.0", "57000")
 echo_client = fn (socket, events, client_ev, client) do
-  if List.has?(events, :read) && List.has(events, :write) do
-    Buf.refill(client.buf_rw.r)
-    str = Buf.read_to_str(client.buf_rw.r)
-    Buf.write_str(client.buf_rw.w, str)
+  puts("echo_client")
+  if List.has?(events, :read) do
+    s = Buf.read_until_str_into_str(client.buf_rw.r, "\n")
+    puts("read: #{s}")
+    if (s == "") do
+      puts("closing")
+      HTTP.Event.del(client_ev)
+      Socket.close(client.sockfd)
+      exit(0)
+    end
+    Buf.write_str(client.buf_rw.w, s)
   end
 end
 acceptor = fn (server_socket, events, acceptor_ev, void) do
   if List.has?(events, :read) do
-    client = Socket.Buf.accept(server_socket)
-    client_ev = HTTP.Event.new(event_base, client.sockfd, [:read, :write],
+    puts("acceptor: read")
+    client = Socket.Buf.accept(%Socket{fd: server_socket})
+    puts("acceptor: got client")
+    client_ev = HTTP.Event.new(event_base, client.sockfd, [:read, :persist],
       echo_client, client)
-    puts("client_ev: #{client_ev}")
-    HTTP.Event.add(client_ev, timeout)
+    r = HTTP.Event.add(client_ev, timeout)
+    puts("HTTP.Event.add: #{r}")
   end
 end
 puts("socket.fd: #{socket.fd}")
 puts("event_base: #{event_base}")
-acceptor_ev = HTTP.Event.new(event_base, socket.fd, [:read], acceptor,
-                             void)
+acceptor_ev = HTTP.Event.new(event_base, socket.fd, [:read, :persist],
+                             acceptor, void)
 puts("acceptor_ev: #{acceptor_ev}")
-puts(HTTP.Event.add(acceptor_ev, timeout))
-r = HTTP.Event.dispatch(event_base)
-if r do
+r = HTTP.Event.add(acceptor_ev, timeout)
+puts("HTTP.Event.add: #{r}")
+quote r = HTTP.Event.dispatch(event_base)
+quote if r do
   e = errno()
   puts("HTTP.Event.dispatch: #{r}: #{strerror(e)}")
 end