agoo 2.5.5 → 2.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

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
@@ -9,38 +9,38 @@
9
9
  #include "err.h"
10
10
  #include "text.h"
11
11
 
12
- typedef struct _Page {
13
- Text resp;
12
+ typedef struct _agooPage {
13
+ agooText resp;
14
14
  char *path;
15
15
  time_t mtime;
16
16
  double last_check;
17
17
  bool immutable;
18
- } *Page;
18
+ } *agooPage;
19
19
 
20
- typedef struct _Dir {
21
- struct _Dir *next;
20
+ typedef struct _agooDir {
21
+ struct _agooDir *next;
22
22
  char *path;
23
23
  int plen;
24
- } *Dir;
24
+ } *agooDir;
25
25
 
26
- typedef struct _Group {
27
- struct _Group *next;
26
+ typedef struct _agooGroup {
27
+ struct _agooGroup *next;
28
28
  char *path;
29
29
  int plen;
30
- Dir dirs;
31
- } *Group;
30
+ agooDir dirs;
31
+ } *agooGroup;
32
32
 
33
- extern void pages_init();
34
- extern void pages_set_root(const char *root);
35
- extern void pages_cleanup();
33
+ extern void agoo_pages_init();
34
+ extern void agoo_pages_set_root(const char *root);
35
+ extern void agoo_pages_cleanup();
36
36
 
37
- extern Group group_create(const char *path);
38
- extern void group_add(Group g, const char *dir);
39
- extern Page group_get(Err err, const char *path, int plen);
37
+ extern agooGroup group_create(const char *path);
38
+ extern void group_add(agooGroup g, const char *dir);
39
+ extern agooPage group_get(agooErr err, const char *path, int plen);
40
40
 
41
- extern Page page_create(const char *path);
42
- extern Page page_immutable(Err err, const char *path, const char *content, int clen);
43
- extern Page page_get(Err err, const char *path, int plen);
44
- extern int mime_set(Err err, const char *key, const char *value);
41
+ extern agooPage agoo_page_create(const char *path);
42
+ extern agooPage agoo_page_immutable(agooErr err, const char *path, const char *content, int clen);
43
+ extern agooPage agoo_page_get(agooErr err, const char *path, int plen);
44
+ extern int mime_set(agooErr err, const char *key, const char *value);
45
45
 
46
- #endif /* AGOO_PAGE_H */
46
+ #endif // AGOO_PAGE_H
@@ -10,14 +10,14 @@
10
10
  #include "text.h"
11
11
  #include "upgraded.h"
12
12
 
