agoo 2.5.5 → 2.5.6

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.

Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/README.md +1 -1
  4. data/ext/agoo/agoo.c +4 -3
  5. data/ext/agoo/atomic.h +120 -0
  6. data/ext/agoo/bind.c +52 -52
  7. data/ext/agoo/bind.h +13 -13
  8. data/ext/agoo/con.c +499 -481
  9. data/ext/agoo/con.h +47 -39
  10. data/ext/agoo/debug.c +42 -42
  11. data/ext/agoo/debug.h +1 -1
  12. data/ext/agoo/doc.c +17 -17
  13. data/ext/agoo/doc.h +12 -12
  14. data/ext/agoo/err.c +18 -18
  15. data/ext/agoo/err.h +27 -27
  16. data/ext/agoo/error_stream.c +9 -9
  17. data/ext/agoo/extconf.rb +3 -0
  18. data/ext/agoo/gqlintro.c +43 -43
  19. data/ext/agoo/gqlintro.h +1 -1
  20. data/ext/agoo/gqlvalue.c +131 -131
  21. data/ext/agoo/gqlvalue.h +32 -32
  22. data/ext/agoo/graphql.c +158 -158
  23. data/ext/agoo/graphql.h +34 -33
  24. data/ext/agoo/hook.c +15 -14
  25. data/ext/agoo/hook.h +18 -14
  26. data/ext/agoo/http.c +14 -14
  27. data/ext/agoo/http.h +4 -4
  28. data/ext/agoo/kinds.h +5 -5
  29. data/ext/agoo/log.c +232 -224
  30. data/ext/agoo/log.h +93 -93
  31. data/ext/agoo/method.h +17 -17
  32. data/ext/agoo/page.c +88 -86
  33. data/ext/agoo/page.h +21 -21
  34. data/ext/agoo/pub.c +36 -36
  35. data/ext/agoo/pub.h +23 -23
  36. data/ext/agoo/queue.c +37 -38
  37. data/ext/agoo/queue.h +20 -19
  38. data/ext/agoo/rack_logger.c +13 -13
  39. data/ext/agoo/ready.c +357 -0
  40. data/ext/agoo/ready.h +41 -0
  41. data/ext/agoo/req.c +11 -11
  42. data/ext/agoo/req.h +30 -31
  43. data/ext/agoo/request.c +46 -46
  44. data/ext/agoo/request.h +2 -2
  45. data/ext/agoo/res.c +40 -18
  46. data/ext/agoo/res.h +14 -14
  47. data/ext/agoo/response.c +6 -6
  48. data/ext/agoo/response.h +9 -9
  49. data/ext/agoo/rhook.c +3 -3
  50. data/ext/agoo/rhook.h +1 -1
  51. data/ext/agoo/rlog.c +47 -42
  52. data/ext/agoo/rlog.h +0 -1
  53. data/ext/agoo/rresponse.c +33 -33
  54. data/ext/agoo/rresponse.h +1 -1
  55. data/ext/agoo/rserver.c +184 -175
  56. data/ext/agoo/rserver.h +2 -2
  57. data/ext/agoo/rupgraded.c +41 -41
  58. data/ext/agoo/rupgraded.h +3 -3
  59. data/ext/agoo/sdl.c +80 -80
  60. data/ext/agoo/sdl.h +1 -1
  61. data/ext/agoo/seg.h +2 -2
  62. data/ext/agoo/server.c +143 -117
  63. data/ext/agoo/server.h +43 -42
  64. data/ext/agoo/sse.c +7 -7
  65. data/ext/agoo/sse.h +4 -4
  66. data/ext/agoo/subject.c +5 -5
  67. data/ext/agoo/subject.h +6 -6
  68. data/ext/agoo/text.c +21 -21
  69. data/ext/agoo/text.h +14 -13
  70. data/ext/agoo/upgraded.c +41 -40
  71. data/ext/agoo/upgraded.h +41 -40
  72. data/ext/agoo/websocket.c +42 -42
  73. data/ext/agoo/websocket.h +16 -16
  74. data/lib/agoo/version.rb +1 -1
  75. data/test/static_test.rb +2 -0
  76. metadata +5 -5
  77. data/ext/agoo/log_queue.h +0 -30
  78. data/ext/agoo/sub.c +0 -111
  79. data/ext/agoo/sub.h +0 -36
