agoo 2.2.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of agoo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/ext/agoo/agoo.c +2 -2
- data/ext/agoo/con.c +65 -62
- data/ext/agoo/debug.c +3 -2
- data/ext/agoo/extconf.rb +4 -2
- data/ext/agoo/hook.c +15 -74
- data/ext/agoo/hook.h +20 -12
- data/ext/agoo/log.c +30 -466
- data/ext/agoo/log.h +6 -5
- data/ext/agoo/method.h +25 -0
- data/ext/agoo/request.c +27 -23
- data/ext/agoo/request.h +1 -0
- data/ext/agoo/response.c +0 -1
- data/ext/agoo/rhook.c +82 -0
- data/ext/agoo/rhook.h +13 -0
- data/ext/agoo/rlog.c +469 -0
- data/ext/agoo/rlog.h +11 -0
- data/ext/agoo/seg.h +11 -0
- data/ext/agoo/server.c +22 -8
- data/ext/agoo/server.h +1 -1
- data/ext/agoo/types.h +0 -19
- data/ext/agoo/upgraded.c +13 -1
- data/ext/agoo/upgraded.h +2 -1
- data/ext/agoo/websocket.c +3 -3
- data/lib/agoo/version.rb +1 -1
- metadata +9 -3
data/ext/agoo/rlog.h
ADDED
data/ext/agoo/seg.h
ADDED
data/ext/agoo/server.c
CHANGED
@@ -74,6 +74,9 @@ server_mark(void *ptr) {
|
|
74
74
|
if (Qnil != up->handler) {
|
75
75
|
rb_gc_mark(up->handler);
|
76
76
|
}
|
77
|
+
if (Qnil != up->env) {
|
78
|
+
rb_gc_mark(up->env);
|
79
|
+
}
|
77
80
|
if (Qnil != up->wrap) {
|
78
81
|
rb_gc_mark(up->wrap);
|
79
82
|
}
|
@@ -423,6 +426,17 @@ rescue_error(VALUE x) {
|
|
423
426
|
res_set_message(req->res, message);
|
424
427
|
queue_wakeup(&the_server.con_queue);
|
425
428
|
} else {
|
429
|
+
// TBD should the backtrace be included in the log?
|
430
|
+
/*
|
431
|
+
volatile VALUE bt = rb_funcall(info, rb_intern("backtrace"), 0);
|
432
|
+
int blen = RARRAY_LEN(bt);
|
433
|
+
int i;
|
434
|
+
VALUE rline;
|
435
|
+
|
436
|
+
for (i = 0; i < blen; i++) {
|
437
|
+
rline = rb_ary_entry(bt, i);
|
438
|
+
}
|
439
|
+
*/
|
426
440
|
log_cat(&error_cat, "%s: %s", classname, ms);
|
427
441
|
}
|
428
442
|
return Qfalse;
|
@@ -585,7 +599,7 @@ handle_rack_inner(void *x) {
|
|
585
599
|
break;
|
586
600
|
}
|
587
601
|
req->handler_type = PUSH_HOOK;
|
588
|
-
upgraded_create(req->res->con, req->handler);
|
602
|
+
upgraded_create(req->res->con, req->handler, request_env(req));
|
589
603
|
t->len = snprintf(t->text, 1024, "HTTP/1.1 101 %s\r\n", status_msg);
|
590
604
|
t = ws_add_headers(req, t);
|
591
605
|
break;
|
@@ -597,7 +611,7 @@ handle_rack_inner(void *x) {
|
|
597
611
|
break;
|
598
612
|
}
|
599
613
|
req->handler_type = PUSH_HOOK;
|
600
|
-
upgraded_create(req->res->con, req->handler);
|
614
|
+
upgraded_create(req->res->con, req->handler, request_env(req));
|
601
615
|
t = sse_upgrade(req, t);
|
602
616
|
res_set_message(req->res, t);
|
603
617
|
queue_wakeup(&the_server.con_queue);
|
@@ -674,12 +688,12 @@ handle_push_inner(void *x) {
|
|
674
688
|
|
675
689
|
switch (req->method) {
|
676
690
|
case ON_MSG:
|
677
|
-
if (req->up->on_msg) {
|
691
|
+
if (req->up->on_msg) {
|
678
692
|
rb_funcall(req->handler, on_message_id, 2, req->up->wrap, rb_str_new(req->msg, req->mlen));
|
679
693
|
}
|
680
694
|
break;
|
681
695
|
case ON_BIN:
|
682
|
-
if (req->up->on_msg) {
|
696
|
+
if (req->up->on_msg) {
|
683
697
|
volatile VALUE rstr = rb_str_new(req->msg, req->mlen);
|
684
698
|
|
685
699
|
rb_enc_associate(rstr, rb_ascii8bit_encoding());
|
@@ -917,7 +931,7 @@ handle(VALUE self, VALUE method, VALUE pattern, VALUE handler) {
|
|
917
931
|
} else {
|
918
932
|
rb_raise(rb_eArgError, "invalid method");
|
919
933
|
}
|
920
|
-
if (NULL == (hook =
|
934
|
+
if (NULL == (hook = rhook_create(meth, pat, handler))) {
|
921
935
|
rb_raise(rb_eStandardError, "out of memory.");
|
922
936
|
} else {
|
923
937
|
Hook h;
|
@@ -931,7 +945,7 @@ handle(VALUE self, VALUE method, VALUE pattern, VALUE handler) {
|
|
931
945
|
} else {
|
932
946
|
the_server.hooks = hook;
|
933
947
|
}
|
934
|
-
rb_gc_register_address(&hook->handler);
|
948
|
+
rb_gc_register_address((VALUE*)&hook->handler);
|
935
949
|
}
|
936
950
|
return Qnil;
|
937
951
|
}
|
@@ -945,10 +959,10 @@ handle(VALUE self, VALUE method, VALUE pattern, VALUE handler) {
|
|
945
959
|
*/
|
946
960
|
static VALUE
|
947
961
|
handle_not_found(VALUE self, VALUE handler) {
|
948
|
-
if (NULL == (the_server.hook404 =
|
962
|
+
if (NULL == (the_server.hook404 = rhook_create(GET, "/", handler))) {
|
949
963
|
rb_raise(rb_eStandardError, "out of memory.");
|
950
964
|
}
|
951
|
-
rb_gc_register_address(&the_server.hook404->handler);
|
965
|
+
rb_gc_register_address((VALUE*)&the_server.hook404->handler);
|
952
966
|
|
953
967
|
return Qnil;
|
954
968
|
}
|
data/ext/agoo/server.h
CHANGED
data/ext/agoo/types.h
CHANGED
@@ -3,25 +3,6 @@
|
|
3
3
|
#ifndef __AGOO_TYPES_H__
|
4
4
|
#define __AGOO_TYPES_H__
|
5
5
|
|
6
|
-
typedef enum {
|
7
|
-
CONNECT = 'C',
|
8
|
-
DELETE = 'D',
|
9
|
-
GET = 'G',
|
10
|
-
HEAD = 'H',
|
11
|
-
OPTIONS = 'O',
|
12
|
-
POST = 'P',
|
13
|
-
PUT = 'U',
|
14
|
-
PATCH = 'T',
|
15
|
-
ALL = 'A',
|
16
|
-
NONE = '\0',
|
17
|
-
|
18
|
-
ON_MSG = 'M', // use for on_message callback
|
19
|
-
ON_BIN = 'B', // use for on_message callback with binary (ASCII8BIT)
|
20
|
-
ON_CLOSE = 'X', // use for on_close callback
|
21
|
-
ON_SHUTDOWN = 'S', // use for on_shotdown callback
|
22
|
-
ON_EMPTY = 'E', // use for on_drained callback
|
23
|
-
} Method;
|
24
|
-
|
25
6
|
typedef enum {
|
26
7
|
CON_ANY = '\0',
|
27
8
|
CON_HTTP = 'H',
|
data/ext/agoo/upgraded.c
CHANGED
@@ -334,7 +334,7 @@ protocol(VALUE self) {
|
|
334
334
|
}
|
335
335
|
|
336
336
|
Upgraded
|
337
|
-
upgraded_create(Con c, VALUE obj) {
|
337
|
+
upgraded_create(Con c, VALUE obj, VALUE env) {
|
338
338
|
Upgraded up = (Upgraded)malloc(sizeof(struct _Upgraded));
|
339
339
|
|
340
340
|
if (!the_server.active) {
|
@@ -344,6 +344,7 @@ upgraded_create(Con c, VALUE obj) {
|
|
344
344
|
DEBUG_ALLOC(mem_upgraded, up);
|
345
345
|
up->con = c;
|
346
346
|
up->handler = obj;
|
347
|
+
up->env = env;
|
347
348
|
atomic_init(&up->pending, 0);
|
348
349
|
atomic_init(&up->ref_cnt, 1); // start with 1 for the Con reference
|
349
350
|
up->on_empty = rb_respond_to(obj, rb_intern("on_drained"));
|
@@ -374,6 +375,16 @@ upgraded_create(Con c, VALUE obj) {
|
|
374
375
|
// Use the publish from the Agoo module.
|
375
376
|
extern VALUE ragoo_publish(VALUE self, VALUE subject, VALUE message);
|
376
377
|
|
378
|
+
static VALUE
|
379
|
+
env(VALUE self) {
|
380
|
+
Upgraded up = get_upgraded(self);
|
381
|
+
|
382
|
+
if (NULL != up) {
|
383
|
+
return up->env;
|
384
|
+
}
|
385
|
+
return Qnil;
|
386
|
+
}
|
387
|
+
|
377
388
|
/* Document-module: Agoo::Upgraded
|
378
389
|
*
|
379
390
|
* Adds methods to a handler of WebSocket and SSE connections.
|
@@ -390,6 +401,7 @@ upgraded_init(VALUE mod) {
|
|
390
401
|
rb_define_method(upgraded_class, "protocol", protocol, 0);
|
391
402
|
rb_define_method(upgraded_class, "publish", ragoo_publish, 2);
|
392
403
|
rb_define_method(upgraded_class, "open?", up_open, 0);
|
404
|
+
rb_define_method(upgraded_class, "env", env, 0);
|
393
405
|
|
394
406
|
on_open_id = rb_intern("on_open");
|
395
407
|
to_s_id = rb_intern("to_s");
|
data/ext/agoo/upgraded.h
CHANGED
@@ -16,6 +16,7 @@ typedef struct _Upgraded {
|
|
16
16
|
struct _Con *con;
|
17
17
|
VALUE handler;
|
18
18
|
VALUE wrap;
|
19
|
+
VALUE env;
|
19
20
|
atomic_int pending;
|
20
21
|
atomic_int ref_cnt;
|
21
22
|
struct _Subject *subjects;
|
@@ -26,7 +27,7 @@ typedef struct _Upgraded {
|
|
26
27
|
} *Upgraded;
|
27
28
|
|
28
29
|
extern void upgraded_init(VALUE mod);
|
29
|
-
extern Upgraded upgraded_create(struct _Con *c, VALUE obj);
|
30
|
+
extern Upgraded upgraded_create(struct _Con *c, VALUE obj, VALUE env);
|
30
31
|
extern void upgraded_release(Upgraded up);
|
31
32
|
extern void upgraded_release_con(Upgraded up);
|
32
33
|
|
data/ext/agoo/websocket.c
CHANGED
@@ -126,7 +126,7 @@ ws_calc_len(Con c, uint8_t *buf, size_t cnt) {
|
|
126
126
|
uint64_t plen;
|
127
127
|
|
128
128
|
if (0 == (0x80 & *b)) {
|
129
|
-
log_cat(&error_cat, "FIN must be 1. Websocket continuation not implemented on connection %llu.", c->id);
|
129
|
+
log_cat(&error_cat, "FIN must be 1. Websocket continuation not implemented on connection %llu.", (unsigned long long)c->id);
|
130
130
|
return -1;
|
131
131
|
}
|
132
132
|
b++;
|
@@ -213,7 +213,7 @@ ws_ping(Con c) {
|
|
213
213
|
Res res;
|
214
214
|
|
215
215
|
if (NULL == (res = res_create(c))) {
|
216
|
-
log_cat(&error_cat, "Memory allocation of response failed on connection %llu.", c->id);
|
216
|
+
log_cat(&error_cat, "Memory allocation of response failed on connection %llu.", (unsigned long long)c->id);
|
217
217
|
} else {
|
218
218
|
if (NULL == c->res_tail) {
|
219
219
|
c->res_head = res;
|
@@ -232,7 +232,7 @@ ws_pong(Con c) {
|
|
232
232
|
Res res;
|
233
233
|
|
234
234
|
if (NULL == (res = res_create(c))) {
|
235
|
-
log_cat(&error_cat, "Memory allocation of response failed on connection %llu.", c->id);
|
235
|
+
log_cat(&error_cat, "Memory allocation of response failed on connection %llu.", (unsigned long long)c->id);
|
236
236
|
} else {
|
237
237
|
if (NULL == c->res_tail) {
|
238
238
|
c->res_head = res;
|
data/lib/agoo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- ext/agoo/log.c
|
67
67
|
- ext/agoo/log.h
|
68
68
|
- ext/agoo/log_queue.h
|
69
|
+
- ext/agoo/method.h
|
69
70
|
- ext/agoo/page.c
|
70
71
|
- ext/agoo/page.h
|
71
72
|
- ext/agoo/pub.c
|
@@ -80,6 +81,11 @@ files:
|
|
80
81
|
- ext/agoo/res.h
|
81
82
|
- ext/agoo/response.c
|
82
83
|
- ext/agoo/response.h
|
84
|
+
- ext/agoo/rhook.c
|
85
|
+
- ext/agoo/rhook.h
|
86
|
+
- ext/agoo/rlog.c
|
87
|
+
- ext/agoo/rlog.h
|
88
|
+
- ext/agoo/seg.h
|
83
89
|
- ext/agoo/server.c
|
84
90
|
- ext/agoo/server.h
|
85
91
|
- ext/agoo/sha1.c
|
@@ -140,7 +146,7 @@ signing_key:
|
|
140
146
|
specification_version: 4
|
141
147
|
summary: An HTTP server
|
142
148
|
test_files:
|
149
|
+
- test/log_test.rb
|
143
150
|
- test/rack_handler_test.rb
|
144
151
|
- test/base_handler_test.rb
|
145
152
|
- test/static_test.rb
|
146
|
-
- test/log_test.rb
|