corrected test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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