@@ -0,0 +1,41 @@
1
+ // Copyright (c) 2018, Peter Ohler, All rights reserved.
2
+
3
+ #ifndef AGOO_READY_H
4
+ #define AGOO_READY_H
5
+
6
+ #include <stdbool.h>
7
+ #include <stdint.h>
8
+ #include <sys/types.h>
9
+
10
+ #include "err.h"
11
+
12
+ typedef enum {
13
+ AGOO_READY_NONE = '\0',
14
+ AGOO_READY_IN = 'i',
15
+ AGOO_READY_OUT = 'o',
16
+ AGOO_READY_BOTH = 'b',
17
+ } agooReadyIO;
18
+
19
+ typedef struct _agooReady *agooReady;
20
+
21
+ typedef struct _agooHandler {
22
+ agooReadyIO (*io)(void *ctx);
23
+ // return false to remove connection
24
+ bool (*check)(void *ctx, double now);
25
+ bool (*read)(agooReady ready, void *ctx);
26
+ bool (*write)(void *ctx);
27
+ void (*error)(void *ctx);
28
+ void (*destroy)(void *ctx);
29
+ } *agooHandler;
30
+
31
+ extern agooReady agoo_ready_create(agooErr err);
32
+ extern void agoo_ready_destroy(agooReady ready);
33
+ extern int agoo_ready_add(agooErr err,
34
+ agooReady ready,
35
+ int fd,
36
+ agooHandler handler,
37
+ void *ctx);
38
+ extern int agoo_ready_go(agooErr err, agooReady ready);
39
+ extern void agoo_ready_iterate(agooReady ready, void (*cb)(void *ctx, void *arg), void *arg);
40
+
41
+ #endif // AGOO_READY_H
@@ -10,15 +10,15 @@
10
10
  #include "server.h"
11
11
  #include "req.h"
12
12
 
