iodine 0.7.60 → 0.8.0

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.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +15 -0
  3. data/.rspec +1 -0
  4. data/.yardopts +1 -3
  5. data/CHANGELOG.md +132 -12
  6. data/Gemfile +5 -7
  7. data/LICENSE.txt +1 -1
  8. data/README.md +147 -671
  9. data/Rakefile +9 -16
  10. data/examples/chatroom.nru +9 -0
  11. data/examples/client +74 -0
  12. data/examples/config-hello.nru +9 -0
  13. data/examples/config-hello.ru +11 -0
  14. data/examples/config-hijack.ru +13 -0
  15. data/examples/config-shootout.ru +43 -0
  16. data/examples/config.nru +120 -0
  17. data/examples/config.rb +37 -0
  18. data/examples/config.ru +42 -53
  19. data/examples/fake +24 -0
  20. data/examples/hello_neorack +137 -0
  21. data/examples/routes.nru +29 -0
  22. data/examples/routes.ru +42 -0
  23. data/exe/iodine +218 -258
  24. data/ext/iodine/extconf.rb +27 -100
  25. data/ext/iodine/fio-stl.h +128336 -0
  26. data/ext/iodine/fio-stl.md +26396 -0
  27. data/ext/iodine/iodine.c +213 -1393
  28. data/ext/iodine/iodine.h +250 -55
  29. data/ext/iodine/iodine_arg_helper.h +329 -0
  30. data/ext/iodine/iodine_caller.h +234 -25
  31. data/ext/iodine/iodine_cli.h +434 -0
  32. data/ext/iodine/iodine_compression.h +312 -0
  33. data/ext/iodine/iodine_connection.h +3484 -34
  34. data/ext/iodine/iodine_core.h +363 -0
  35. data/ext/iodine/iodine_crypto.h +1441 -0
  36. data/ext/iodine/iodine_defer.h +225 -4
  37. data/ext/iodine/iodine_json.h +738 -4
  38. data/ext/iodine/iodine_listener.h +263 -0
  39. data/ext/iodine/iodine_log.h +297 -0
  40. data/ext/iodine/iodine_minimap.h +543 -0
  41. data/ext/iodine/iodine_mustache.h +461 -4
  42. data/ext/iodine/iodine_pubsub_eng.h +729 -0
  43. data/ext/iodine/iodine_pubsub_history.h +547 -0
  44. data/ext/iodine/iodine_pubsub_msg.h +228 -0
  45. data/ext/iodine/iodine_redis.h +322 -0
  46. data/ext/iodine/iodine_store.h +418 -16
  47. data/ext/iodine/iodine_threads.h +279 -0
  48. data/ext/iodine/iodine_tls.h +515 -6
  49. data/ext/iodine/iodine_utils.h +923 -0
  50. data/iodine.gemspec +37 -42
  51. data/lib/iodine/benchmark.rb +1690 -0
  52. data/lib/iodine/documentation.rb +3085 -0
  53. data/lib/iodine/version.rb +17 -1
  54. data/lib/iodine.rb +54 -255
  55. data/logo.svg +36 -0
  56. data/mustache.md +55 -0
  57. data/sig/iodine.rbs +4 -0
  58. metadata +58 -184
  59. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  60. data/.github/workflows/ruby.yml +0 -42
  61. data/.gitignore +0 -21
  62. data/LIMITS.md +0 -41
  63. data/SPEC-PubSub-Draft.md +0 -159
  64. data/SPEC-WebSocket-Draft.md +0 -239
  65. data/bin/console +0 -22
  66. data/bin/info.md +0 -353
  67. data/bin/mustache_bench.rb +0 -100
  68. data/bin/poc/Gemfile.lock +0 -23
  69. data/bin/poc/README.md +0 -37
  70. data/bin/poc/config.ru +0 -66
  71. data/bin/poc/gemfile +0 -1
  72. data/bin/poc/www/index.html +0 -57
  73. data/examples/async_task.ru +0 -92
  74. data/examples/bates/README.md +0 -3
  75. data/examples/bates/config.ru +0 -342
  76. data/examples/bates/david+bold.pdf +0 -0
  77. data/examples/bates/public/drop-pdf.png +0 -0
  78. data/examples/bates/public/index.html +0 -600
  79. data/examples/echo.ru +0 -59
  80. data/examples/etag.ru +0 -16
  81. data/examples/hello.ru +0 -29
  82. data/examples/pubsub_engine.ru +0 -81
  83. data/examples/rack3.ru +0 -12
  84. data/examples/redis.ru +0 -70
  85. data/examples/shootout.ru +0 -73
  86. data/examples/sub-protocols.ru +0 -90
  87. data/examples/tcp_client.rb +0 -66
  88. data/examples/x-sendfile.ru +0 -14
  89. data/ext/iodine/fio.c +0 -11995
  90. data/ext/iodine/fio.h +0 -6371
  91. data/ext/iodine/fio_cli.c +0 -431
  92. data/ext/iodine/fio_cli.h +0 -189
  93. data/ext/iodine/fio_json_parser.h +0 -688
  94. data/ext/iodine/fio_siphash.c +0 -157
  95. data/ext/iodine/fio_siphash.h +0 -37
  96. data/ext/iodine/fio_tls.h +0 -129
  97. data/ext/iodine/fio_tls_missing.c +0 -649
  98. data/ext/iodine/fio_tls_openssl.c +0 -1106
  99. data/ext/iodine/fio_tmpfile.h +0 -50
  100. data/ext/iodine/fiobj.h +0 -44
  101. data/ext/iodine/fiobj4fio.h +0 -21
  102. data/ext/iodine/fiobj_ary.c +0 -333
  103. data/ext/iodine/fiobj_ary.h +0 -139
  104. data/ext/iodine/fiobj_data.c +0 -1187
  105. data/ext/iodine/fiobj_data.h +0 -167
  106. data/ext/iodine/fiobj_hash.c +0 -409
  107. data/ext/iodine/fiobj_hash.h +0 -176
  108. data/ext/iodine/fiobj_json.c +0 -622
  109. data/ext/iodine/fiobj_json.h +0 -68
  110. data/ext/iodine/fiobj_mem.h +0 -71
  111. data/ext/iodine/fiobj_mustache.c +0 -317
  112. data/ext/iodine/fiobj_mustache.h +0 -62
  113. data/ext/iodine/fiobj_numbers.c +0 -344
  114. data/ext/iodine/fiobj_numbers.h +0 -127
  115. data/ext/iodine/fiobj_str.c +0 -433
  116. data/ext/iodine/fiobj_str.h +0 -172
  117. data/ext/iodine/fiobject.c +0 -620
  118. data/ext/iodine/fiobject.h +0 -655
  119. data/ext/iodine/hpack.h +0 -1923
  120. data/ext/iodine/http.c +0 -2743
  121. data/ext/iodine/http.h +0 -1002
  122. data/ext/iodine/http1.c +0 -910
  123. data/ext/iodine/http1.h +0 -29
  124. data/ext/iodine/http1_parser.h +0 -878
  125. data/ext/iodine/http_internal.c +0 -1279
  126. data/ext/iodine/http_internal.h +0 -237
  127. data/ext/iodine/http_mime_parser.h +0 -350
  128. data/ext/iodine/iodine_caller.c +0 -230
  129. data/ext/iodine/iodine_connection.c +0 -941
  130. data/ext/iodine/iodine_defer.c +0 -420
  131. data/ext/iodine/iodine_fiobj2rb.h +0 -120
  132. data/ext/iodine/iodine_helpers.c +0 -282
  133. data/ext/iodine/iodine_helpers.h +0 -12
  134. data/ext/iodine/iodine_http.c +0 -1181
  135. data/ext/iodine/iodine_http.h +0 -23
  136. data/ext/iodine/iodine_json.c +0 -302
  137. data/ext/iodine/iodine_mustache.c +0 -567
  138. data/ext/iodine/iodine_pubsub.c +0 -580
  139. data/ext/iodine/iodine_pubsub.h +0 -26
  140. data/ext/iodine/iodine_rack_io.c +0 -273
  141. data/ext/iodine/iodine_rack_io.h +0 -20
  142. data/ext/iodine/iodine_store.c +0 -148
  143. data/ext/iodine/iodine_tcp.c +0 -346
  144. data/ext/iodine/iodine_tcp.h +0 -13
  145. data/ext/iodine/iodine_tls.c +0 -261
  146. data/ext/iodine/mustache_parser.h +0 -1546
  147. data/ext/iodine/redis_engine.c +0 -957
  148. data/ext/iodine/redis_engine.h +0 -79
  149. data/ext/iodine/resp_parser.h +0 -317
  150. data/ext/iodine/websocket_parser.h +0 -506
  151. data/ext/iodine/websockets.c +0 -743
  152. data/ext/iodine/websockets.h +0 -185
  153. data/lib/iodine/connection.rb +0 -61
  154. data/lib/iodine/json.rb +0 -42
  155. data/lib/iodine/mustache.rb +0 -113
  156. data/lib/iodine/pubsub.rb +0 -55
  157. data/lib/iodine/rack_utils.rb +0 -43
  158. data/lib/iodine/tls.rb +0 -16
  159. data/lib/rack/handler/iodine.rb +0 -33
  160. data/logo.png +0 -0
