-
Notifications
You must be signed in to change notification settings - Fork 8
/
mini_trusterd.c
48 lines (42 loc) · 1.99 KB
/
mini_trusterd.c
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
#include <stdio.h>
#include "mruby.h"
#include "mruby/compile.h"
#include "mruby/variable.h"
const char config[] = " \n\
s = HTTP2::Server.new({ \n\
# instance variable from C \n\
:port => @port, \n\
:document_root => './', \n\
:server_name => 'mini_trusterd', \n\
:tls => false, \n\
:callback => true, \n\
:worker => 'auto', \n\
}) \n\
";
const char response[] = " \n\
s.set_map_to_storage_cb { \n\
if s.request.uri =~ /hello/ \n\
s.set_content_cb { \n\
s.rputs 'hello mini-trusterd ' \n\
s.echo @echo_content \n\
} \n\
end \n\
} \n\
";
const char run[] = " \n\
s.run \n\
";
int main(void)
{
mrb_state *mrb = mrb_open();
mrbc_context *ctx = mrbc_context_new(mrb);
// 8080 into instance variable "@port" of main on same ctx
mrb_iv_set(mrb, mrb_top_self(mrb), mrb_intern_lit(mrb, "@port"), mrb_fixnum_value(8080));
mrb_iv_set(mrb, mrb_top_self(mrb), mrb_intern_lit(mrb, "@echo_content"), mrb_str_new_lit(mrb, "world from cb."));
mrb_load_string_cxt(mrb, config, ctx);
mrb_load_string_cxt(mrb, response, ctx);
mrb_load_string_cxt(mrb, run, ctx);
mrbc_context_free(mrb, ctx);
mrb_close(mrb);
return 0;
}