13
- Req
14
- req_create(size_t mlen) {
15
- size_t size = mlen + sizeof(struct _Req) - 7;
16
- Req req = (Req)malloc(size);
13
+ agooReq
14
+ agoo_req_create(size_t mlen) {
15
+ size_t size = mlen + sizeof(struct _agooReq) - 7;
16
+ agooReq req = (agooReq)malloc(size);
17
17
 
18
18
  if (NULL != req) {
19
19
  DEBUG_ALLOC(mem_req, req);
20
20
  memset(req, 0, size);
21
- req->env = the_server.env_nil_value;
21
+ req->env = agoo_server.env_nil_value;
22
22
  req->mlen = mlen;
23
23
  req->hook = NULL;
24
24
  }
@@ -26,7 +26,7 @@ req_create(size_t mlen) {
26
26
  }
27
27
 
28
28
  void
29
- req_destroy(Req req) {
29
+ agoo_req_destroy(agooReq req) {
30
30
  DEBUG_FREE(mem_req, req);
31
31
  if (NULL != req->hook && PUSH_HOOK == req->hook->type) {
32
32
  free(req->hook);
@@ -35,11 +35,11 @@ req_destroy(Req req) {
35
35
  }
36
36
 
37
37
  const char*
38
- req_host(Req r, int *lenp) {
38
+ agoo_req_host(agooReq r, int *lenp) {
39
39
  const char *host;
40
40
  const char *colon;
41
41
 
42
- if (NULL == (host = con_header_value(r->header.start, r->header.len, "Host", lenp))) {
42
+ if (NULL == (host = agoo_con_header_value(r->header.start, r->header.len, "Host", lenp))) {
43
43
  return NULL;
44
44
  }
45
45
  for (colon = host + *lenp - 1; host < colon; colon--) {
@@ -54,12 +54,12 @@ req_host(Req r, int *lenp) {
54
54
  }
55
55
 
56
56
  int
57
- req_port(Req r) {
57
+ agoo_req_port(agooReq r) {
58
58
  int len;
59
59
  const char *host;
60
60
  const char *colon;
61
61
 
62
- if (NULL == (host = con_header_value(r->header.start, r->header.len, "Host", &len))) {
62
+ if (NULL == (host = agoo_con_header_value(r->header.start, r->header.len, "Host", &len))) {
63
63
  return 0;
64
64
  }
65
65
  for (colon = host + len - 1; host < colon; colon--) {
@@ -74,7 +74,7 @@ req_port(Req r) {
74
74
  }
75
75
 
76
76
  const char*
77
- req_query_value(Req r, const char *key, int klen, int *vlenp) {
77
+ agoo_req_query_value(agooReq r, const char *key, int klen, int *vlenp) {
78
78
  const char *value;
79
79
 
80
80
  if (NULL != (value = strstr(r->query.start, key))) {
@@ -8,41 +8,40 @@
8
8
  #include "hook.h"
9
9
  #include "kinds.h"
10
10
 
11
- struct _Server;
12
- struct _Upgraded;
13
- struct _Res;
11
+ struct _agooUpgraded;
12
+ struct _agooRes;
14
13
 
15
14
  typedef enum {
16
- UP_NONE = '\0',
17
- UP_WS = 'W',
18
- UP_SSE = 'S',
19
- } Upgrade;
15
+ AGOO_UP_NONE = '\0',
16
+ AGOO_UP_WS = 'W',
17
+ AGOO_UP_SSE = 'S',
18
+ } agooUpgrade;
20
19
 
21
- typedef struct _Str {
20
+ typedef struct _agooStr {
22
21
  char *start;
23
22
  unsigned int len;
24
- } *Str;
25
-
26
- typedef struct _Req {
27
- Method method;
28
- struct _Res *res;
29
-
30
- Upgrade upgrade;
31
- struct _Upgraded *up;
32
- struct _Str path;
33
- struct _Str query;
34
- struct _Str header;
35
- struct _Str body;
36
- void *env;
37
- Hook hook;
38
- size_t mlen; // allocated msg length
39
- char msg[8]; // expanded to be full message
40
- } *Req;
41
-
42
- extern Req req_create(size_t mlen);
43
- extern void req_destroy(Req req);
44
- extern const char* req_host(Req r, int *lenp);
45
- extern int req_port(Req r);
46
- extern const char* req_query_value(Req r, const char *key, int klen, int *vlenp);
23
+ } *agooStr;
24
+
25
+ typedef struct _agooReq {
26
+ agooMethod method;
27
+ struct _agooRes *res;
28
+
29
+ agooUpgrade upgrade;
30
+ struct _agooUpgraded *up;
31
+ struct _agooStr path;
32
+ struct _agooStr query;
33
+ struct _agooStr header;
34
+ struct _agooStr body;
35
+ void *env;
36
+ agooHook hook;
37
+ size_t mlen; // allocated msg length
38
+ char msg[8]; // expanded to be full message
39
+ } *agooReq;
40
+
41
+ extern agooReq agoo_req_create(size_t mlen);
42
+ extern void agoo_req_destroy(agooReq req);
43
+ extern const char* agoo_req_host(agooReq r, int *lenp);
44
+ extern int agoo_req_port(agooReq r);
45
+ extern const char* agoo_req_query_value(agooReq r, const char *key, int klen, int *vlenp);
47
46
 
48
47
  #endif // AGOO_REQ_H
@@ -62,21 +62,21 @@ static const char accept_key[] = "Accept";
62
62
  static const char event_stream_val[] = "text/event-stream";
63
63
 
64
64
  static VALUE
65
- req_method(Req r) {
65
+ req_method(agooReq r) {
66
66
  VALUE m;
67
67
 
68
68
  if (NULL == r) {
69
69
  rb_raise(rb_eArgError, "Request is no longer valid.");
70
70
  }
71
71
  switch (r->method) {
72
- case CONNECT: m = connect_val; break;
73
- case DELETE: m = delete_val; break;
74
- case GET: m = get_val; break;
75
- case HEAD: m = head_val; break;
76
- case OPTIONS: m = options_val; break;
77
- case POST: m = post_val; break;
78
- case PUT: m = put_val; break;
79
- case PATCH: m = patch_val; break;
72
+ case AGOO_CONNECT: m = connect_val; break;
73
+ case AGOO_DELETE: m = delete_val; break;
74
+ case AGOO_GET: m = get_val; break;
75
+ case AGOO_HEAD: m = head_val; break;
76
+ case AGOO_OPTIONS: m = options_val; break;
77
+ case AGOO_POST: m = post_val; break;
78
+ case AGOO_PUT: m = put_val; break;
79
+ case AGOO_PATCH: m = patch_val; break;
80
80
  default: m = Qnil; break;
81
81
  }
82
82
  return m;
@@ -90,11 +90,11 @@ req_method(Req r) {
90
90
  */
91
91
  static VALUE
92
92
  method(VALUE self) {
93
- return req_method((Req)DATA_PTR(self));
93
+ return req_method((agooReq)DATA_PTR(self));
94
94
  }
95
95
 
96
96
  static VALUE
97
- req_script_name(Req r) {
97
+ req_script_name(agooReq r) {
98
98
  // The logic is a bit tricky here and for path_info. If the HTTP path is /
99
99
  // then the script_name must be empty and the path_info will be /. All
100
100
  // other cases are handled with the full path in script_name and path_info
@@ -115,11 +115,11 @@ req_script_name(Req r) {
115
115
  */
116
116
  static VALUE
117
117
  script_name(VALUE self) {
118
- return req_script_name((Req)DATA_PTR(self));
118
+ return req_script_name((agooReq)DATA_PTR(self));
119
119
  }
120
120
 
121
121
  static VALUE
122
- req_path_info(Req r) {
122
+ req_path_info(agooReq r) {
123
123
  if (NULL == r) {
124
124
  rb_raise(rb_eArgError, "Request is no longer valid.");
125
125
  }
@@ -143,11 +143,11 @@ req_path_info(Req r) {
143
143
  */
144
144
  static VALUE
145
145
  path_info(VALUE self) {
146
- return req_path_info((Req)DATA_PTR(self));
146
+ return req_path_info((agooReq)DATA_PTR(self));
147
147
  }
148
148
 
149
149
  static VALUE
150
- req_query_string(Req r) {
150
+ req_query_string(agooReq r) {
151
151
  if (NULL == r) {
152
152
  rb_raise(rb_eArgError, "Request is no longer valid.");
153
153
  }
@@ -165,18 +165,18 @@ req_query_string(Req r) {
165
165
  */
166
166
  static VALUE
167
167
  query_string(VALUE self) {
168
- return req_query_string((Req)DATA_PTR(self));
168
+ return req_query_string((agooReq)DATA_PTR(self));
169
169
  }
170
170
 
171
171
  static VALUE
172
- req_server_name(Req r) {
172
+ req_server_name(agooReq r) {
173
173
  int len;
174
174
  const char *host;
175
175
 
176
176
  if (NULL == r) {
177
177
  rb_raise(rb_eArgError, "Request is no longer valid.");
178
178
  }
179
- if (NULL == (host = req_host(r, &len))) {
179
+ if (NULL == (host = agoo_req_host(r, &len))) {
180
180
  return rb_str_new2("unknown");
181
181
  }
182
182
  return rb_str_new(host, len);
@@ -190,11 +190,11 @@ req_server_name(Req r) {
190
190
  */
191
191
  static VALUE
192
192
  server_name(VALUE self) {
193
- return req_server_name((Req)DATA_PTR(self));
193
+ return req_server_name((agooReq)DATA_PTR(self));
194
194
  }
195
195
 
196
196
  static VALUE
197
- req_server_port(Req r) {
197
+ req_server_port(agooReq r) {
198
198
  int len;
199
199
  const char *host;
200
200
  const char *colon;
@@ -202,7 +202,7 @@ req_server_port(Req r) {
202
202
  if (NULL == r) {
203
203
  rb_raise(rb_eArgError, "Request is no longer valid.");
204
204
  }
205
- if (NULL == (host = con_header_value(r->header.start, r->header.len, "Host", &len))) {
205
+ if (NULL == (host = agoo_con_header_value(r->header.start, r->header.len, "Host", &len))) {
206
206
  return Qnil;
207
207
  }
208
208
  for (colon = host + len - 1; host < colon; colon--) {
@@ -224,14 +224,14 @@ req_server_port(Req r) {
224
224
  */
225
225
  static VALUE
226
226
  server_port(VALUE self) {
227
- return req_server_port((Req)DATA_PTR(self));
227
+ return req_server_port((agooReq)DATA_PTR(self));
228
228
  }
229
229
 
230
230
  static VALUE
231
- req_rack_upgrade(Req r) {
231
+ req_rack_upgrade(agooReq r) {
232
232
  switch (r->upgrade) {
233
- case UP_WS: return websocket_sym;
234
- case UP_SSE: return sse_sym;
233
+ case AGOO_UP_WS: return websocket_sym;
234
+ case AGOO_UP_SSE: return sse_sym;
235
235
  default: return Qnil;
236
236
  }
237
237
  }
@@ -244,7 +244,7 @@ req_rack_upgrade(Req r) {
244
244
  */
245
245
  static VALUE
246
246
  rack_upgrade(VALUE self) {
247
- return req_rack_upgrade((Req)DATA_PTR(self));
247
+ return req_rack_upgrade((agooReq)DATA_PTR(self));
248
248
  }
249
249
 
250
250
  /* Document-method: rack_version
@@ -259,7 +259,7 @@ rack_version(VALUE self) {
259
259
  }
260
260
 
261
261
  static VALUE
262
- req_rack_url_scheme(Req r) {
262
+ req_rack_url_scheme(agooReq r) {
263
263
  // TBD http or https when ssl is supported
264
264
  return http_val;
265
265
  }
@@ -272,11 +272,11 @@ req_rack_url_scheme(Req r) {
272
272
  */
273
273
  static VALUE
274
274
  rack_url_scheme(VALUE self) {
275
- return req_rack_url_scheme((Req)DATA_PTR(self));
275
+ return req_rack_url_scheme((agooReq)DATA_PTR(self));
276
276
  }
277
277
 
278
278
  static VALUE
279
- req_rack_input(Req r) {
279
+ req_rack_input(agooReq r) {
280
280
  if (NULL == r) {
281
281
  rb_raise(rb_eArgError, "Request is no longer valid.");
282
282
  }
@@ -295,11 +295,11 @@ req_rack_input(Req r) {
295
295
  */
296
296
  static VALUE
297
297
  rack_input(VALUE self) {
298
- return req_rack_input((Req)DATA_PTR(self));
298
+ return req_rack_input((agooReq)DATA_PTR(self));
299
299
  }
300
300
 
301
301
  static VALUE
302
- req_rack_errors(Req r) {
302
+ req_rack_errors(agooReq r) {
303
303
  return error_stream_new();
304
304
  }
305
305
 
@@ -312,15 +312,15 @@ req_rack_errors(Req r) {
312
312
  */
313
313
  static VALUE
314
314
  rack_errors(VALUE self) {
315
- return req_rack_errors((Req)DATA_PTR(self));
315
+ return req_rack_errors((agooReq)DATA_PTR(self));
316
316
  }
317
317
 
318
318
  static VALUE
319
- req_rack_multithread(Req r) {
319
+ req_rack_multithread(agooReq r) {
320
320
  if (NULL == r) {
321
321
  rb_raise(rb_eArgError, "Request is no longer valid.");
322
322
  }
323
- if (1 < the_server.thread_cnt) {
323
+ if (1 < agoo_server.thread_cnt) {
324
324
  return Qtrue;
325
325
  }
326
326
  return Qfalse;
@@ -334,7 +334,7 @@ req_rack_multithread(Req r) {
334
334
  */
335
335
  static VALUE
336
336
  rack_multithread(VALUE self) {
337
- return req_rack_multithread((Req)DATA_PTR(self));
337
+ return req_rack_multithread((agooReq)DATA_PTR(self));
338
338
  }
339
339
 
340
340
  /* Document-method: rack_multiprocess
@@ -394,7 +394,7 @@ add_header_value(VALUE hh, const char *key, int klen, const char *val, int vlen)
394
394
 
395
395
  // TBD req.c
396
396
  static void
397
- fill_headers(Req r, VALUE hash) {
397
+ fill_headers(agooReq r, VALUE hash) {
398
398
  char *h = r->header.start;
399
399
  char *end = h + r->header.len + 1; // +1 for last \r
400
400
  char *key = h;
@@ -448,7 +448,7 @@ fill_headers(Req r, VALUE hash) {
448
448
  } else if (sizeof(accept_key) - 1 == klen && 0 == strncasecmp(key, accept_key, sizeof(accept_key) - 1)) {
449
449
  if (sizeof(event_stream_val) - 1 == vend - val &&
450
450
  0 == strncasecmp(val, event_stream_val, sizeof(event_stream_val) - 1)) {
451
- r->upgrade = UP_SSE;
451
+ r->upgrade = AGOO_UP_SSE;
452
452
  }
453
453
  }
454
454
  key = h + 1;
@@ -461,7 +461,7 @@ fill_headers(Req r, VALUE hash) {
461
461
  }
462
462
  }
463
463
  if (upgrade && ws) {
464
- r->upgrade = UP_WS;
464
+ r->upgrade = AGOO_UP_WS;
465
465
  }
466
466
  }
467
467
 
@@ -473,7 +473,7 @@ fill_headers(Req r, VALUE hash) {
473
473
  */
474
474
  static VALUE
475
475
  headers(VALUE self) {
476
- Req r = DATA_PTR(self);
476
+ agooReq r = DATA_PTR(self);
477
477
  volatile VALUE h;
478
478
 
479
479
  if (NULL == r) {
@@ -494,7 +494,7 @@ headers(VALUE self) {
494
494
  */
495
495
  static VALUE
496
496
  body(VALUE self) {
497
- Req r = DATA_PTR(self);
497
+ agooReq r = DATA_PTR(self);
498
498
 
499
499
  if (NULL == r) {
500
500
  rb_raise(rb_eArgError, "Request is no longer valid.");
@@ -506,7 +506,7 @@ body(VALUE self) {
506
506
  }
507
507
 
508
508
  static VALUE
509
- req_rack_logger(Req req) {
509
+ req_rack_logger(agooReq req) {
510
510
  return rack_logger_new();
511
511
  }
512
512
 
@@ -521,7 +521,7 @@ req_rack_logger(Req req) {
521
521
  */
522
522
  static VALUE
523
523
  rack_logger(VALUE self) {
524
- return req_rack_logger((Req)DATA_PTR(self));
524
+ return req_rack_logger((agooReq)DATA_PTR(self));
525
525
  }
526
526
 
527
527
  /* Document-class: Agoo::Request
@@ -530,7 +530,7 @@ rack_logger(VALUE self) {
530
530
  * request is a more efficient encapsulation of the rack environment.
531
531
  */
532
532
  VALUE
533
- request_env(Req req, VALUE self) {
533
+ request_env(agooReq req, VALUE self) {
534
534
  if (Qnil == (VALUE)req->env) {
535
535
  volatile VALUE env = rb_hash_new();
536
536
 
@@ -580,7 +580,7 @@ request_env(Req req, VALUE self) {
580
580
  */
581
581
  static VALUE
582
582
  to_h(VALUE self) {
583
- Req r = DATA_PTR(self);
583
+ agooReq r = DATA_PTR(self);
584
584
 
585
585
  if (NULL == r) {
586
586
  rb_raise(rb_eArgError, "Request is no longer valid.");
@@ -609,7 +609,7 @@ to_s(VALUE self) {
609
609
  */
610
610
  static VALUE
611
611
  call(VALUE self) {
612
- Req r = DATA_PTR(self);
612
+ agooReq r = DATA_PTR(self);
613
613
  VALUE args[1];
614
614
  volatile VALUE io;
615
615
 
@@ -630,7 +630,7 @@ call(VALUE self) {
630
630
  }
631
631
 
632
632
  VALUE
633
- request_wrap(Req req) {
633
+ request_wrap(agooReq req) {
634
634
  // freed from the C side of things
635
635
  return Data_Wrap_Struct(req_class, NULL, NULL, req);
636
636
  }