diff --git a/http/http_event.c b/http/http_event.c
index 9b13bbe..96f9bb2 100644
--- a/http/http_event.c
+++ b/http/http_event.c
@@ -25,13 +25,14 @@ s32 http_event_add (struct event *ev, s_time *time)
/* http_event_callback
expects a tag of the form
- {fn (fd, events, socket_buf) {void},
+ {fn ((S32) fd, (List) events, (Ptr) ev, (Tag) Arg) {void},
arg} */
void http_event_callback (int fd, short events, void *tag_tuple)
{
s_tag *arg;
s_list *arguments;
- s_list *events_list;
+ struct event *ev;
+ s_list *events_list;
s_fn *fn;
s_tag *tag;
s_tag tmp;
@@ -45,8 +46,11 @@ void http_event_callback (int fd, short events, void *tag_tuple)
abort();
}
fn = &tag->data.tuple.tag[0].data.fn;
- arg = tag->data.tuple.tag + 1;
+ ev = tag->data.tuple.tag[1].data.ptr.p;
+ arg = tag->data.tuple.tag + 2;
events_list = NULL;
+ if (events & EV_PERSIST)
+ events_list = list_new_sym(&g_sym_persist, events_list);
if (events & EV_WRITE)
events_list = list_new_sym(&g_sym_write, events_list);
if (events & EV_READ)
@@ -56,8 +60,9 @@ void http_event_callback (int fd, short events, void *tag_tuple)
if (events & EV_TIMEOUT)
events_list = list_new_sym(&g_sym_timeout, events_list);
arguments = list_new_s32(fd, list_new_list
- (events_list, list_new_tag_copy
- (arg, NULL)));
+ (events_list, list_new_ptr
+ (ev, list_new_tag_copy
+ (arg, NULL))));
if (! env_eval_call_fn_args(&g_kc3_env, fn, arguments, &tmp)) {
err_puts("http_event_callback: callback failed");
assert(! "http_event_callback: callback failed");
diff --git a/lib/kc3/0.1/http/event.kc3 b/lib/kc3/0.1/http/event.kc3
index 6922e28..e49f101 100644
--- a/lib/kc3/0.1/http/event.kc3
+++ b/lib/kc3/0.1/http/event.kc3
@@ -4,12 +4,15 @@ defmodule HTTP.Event do
def add = cfn S32 "http_event_add" (Ptr, Time)
+ # base_set(base, ev)
+ def base_set = cfn S32 "event_base_set" (Ptr, Ptr)
+
def del = cfn S32 "event_del" (Ptr)
def dispatch = cfn S32 "event_dispatch" ()
def init = cfn Ptr "event_init" ()
- def new = cfn Void "http_event_new" (S32, List, Fn, Tag)
+ def new = cfn Ptr "http_event_new" (S32, List, Fn, Tag)
end
diff --git a/libkc3/cfn.c b/libkc3/cfn.c
index a6fde5a..0d7cd45 100644
--- a/libkc3/cfn.c
+++ b/libkc3/cfn.c
@@ -53,7 +53,9 @@ s_tag * cfn_apply (s_cfn *cfn, s_list *args, s_tag *dest)
return NULL;
}
cfn_tag_init(&tmp, cfn->result_type);
- if (cfn->cif.rtype == &ffi_type_pointer) {
+ if ((cfn->result_type != &g_sym_Ptr ||
+ cfn->arg_result) &&
+ cfn->cif.rtype == &ffi_type_pointer) {
/* make result point to result_pointer */
if (! tag_to_ffi_pointer(&tmp, cfn->result_type,
(void **) &result_pointer)) {
diff --git a/test/http/07_event_echo.kc3 b/test/http/07_event_echo.kc3
index 527ed6d..97d367e 100644
--- a/test/http/07_event_echo.kc3
+++ b/test/http/07_event_echo.kc3
@@ -1,13 +1,11 @@
-quote event_base = HTTP.Event.init()
+timeout = %Time{tv_sec: (Sw) 300}
event_base = HTTP.Event.init()
-quote socket = Socket.listen("0.0.0.0", "57000")
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)
-
end
end
acceptor = fn (server_socket, events, acceptor_ev, void) do
@@ -15,19 +13,17 @@ acceptor = fn (server_socket, events, acceptor_ev, void) do
client = Socket.Buf.accept(server_socket)
client_ev = HTTP.Event.new(client.sockfd, [:read, :write],
echo_client, client)
- HTTP.Event.add(client_ev, Time.now() + %Time{tv_sec: 30})
+ puts(client_ev)
+ HTTP.Event.base_set(event_base, client_ev)
+ HTTP.Event.add(client_ev, timeout)
end
end
-quote acceptor_ev = HTTP.Event.new(socket.fd, [:read, :persist], acceptor,
- void)
-acceptor_ev = HTTP.Event.new(socket.fd, [:read, :persist], acceptor,
+puts(socket.fd)
+acceptor_ev = HTTP.Event.new(socket.fd, [:read], acceptor,
void)
-quote r = HTTP.Event.dispatch()
+puts(HTTP.Event.base_set(event_base, acceptor_ev))
+puts(HTTP.Event.add(acceptor_ev, timeout))
r = HTTP.Event.dispatch()
-quote if r do
- e = errno()
- puts("HTTP.Event.dispatch: #{r}: #{strerror(e)}")
-end
if r do
e = errno()
puts("HTTP.Event.dispatch: #{r}: #{strerror(e)}")