13
- Pub
14
- pub_close(Upgraded up) {
15
- Pub p = (Pub)malloc(sizeof(struct _Pub));
13
+ agooPub
14
+ agoo_pub_close(agooUpgraded up) {
15
+ agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
16
16
 
17
17
  if (NULL != p) {
18
18
  DEBUG_ALLOC(mem_pub, p);
19
19
  p->next = NULL;
20
- p->kind = PUB_CLOSE;
20
+ p->kind = AGOO_PUB_CLOSE;
21
21
  p->up = up;
22
22
  p->subject = NULL;
23
23
  p->msg = NULL;
@@ -25,32 +25,32 @@ pub_close(Upgraded up) {
25
25
  return p;
26
26
  }
27
27
 
28
- Pub
29
- pub_subscribe(Upgraded up, const char *subject, int slen) {
30
- Pub p = (Pub)malloc(sizeof(struct _Pub));
28
+ agooPub
29
+ agoo_pub_subscribe(agooUpgraded up, const char *subject, int slen) {
30
+ agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
31
31
 
32
32
  if (NULL != p) {
33
33
  DEBUG_ALLOC(mem_pub, p);
34
34
  p->next = NULL;
35
- p->kind = PUB_SUB;
35
+ p->kind = AGOO_PUB_SUB;
36
36
  p->up = up;
37
- p->subject = subject_create(subject, slen);
37
+ p->subject = agoo_subject_create(subject, slen);
38
38
  p->msg = NULL;
39
39
  }
40
40
  return p;
41
41
  }
42
42
 
43
- Pub
44
- pub_unsubscribe(Upgraded up, const char *subject, int slen) {
45
- Pub p = (Pub)malloc(sizeof(struct _Pub));
43
+ agooPub
44
+ agoo_pub_unsubscribe(agooUpgraded up, const char *subject, int slen) {
45
+ agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
46
46
 
47
47
  if (NULL != p) {
48
48
  DEBUG_ALLOC(mem_pub, p);
49
49
  p->next = NULL;
50
- p->kind = PUB_UN;
50
+ p->kind = AGOO_PUB_UN;
51
51
  p->up = up;
52
52
  if (NULL != subject) {
53
- p->subject = subject_create(subject, slen);
53
+ p->subject = agoo_subject_create(subject, slen);
54
54
  } else {
55
55
  p->subject = NULL;
56
56
  }
@@ -59,71 +59,71 @@ pub_unsubscribe(Upgraded up, const char *subject, int slen) {
59
59
  return p;
60
60
  }
61
61
 
62
- Pub
63
- pub_publish(const char *subject, int slen, const char *message, size_t mlen) {
64
- Pub p = (Pub)malloc(sizeof(struct _Pub));
62
+ agooPub
63
+ agoo_pub_publish(const char *subject, int slen, const char *message, size_t mlen) {
64
+ agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
65
65
 
66
66
  if (NULL != p) {
67
67
  DEBUG_ALLOC(mem_pub, p);
68
68
  p->next = NULL;
69
- p->kind = PUB_MSG;
69
+ p->kind = AGOO_PUB_MSG;
70
70
  p->up = NULL;
71
- p->subject = subject_create(subject, slen);
71
+ p->subject = agoo_subject_create(subject, slen);
72
72
  // Allocate an extra 24 bytes so the message can be expanded in place
73
73
  // if a WebSocket or SSE write.
74
- p->msg = text_append(text_allocate((int)mlen + 24), message, (int)mlen);
75
- text_ref(p->msg);
74
+ p->msg = agoo_text_append(agoo_text_allocate((int)mlen + 24), message, (int)mlen);
75
+ agoo_text_ref(p->msg);
76
76
  }
77
77
  return p;
78
78
  }
79
79
 
80
- Pub
81
- pub_write(Upgraded up, const char *message, size_t mlen, bool bin) {
80
+ agooPub
81
+ agoo_pub_write(agooUpgraded up, const char *message, size_t mlen, bool bin) {
82
82
  // Allocate an extra 16 bytes so the message can be expanded in place if a
83
83
  // WebSocket write.
84
- Pub p = (Pub)malloc(sizeof(struct _Pub));
84
+ agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
85
85
 
86
86
  if (NULL != p) {
87
87
  DEBUG_ALLOC(mem_pub, p);
88
88
  p->next = NULL;
89
- p->kind = PUB_WRITE;
89
+ p->kind = AGOO_PUB_WRITE;
90
90
  p->up = up;
91
91
  p->subject = NULL;
92
92
  // Allocate an extra 16 bytes so the message can be expanded in place
93
93
  // if a WebSocket write.
94
- p->msg = text_append(text_allocate((int)mlen + 16), message, (int)mlen);
94
+ p->msg = agoo_text_append(agoo_text_allocate((int)mlen + 16), message, (int)mlen);
95
95
  p->msg->bin = bin;
96
- text_ref(p->msg);
96
+ agoo_text_ref(p->msg);
97
97
  }
98
98
  return p;
99
99
  }
100
100
 
101
- Pub
102
- pub_dup(Pub src) {
103
- Pub p = (Pub)malloc(sizeof(struct _Pub));
101
+ agooPub
102
+ agoo_pub_dup(agooPub src) {
103
+ agooPub p = (agooPub)malloc(sizeof(struct _agooPub));
104
104
 
105
105
  if (NULL != p) {
106
106
  DEBUG_ALLOC(mem_pub, p);
107
107
  p->next = NULL;
108
108
  p->kind = src->kind;
109
109
  p->up = src->up;
110
- p->subject = subject_create(src->subject->pattern, strlen(src->subject->pattern));
110
+ p->subject = agoo_subject_create(src->subject->pattern, strlen(src->subject->pattern));
111
111
  p->msg = src->msg;
112
- text_ref(p->msg);
112
+ agoo_text_ref(p->msg);
113
113
  }
114
114
  return p;
115
115
  }
116
116
 
117
117
  void
118
- pub_destroy(Pub pub) {
118
+ agoo_pub_destroy(agooPub pub) {
119
119
  if (NULL != pub->msg) {
120
- text_release(pub->msg);
120
+ agoo_text_release(pub->msg);
121
121
  }
122
122
  if (NULL != pub->subject) {
123
- subject_destroy(pub->subject);
123
+ agoo_subject_destroy(pub->subject);
124
124
  }
125
125
  if (NULL != pub->up) {
126
- upgraded_release(pub->up);
126
+ agoo_upgraded_release(pub->up);
127
127
  }
128
128
  DEBUG_FREE(mem_pub, pub);
129
129
  free(pub);
@@ -7,34 +7,34 @@
7
7
  #include <stdint.h>
8
8
  #include <stdlib.h>
9
9
 
10
- struct _Text;
11
- struct _Upgraded;
12
- struct _Subject;
10
+ struct _agooText;
11
+ struct _agooUpgraded;
12
+ struct _agooSubject;
13
13
 
14
14
  typedef enum {
15
- PUB_SUB = 'S',
16
- PUB_CLOSE = 'C',
17
- PUB_UN = 'U',
18
- PUB_MSG = 'M',
19
- PUB_WRITE = 'W',
20
- } PubKind;
15
+ AGOO_PUB_SUB = 'S',
16
+ AGOO_PUB_CLOSE = 'C',
17
+ AGOO_PUB_UN = 'U',
18
+ AGOO_PUB_MSG = 'M',
19
+ AGOO_PUB_WRITE = 'W',
20
+ } agooPubKind;
21
21
 
22
22
  // Generated by extened handlers and placed on the pub_queue to be pulled off
23
23
  // in the con_loop.
24
- typedef struct _Pub {
25
- struct _Pub *next;
26
- PubKind kind;
27
- struct _Upgraded *up;
28
- struct _Subject *subject;
29
- struct _Text *msg;
30
- } *Pub;
24
+ typedef struct _agooPub {
25
+ struct _agooPub *next;
26
+ agooPubKind kind;
27
+ struct _agooUpgraded *up;
28
+ struct _agooSubject *subject;
29
+ struct _agooText *msg;
30
+ } *agooPub;
31
31
 
32
- extern Pub pub_close(struct _Upgraded *up);
33
- extern Pub pub_subscribe(struct _Upgraded *up, const char *subject, int slen);
34
- extern Pub pub_unsubscribe(struct _Upgraded *up, const char *subject, int slen);
35
- extern Pub pub_publish(const char *subject, int slen, const char *message, size_t mlen);
36
- extern Pub pub_write(struct _Upgraded *up, const char *message, size_t mlen, bool bin);
37
- extern Pub pub_dup(Pub src);
38
- extern void pub_destroy(Pub pub);
32
+ extern agooPub agoo_pub_close(struct _agooUpgraded *up);
33
+ extern agooPub agoo_pub_subscribe(struct _agooUpgraded *up, const char *subject, int slen);
34
+ extern agooPub agoo_pub_unsubscribe(struct _agooUpgraded *up, const char *subject, int slen);
35
+ extern agooPub agoo_pub_publish(const char *subject, int slen, const char *message, size_t mlen);
36
+ extern agooPub agoo_pub_write(struct _agooUpgraded *up, const char *message, size_t mlen, bool bin);
37
+ extern agooPub agoo_pub_dup(agooPub src);
38
+ extern void agoo_pub_destroy(agooPub pub);
39
39
 
40
40
  #endif // AGOO_PUB_H
@@ -27,25 +27,25 @@
27
27
  //
28
28
 
29
29
  void
30
- queue_init(Queue q, size_t qsize) {
31
- queue_multi_init(q, qsize, false, false);
30
+ agoo_queue_init(agooQueue q, size_t qsize) {
31
+ agoo_queue_multi_init(q, qsize, false, false);
32
32
  }
33
33
 
34
34
  void
35
- queue_multi_init(Queue q, size_t qsize, bool multi_push, bool multi_pop) {
35
+ agoo_queue_multi_init(agooQueue q, size_t qsize, bool multi_push, bool multi_pop) {
36
36
  if (qsize < 4) {
37
37
  qsize = 4;
38
38
  }
39
- q->q = (QItem*)malloc(sizeof(QItem) * qsize);
39
+ q->q = (agooQItem*)malloc(sizeof(agooQItem) * qsize);
40
40
  DEBUG_ALLOC(mem_qitem, q->q)
41
41
  q->end = q->q + qsize;
42
42
 
43
- memset(q->q, 0, sizeof(QItem) * qsize);
44
- q->head = q->q;
45
- q->tail = q->q + 1;
46
- atomic_flag_clear(&q->push_lock);
47
- atomic_flag_clear(&q->pop_lock);
48
- q->wait_state = 0;
43
+ memset(q->q, 0, sizeof(agooQItem) * qsize);
44
+ atomic_init(&q->head, q->q);
45
+ atomic_init(&q->tail, q->q + 1);
46
+ agoo_atomic_flag_init(&q->push_lock);
47
+ agoo_atomic_flag_init(&q->pop_lock);
48
+ atomic_init(&q->wait_state, 0);
49
49
  q->multi_push = multi_push;
50
50
  q->multi_pop = multi_pop;
51
51
  // Create when/if needed.
@@ -54,7 +54,7 @@ queue_multi_init(Queue q, size_t qsize, bool multi_push, bool multi_pop) {
54
54
  }
55
55
 
56
56
  void
57
- queue_cleanup(Queue q) {
57
+ agoo_queue_cleanup(agooQueue q) {
58
58
  DEBUG_FREE(mem_qitem, q->q)
59
59
  free(q->q);
60
60
  q->q = NULL;
@@ -68,8 +68,8 @@ queue_cleanup(Queue q) {
68
68
  }
69
69
 
70
70
  void
71
- queue_push(Queue q, QItem item) {
72
- QItem *tail;
71
+ agoo_queue_push(agooQueue q, agooQItem item) {
72
+ agooQItem *tail;
73
73
 
74
74
  if (q->multi_push) {
75
75
  while (atomic_flag_test_and_set(&q->push_lock)) {
@@ -77,11 +77,11 @@ queue_push(Queue q, QItem item) {
77
77
  }
78
78
  }
79
79
  // Wait for head to move on.
80
- while (atomic_load(&q->head) == q->tail) {
80
+ while (atomic_load(&q->head) == atomic_load(&q->tail)) {
81
81
  dsleep(RETRY_SECS);
82
82
  }
83
- *q->tail = item;
84
- tail = q->tail + 1;
83
+ *(agooQItem*)atomic_load(&q->tail) = item;
84
+ tail = (agooQItem*)atomic_load(&q->tail) + 1;
85
85
 
86
86
  if (q->end <= tail) {
87
87
  tail = q->q;
@@ -90,39 +90,39 @@ queue_push(Queue q, QItem item) {
90
90
  if (q->multi_push) {
91
91
  atomic_flag_clear(&q->push_lock);
92
92
  }
93
- if (0 != q->wsock && WAITING == atomic_load(&q->wait_state)) {
93
+ if (0 != q->wsock && WAITING == (long)atomic_load(&q->wait_state)) {
94
94
  if (write(q->wsock, ".", 1)) {}
95
95
  atomic_store(&q->wait_state, NOTIFIED);
96
96
  }
97
97
  }
98
98
 
99
99
  void
100
- queue_wakeup(Queue q) {
100
+ agoo_queue_wakeup(agooQueue q) {
101
101
  if (0 != q->wsock) {
102
102
  if (write(q->wsock, ".", 1)) {}
103
103
  }
104
104
  }
105
105
 
106
- QItem
107
- queue_pop(Queue q, double timeout) {
108
- QItem item;
109
- QItem *next;
106
+ agooQItem
107
+ agoo_queue_pop(agooQueue q, double timeout) {
108
+ agooQItem item;
109
+ agooQItem *next;
110
110
 
111
111
  if (q->multi_pop) {
112
112
  while (atomic_flag_test_and_set(&q->pop_lock)) {
113
113
  dsleep(RETRY_SECS);
114
114
  }
115
115
  }
116
- item = *q->head;
116
+ item = *(agooQItem*)atomic_load(&q->head);
117
117
 
118
118
  if (NULL != item) {
119
- *q->head = NULL;
119
+ *(agooQItem*)atomic_load(&q->head) = NULL;
120
120
  if (q->multi_pop) {
121
121
  atomic_flag_clear(&q->pop_lock);
122
122
  }
123
123
  return item;
124
124
  }
125
- next = q->head + 1;
125
+ next = (agooQItem*)atomic_load(&q->head) + 1;
126
126
 
127
127
  if (q->end <= next) {
128
128
  next = q->q;
@@ -137,17 +137,16 @@ queue_pop(Queue q, double timeout) {
137
137
  }
138
138
  return NULL;
139
139
  }
140
- pa.fd = queue_listen(q);
140
+ pa.fd = agoo_queue_listen(q);
141
141
  pa.events = POLLIN;
142
142
  pa.revents = 0;
143
143
  if (0 < poll(&pa, 1, WAIT_MSECS)) {
144
- queue_release(q);
144
+ agoo_queue_release(q);
145
145
  }
146
146
  }
147
147
  atomic_store(&q->head, next);
148
-
149
- item = *q->head;
150
- *q->head = NULL;
148
+ item = *next;
149
+ *next = NULL;
151
150
  if (q->multi_pop) {
152
151
  atomic_flag_clear(&q->pop_lock);
153
152
  }
@@ -156,21 +155,21 @@ queue_pop(Queue q, double timeout) {
156
155
 
157
156
  // Called by the popper usually.
158
157
  bool
159
- queue_empty(Queue q) {
160
- QItem *head = atomic_load(&q->head);
161
- QItem *next = head + 1;
158
+ agoo_queue_empty(agooQueue q) {
159
+ agooQItem *head = atomic_load(&q->head);
160
+ agooQItem *next = head + 1;
162
161
 
163
162
  if (q->end <= next) {
164
163
  next = q->q;
165
164
  }
166
- if (NULL == *head && q->tail == next) {
165
+ if (NULL == *head && atomic_load(&q->tail) == next) {
167
166
  return true;
168
167
  }
169
168
  return false;
170
169
  }
171
170
 
172
171
  int
173
- queue_listen(Queue q) {
172
+ agoo_queue_listen(agooQueue q) {
174
173
  if (0 == q->rsock) {
175
174
  int fd[2];
176
175
 
@@ -187,7 +186,7 @@ queue_listen(Queue q) {
187
186
  }
188
187
 
189
188
  void
190
- queue_release(Queue q) {
189
+ agoo_queue_release(agooQueue q) {
191
190
  char buf[8];
192
191
 
193
192
  // clear pipe
@@ -197,9 +196,9 @@ queue_release(Queue q) {
197
196
  }
198
197
 
199
198
  int
200
- queue_count(Queue q) {
199
+ agoo_queue_count(agooQueue q) {
201
200
  int size = (int)(q->end - q->q);
202
201
 
203
- return (q->tail - q->head + size) % size;
202
+ return ((agooQItem*)atomic_load(&q->tail) - (agooQItem*)atomic_load(&q->head) + size) % size;
204
203
  }
205
204