wip httpd libevent2
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
diff --git a/.ikc3_history b/.ikc3_history
index 97d336e..39f7287 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,9 +1,5 @@
Struct.offset(%HTTP.Response{}, :code)
Struct.offset(%HTTP.Response{}, :message)
-Struct.offset(%HTTP.Response{}, :response)
-Struct.offset(%HTTP.Response{}, :protocol)
-Struct.offset(%HTTP.Response{}, :code)
-Struct.offset(%HTTP.Response{}, :message)
Struct.offset(%HTTP.Response{}, :headers)
Struct.offset(%HTTP.Response{}, :body)
Struct.offset(%HTTP.Response{}, :message)
@@ -97,3 +93,8 @@ quote if true do if true do 1 else 2 end else if true do 3 else 4 end end
Fact.subject(%Fact{})
Facts.env_facts
Fact.subject(%Fact{})
+%Socket.Buf{}
+quote quote quote %Socket.Buf{}
+quote quote quote %Socket.Buf{sockfd: (S32) 1}
+"#{%Socket.Buf{}}"
+
diff --git a/lib/kc3/0.1/httpd.kc3 b/lib/kc3/0.1/httpd.kc3
index 78f79e3..aa0d3eb 100644
--- a/lib/kc3/0.1/httpd.kc3
+++ b/lib/kc3/0.1/httpd.kc3
@@ -8,21 +8,46 @@ defmodule HTTPd do
require HTTP.Event
require HTTP.Request
require HTTP.Response
-
+
def root_dir = "./public"
+ def http_client = fn (socket, events, client_ev, client) do
+ puts("echo_client")
+ if List.has?(events, :read) do
+ server_client(client)
+ end
+ end
+
+ def acceptor = fn (server_socket, events, acceptor_ev, void) do
+ if List.has?(events, :read) do
+ 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],
+ http_client, client)
+ r = HTTP.Event.add(client_ev, timeout)
+ puts("HTTP.Event.add: #{r}")
+ end
+ end
+
def server = fn (host, port) {
+ timeout = %Time{tv_sec: (Sw) 30}
+ event_base = HTTP.Event.base_new()
socket = Socket.listen(host, port)
puts("KC3 HTTPd: listening on #{host}:#{port}")
- acceptor = HTTPd.fn () {
- while true do
- client = Socket.Buf.accept(socket)
- server_client(client)
- Socket.Buf.close(client)
- end
- }
- acceptor();
- Socket.close(socket)
+ puts("socket.fd: #{socket.fd}")
+ puts("event_base: #{event_base}")
+ acceptor_ev = HTTP.Event.new(event_base, socket.fd, [:read, :persist],
+ acceptor, void)
+ puts("acceptor_ev: #{acceptor_ev}")
+ r = HTTP.Event.add(acceptor_ev, timeout)
+ puts("HTTP.Event.add: #{r}")
+ r = HTTP.Event.dispatch(event_base)
+ if r do
+ e = errno()
+ puts("HTTP.Event.dispatch: #{r}: #{strerror(e)}")
+ end
+ Socket.close(%Socket{fd: socket})
}
def server_client = fn (client) {
@@ -106,7 +131,7 @@ defmodule HTTPd do
<head>
<title>Index of #{request.url}</title>
<style type="text/css">
- ul { font-family: monospace; }
+ ul { font-family: monospace; }
</style>
</head>
<body>
diff --git a/test/http/07_event_echo.kc3 b/test/http/07_event_echo.kc3
index 7421de4..c807f61 100644
--- a/test/http/07_event_echo.kc3
+++ b/test/http/07_event_echo.kc3
@@ -33,8 +33,8 @@ acceptor_ev = HTTP.Event.new(event_base, socket.fd, [:read, :persist],
puts("acceptor_ev: #{acceptor_ev}")
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
+# r = HTTP.Event.dispatch(event_base)
+# if r do
+# e = errno()
+# puts("HTTP.Event.dispatch: #{r}: #{strerror(e)}")
+# end
diff --git a/test/ikc3/str.kc3 b/test/ikc3/str.kc3
index f3e8369..fd08880 100644
--- a/test/ikc3/str.kc3
+++ b/test/ikc3/str.kc3
@@ -76,3 +76,5 @@ quote "#{%BufRW{}}"
"#{%BufRW{}}"
quote "#{(U8[]) {{0, 0}, {0, 0}, {0, 0}}}"
"#{(U8[]) {{0, 0}, {0, 0}, {0, 0}}}"
+quote "#{%Socket.Buf{}}"
+"#{%Socket.Buf{}}"