@@ -1,79 +0,0 @@
1
- /*
2
- Copyright: Boaz segev, 2016-2019
3
- License: MIT
4
-
5
- Feel free to copy, use and enjoy according to the license provided.
6
- */
7
- #ifndef H_REDIS_ENGINE_H
8
- #define H_REDIS_ENGINE_H
9
-
10
- #include <fio.h>
11
- #include <fiobj.h>
12
-
13
- /* support C++ */
14
- #ifdef __cplusplus
15
- extern "C" {
16
- #endif
17
-
18
- /** possible arguments for the `redis_engine_create` function call */
19
- struct redis_engine_create_args {
20
- /** Redis server's address, defaults to localhost. */
21
- fio_str_info_s address;
22
- /** Redis server's port, defaults to 6379. */
23
- fio_str_info_s port;
24
- /** Redis server's password, if any. */
25
- fio_str_info_s auth;
26
- /** A `ping` will be sent every `ping_interval` interval or inactivity. */
27
- uint8_t ping_interval;
28
- };
29
-
30
- /**
31
- * See the {fio.h} file for documentation about engines.
32
- *
33
- * The engine is active only after facil.io starts running.
34
- *
35
- * A `ping` will be sent every `ping_interval` interval or inactivity. The
36
- * default value (0) will fallback to facil.io's maximum time of inactivity (5
37
- * minutes) before polling on the connection's protocol.
38
- *
39
- * function names speak for themselves ;-)
40
- *
41
- * Note: The Redis engine assumes it will stay alive until all the messages and
42
- * callbacks have been called (or facil.io exits)... If the engine is destroyed
43
- * midway, memory leaks might occur (and little puppies might cry).
44
- */
45
- fio_pubsub_engine_s *redis_engine_create(struct redis_engine_create_args);
46
- #define redis_engine_create(...) \
47
- redis_engine_create((struct redis_engine_create_args){__VA_ARGS__})
48
-
49
- /**
50
- * Sends a Redis command through the engine's connection.
51
- *
52
- * The response will be sent back using the optional callback. `udata` is passed
53
- * along untouched.
54
- *
55
- * The message will be resent on network failures, until a response validates
56
- * the fact that the command was sent (or the engine is destroyed).
57
- *
58
- * Note: NEVER call Pub/Sub commands using this function, as it will violate the
59
- * Redis connection's protocol (best case scenario, a disconnection will occur
60
- * before and messages are lost).
61
- */
62
- intptr_t redis_engine_send(fio_pubsub_engine_s *engine, FIOBJ command,
63
- void (*callback)(fio_pubsub_engine_s *e, FIOBJ reply,
64
- void *udata),
65
- void *udata);
66
-
67
- /**
68
- * See the {pubsub.h} file for documentation about engines.
69
- *
70
- * function names speak for themselves ;-)
71
- */
72
- void redis_engine_destroy(fio_pubsub_engine_s *engine);
73
-
74
- /* support C++ */
75
- #ifdef __cplusplus
76
- }
77
- #endif
78
-
79
- #endif /* H_REDIS_ENGINE_H */
@@ -1,317 +0,0 @@
1
- /*
2
- Copyright: Boaz segev, 2016-2019
3
- License: MIT
4
-
5
- Feel free to copy, use and enjoy according to the license provided.
6
- */
7
- #ifndef H_RESP_PARSER_H
8
- /**
9
- * This single file library is a RESP parser for Redis connections.
10
- *
11
- * To use this file, the `.c` file in which this file is included MUST define a
12
- * number of callbacks, as later inticated.
13
- *
14
- * When feeding the parser, the parser will inform of any trailing bytes (bytes
15
- * at the end of the buffer that could not be parsed). These bytes should be
16
- * resent to the parser along with more data. Zero is a valid return value.
17
- *
18
- * Note: mostly, callback return vaslues are ignored.
19
- */
20
- #define H_RESP_PARSER_H
21
-
22
- #ifndef _GNU_SOURCE
23
- #define _GNU_SOURCE
24
- #endif
25
-
26
- #include <stdint.h>
27
- #include <stdlib.h>
28
- #include <string.h>
29
-
30
- /* *****************************************************************************
31
- The Parser
32
- ***************************************************************************** */
33
-
34
- typedef struct resp_parser_s {
35
- /* for internal use - (array / object countdown) */
36
- intptr_t obj_countdown;
37
- /* for internal use - (string byte consumption) */
38
- intptr_t expecting;
39
- } resp_parser_s;
40
-
41
- /**
42
- * Returns the number of bytes to be resent. i.e., for a return value 5, the
43
- * last 5 bytes in the buffer need to be resent to the parser.
44
- */
45
- static size_t resp_parse(resp_parser_s *parser, const void *buffer,
46
- size_t length);
47
-
48
- /* *****************************************************************************
49
- Required Parser Callbacks (to be defined by the including file)
50
- ***************************************************************************** */
51
-
52
- /** a local static callback, called when the RESP message is complete. */
53
- static int resp_on_message(resp_parser_s *parser);
54
-
55
- /** a local static callback, called when a Number object is parsed. */
56
- static int resp_on_number(resp_parser_s *parser, int64_t num);
57
- /** a local static callback, called when a OK message is received. */
58
- static int resp_on_okay(resp_parser_s *parser);
59
- /** a local static callback, called when NULL is received. */
60
- static int resp_on_null(resp_parser_s *parser);
61
-
62
- /**
63
- * a local static callback, called when a String should be allocated.
64
- *
65
- * `str_len` is the expected number of bytes that will fill the final string
66
- * object, without any NUL byte marker (the string might be binary).
67
- *
68
- * If this function returns any value besides 0, parsing is stopped.
69
- */
70
- static int resp_on_start_string(resp_parser_s *parser, size_t str_len);
71
- /** a local static callback, called as String objects are streamed. */
72
- static int resp_on_string_chunk(resp_parser_s *parser, void *data, size_t len);
73
- /** a local static callback, called when a String object had finished streaming.
74
- */
75
- static int resp_on_end_string(resp_parser_s *parser);
76
-
77
- /** a local static callback, called an error message is received. */
78
- static int resp_on_err_msg(resp_parser_s *parser, void *data, size_t len);
79
-
80
- /**
81
- * a local static callback, called when an Array should be allocated.
82
- *
83
- * `array_len` is the expected number of objects that will fill the Array
84
- * object.
85
- *
86
- * There's no `resp_on_end_array` callback since the RESP protocol assumes the
87
- * message is finished along with the Array (`resp_on_message` is called).
88
- * However, just in case a non-conforming client/server sends nested Arrays, the
89
- * callback should test against possible overflow or nested Array endings.
90
- *
91
- * If this function returns any value besides 0, parsing is stopped.
92
- */
93
- static int resp_on_start_array(resp_parser_s *parser, size_t array_len);
94
-
95
- /** a local static callback, called when a parser / protocol error occurs. */
96
- static int resp_on_parser_error(resp_parser_s *parser);
97
-
98
- /* *****************************************************************************
99
- Seeking the new line...
100
- ***************************************************************************** */
101
-
102
- #if FIO_MEMCHAR
103
-
104
- /**
105
- * This seems to be faster on some systems, especially for smaller distances.
106
- *
107
- * On newer systems, `memchr` should be faster.
108
- */
109
- static inline int seek2ch(uint8_t **buffer, register const uint8_t *limit,
110
- const uint8_t c) {
111
- if (**buffer == c)
112
- return 1;
113
-
114
- #if !ALLOW_UNALIGNED_MEMORY_ACCESS || !defined(__x86_64__)
115
- /* too short for this mess */
116
- if ((uintptr_t)limit <= 16 + ((uintptr_t)*buffer & (~(uintptr_t)7)))
117
- goto finish;
118
-
119
- /* align memory */
120
- {
121
- const uint8_t *alignment =
122
- (uint8_t *)(((uintptr_t)(*buffer) & (~(uintptr_t)7)) + 8);
123
- if (limit >= alignment) {
124
- while (*buffer < alignment) {
125
- if (**buffer == c)
126
- return 1;
127
- *buffer += 1;
128
- }
129
- }
130
- }
131
- const uint8_t *limit64 = (uint8_t *)((uintptr_t)limit & (~(uintptr_t)7));
132
- #else
133
- const uint8_t *limit64 = (uint8_t *)limit - 7;
134
- #endif
135
- uint64_t wanted1 = 0x0101010101010101ULL * c;
136
- for (; *buffer < limit64; *buffer += 8) {
137
- const uint64_t eq1 = ~((*((uint64_t *)*buffer)) ^ wanted1);
138
- const uint64_t t0 = (eq1 & 0x7f7f7f7f7f7f7f7fllu) + 0x0101010101010101llu;
139
- const uint64_t t1 = (eq1 & 0x8080808080808080llu);
140
- if ((t0 & t1)) {
141
- break;
142
- }
143
- }
144
- #if !ALLOW_UNALIGNED_MEMORY_ACCESS || !defined(__x86_64__)
145
- finish:
146
- #endif
147
- while (*buffer < limit) {
148
- if (**buffer == c)
149
- return 1;
150
- (*buffer)++;
151
- }
152
- return 0;
153
- }
154
-
155
- #else
156
-
157
- /* a helper that seeks any char, converts it to NUL and returns 1 if found. */
158
- inline static uint8_t seek2ch(uint8_t **pos, const uint8_t *limit, uint8_t ch) {
159
- /* This is library based alternative that is sometimes slower */
160
- if (*pos >= limit || **pos == ch) {
161
- return 0;
162
- }
163
- uint8_t *tmp = (uint8_t *)memchr(*pos, ch, limit - (*pos));
164
- if (tmp) {
165
- *pos = tmp;
166
- return 1;
167
- }
168
- *pos = (uint8_t *)limit;
169
- return 0;
170
- }
171
-
172
- #endif
173
-
174
- /* *****************************************************************************
175
- Parsing RESP requests
176
- ***************************************************************************** */
177
-
178
- /**
179
- * Returns the number of bytes to be resent. i.e., for a return value 5, the
180
- * last 5 bytes in the buffer need to be resent to the parser.
181
- */
182
- static size_t resp_parse(resp_parser_s *parser, const void *buffer,
183
- size_t length) {
184
- if (!parser->obj_countdown)
185
- parser->obj_countdown = 1; /* always expect something... */
186
- uint8_t *pos = (uint8_t *)buffer;
187
- const uint8_t *stop = pos + length;
188
- while (pos < stop) {
189
- uint8_t *eol;
190
- if (parser->expecting) {
191
- if (pos + parser->expecting + 2 > stop) {
192
- /* read, but make sure the buffer includes the new line markers */
193
- size_t tmp = (size_t)((uintptr_t)stop - (uintptr_t)pos);
194
- if ((intptr_t)tmp >= parser->expecting)
195
- tmp = parser->expecting - 1;
196
- resp_on_string_chunk(parser, (void *)pos, tmp);
197
- parser->expecting -= tmp;
198
- return (size_t)((uintptr_t)stop - ((uintptr_t)pos + tmp)); /* 0 or 1 */
199
- } else {
200
- resp_on_string_chunk(parser, (void *)pos, parser->expecting);
201
- resp_on_end_string(parser);
202
- pos += parser->expecting;
203
- if (pos[0] == '\r')
204
- ++pos;
205
- if (pos[0] == '\n')
206
- ++pos;
207
- parser->expecting = 0;
208
- --parser->obj_countdown;
209
- if (parser->obj_countdown <= 0) {
210
- parser->obj_countdown = 1;
211
- if (resp_on_message(parser))
212
- goto finish;
213
- }
214
- continue;
215
- }
216
- }
217
- eol = pos;
218
- if (seek2ch(&eol, stop, '\n') == 0)
219
- break;
220
- switch (*pos) {
221
- case '+':
222
- if (pos[1] == 'O' && pos[2] == 'K' && pos[3] == '\r' && pos[4] == '\n') {
223
- resp_on_okay(parser);
224
- --parser->obj_countdown;
225
- break;
226
- }
227
- if (resp_on_start_string(parser,
228
- (size_t)((uintptr_t)eol - (uintptr_t)pos - 2))) {
229
- pos = eol + 1;
230
- goto finish;
231
- }
232
- resp_on_string_chunk(parser, (void *)(pos + 1),
233
- (size_t)((uintptr_t)eol - (uintptr_t)pos - 1));
234
- resp_on_end_string(parser);
235
- --parser->obj_countdown;
236
- break;
237
- case '-':
238
- resp_on_err_msg(parser, pos,
239
- (size_t)((uintptr_t)eol - (uintptr_t)pos - 1));
240
- --parser->obj_countdown;
241
- break;
242
- case '*': /* fallthrough */
243
- case '$': /* fallthrough */
244
- case ':': {
245
- uint8_t id = *pos;
246
- uint8_t inv = 0;
247
- int64_t i = 0;
248
- ++pos;
249
- if (pos[0] == '-') {
250
- inv = 1;
251
- ++pos;
252
- }
253
- while ((size_t)(pos[0] - (uint8_t)'0') <= 9) {
254
- i = (i * 10) + (pos[0] - ((uint8_t)'0'));
255
- ++pos;
256
- }
257
- if (inv)
258
- i = i * -1;
259
-
260
- switch (id) {
261
- case ':':
262
- resp_on_number(parser, i);
263
- --parser->obj_countdown;
264
- break;
265
- case '$':
266
- if (i < 0) {
267
- resp_on_null(parser);
268
- --parser->obj_countdown;
269
- } else if (i == 0) {
270
- resp_on_start_string(parser, 0);
271
- resp_on_end_string(parser);
272
- --parser->obj_countdown;
273
- eol += 2; /* consume the extra "\r\n" */
274
- } else {
275
- if (resp_on_start_string(parser, i)) {
276
- pos = eol + 1;
277
- goto finish;
278
- }
279
- parser->expecting = i;
280
- }
281
- break;
282
- case '*':
283
- if (i < 0) {
284
- resp_on_null(parser);
285
- } else {
286
- if (resp_on_start_array(parser, i)) {
287
- pos = eol + 1;
288
- goto finish;
289
- }
290
- parser->obj_countdown += i;
291
- }
292
- --parser->obj_countdown;
293
- break;
294
- }
295
- } break;
296
- default:
297
- if (!parser->obj_countdown && !parser->expecting) {
298
- /* possible (probable) inline command... for server authoring. */
299
- /* Not Supported, PRs are welcome. */
300
- resp_on_parser_error(parser);
301
- return (size_t)((uintptr_t)stop - (uintptr_t)pos);
302
- } else {
303
- resp_on_parser_error(parser);
304
- return (size_t)((uintptr_t)stop - (uintptr_t)pos);
305
- }
306
- }
307
- pos = eol + 1;
308
- if (parser->obj_countdown <= 0 && !parser->expecting) {
309
- parser->obj_countdown = 1;
310
- resp_on_message(parser);
311
- }
312
- }
313
- finish:
314
- return (size_t)((uintptr_t)stop - (uintptr_t)pos);
315
- }
316
-
317
- #endif /* H_RESP_PARSER_H */