iodine 0.7.59 → 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.
- checksums.yaml +4 -4
- data/.clang-format +15 -0
- data/.rspec +1 -0
- data/.yardopts +1 -3
- data/CHANGELOG.md +132 -12
- data/Gemfile +5 -7
- data/LICENSE.txt +1 -1
- data/README.md +147 -671
- data/Rakefile +9 -16
- data/examples/chatroom.nru +9 -0
- data/examples/client +74 -0
- data/examples/config-hello.nru +9 -0
- data/examples/config-hello.ru +11 -0
- data/examples/config-hijack.ru +13 -0
- data/examples/config-shootout.ru +43 -0
- data/examples/config.nru +120 -0
- data/examples/config.rb +37 -0
- data/examples/config.ru +42 -53
- data/examples/fake +24 -0
- data/examples/hello_neorack +137 -0
- data/examples/routes.nru +29 -0
- data/examples/routes.ru +42 -0
- data/exe/iodine +218 -258
- data/ext/iodine/extconf.rb +27 -100
- data/ext/iodine/fio-stl.h +128336 -0
- data/ext/iodine/fio-stl.md +26396 -0
- data/ext/iodine/iodine.c +213 -1393
- data/ext/iodine/iodine.h +250 -55
- data/ext/iodine/iodine_arg_helper.h +329 -0
- data/ext/iodine/iodine_caller.h +234 -25
- data/ext/iodine/iodine_cli.h +434 -0
- data/ext/iodine/iodine_compression.h +312 -0
- data/ext/iodine/iodine_connection.h +3484 -34
- data/ext/iodine/iodine_core.h +363 -0
- data/ext/iodine/iodine_crypto.h +1441 -0
- data/ext/iodine/iodine_defer.h +225 -4
- data/ext/iodine/iodine_json.h +738 -4
- data/ext/iodine/iodine_listener.h +263 -0
- data/ext/iodine/iodine_log.h +297 -0
- data/ext/iodine/iodine_minimap.h +543 -0
- data/ext/iodine/iodine_mustache.h +461 -4
- data/ext/iodine/iodine_pubsub_eng.h +729 -0
- data/ext/iodine/iodine_pubsub_history.h +547 -0
- data/ext/iodine/iodine_pubsub_msg.h +228 -0
- data/ext/iodine/iodine_redis.h +322 -0
- data/ext/iodine/iodine_store.h +418 -16
- data/ext/iodine/iodine_threads.h +279 -0
- data/ext/iodine/iodine_tls.h +515 -6
- data/ext/iodine/iodine_utils.h +923 -0
- data/iodine.gemspec +37 -42
- data/lib/iodine/benchmark.rb +1690 -0
- data/lib/iodine/documentation.rb +3085 -0
- data/lib/iodine/version.rb +17 -1
- data/lib/iodine.rb +54 -255
- data/logo.svg +36 -0
- data/mustache.md +55 -0
- data/sig/iodine.rbs +4 -0
- metadata +58 -184
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
- data/.github/workflows/ruby.yml +0 -42
- data/.gitignore +0 -20
- data/LIMITS.md +0 -41
- data/SPEC-PubSub-Draft.md +0 -159
- data/SPEC-WebSocket-Draft.md +0 -239
- data/bin/console +0 -22
- data/bin/info.md +0 -353
- data/bin/mustache_bench.rb +0 -100
- data/bin/poc/Gemfile.lock +0 -23
- data/bin/poc/README.md +0 -37
- data/bin/poc/config.ru +0 -66
- data/bin/poc/gemfile +0 -1
- data/bin/poc/www/index.html +0 -57
- data/examples/async_task.ru +0 -92
- data/examples/bates/README.md +0 -3
- data/examples/bates/config.ru +0 -342
- data/examples/bates/david+bold.pdf +0 -0
- data/examples/bates/public/drop-pdf.png +0 -0
- data/examples/bates/public/index.html +0 -600
- data/examples/echo.ru +0 -59
- data/examples/etag.ru +0 -16
- data/examples/hello.ru +0 -29
- data/examples/pubsub_engine.ru +0 -81
- data/examples/rack3.ru +0 -12
- data/examples/redis.ru +0 -70
- data/examples/shootout.ru +0 -73
- data/examples/sub-protocols.ru +0 -90
- data/examples/tcp_client.rb +0 -66
- data/examples/x-sendfile.ru +0 -14
- data/ext/iodine/fio.c +0 -11995
- data/ext/iodine/fio.h +0 -6371
- data/ext/iodine/fio_cli.c +0 -431
- data/ext/iodine/fio_cli.h +0 -189
- data/ext/iodine/fio_json_parser.h +0 -688
- data/ext/iodine/fio_siphash.c +0 -157
- data/ext/iodine/fio_siphash.h +0 -37
- data/ext/iodine/fio_tls.h +0 -129
- data/ext/iodine/fio_tls_missing.c +0 -649
- data/ext/iodine/fio_tls_openssl.c +0 -1106
- data/ext/iodine/fio_tmpfile.h +0 -50
- data/ext/iodine/fiobj.h +0 -44
- data/ext/iodine/fiobj4fio.h +0 -21
- data/ext/iodine/fiobj_ary.c +0 -333
- data/ext/iodine/fiobj_ary.h +0 -139
- data/ext/iodine/fiobj_data.c +0 -1187
- data/ext/iodine/fiobj_data.h +0 -167
- data/ext/iodine/fiobj_hash.c +0 -409
- data/ext/iodine/fiobj_hash.h +0 -176
- data/ext/iodine/fiobj_json.c +0 -622
- data/ext/iodine/fiobj_json.h +0 -68
- data/ext/iodine/fiobj_mem.h +0 -71
- data/ext/iodine/fiobj_mustache.c +0 -317
- data/ext/iodine/fiobj_mustache.h +0 -62
- data/ext/iodine/fiobj_numbers.c +0 -344
- data/ext/iodine/fiobj_numbers.h +0 -127
- data/ext/iodine/fiobj_str.c +0 -433
- data/ext/iodine/fiobj_str.h +0 -172
- data/ext/iodine/fiobject.c +0 -620
- data/ext/iodine/fiobject.h +0 -655
- data/ext/iodine/hpack.h +0 -1923
- data/ext/iodine/http.c +0 -2743
- data/ext/iodine/http.h +0 -1002
- data/ext/iodine/http1.c +0 -910
- data/ext/iodine/http1.h +0 -29
- data/ext/iodine/http1_parser.h +0 -878
- data/ext/iodine/http_internal.c +0 -1279
- data/ext/iodine/http_internal.h +0 -237
- data/ext/iodine/http_mime_parser.h +0 -350
- data/ext/iodine/iodine_caller.c +0 -230
- data/ext/iodine/iodine_connection.c +0 -941
- data/ext/iodine/iodine_defer.c +0 -420
- data/ext/iodine/iodine_fiobj2rb.h +0 -120
- data/ext/iodine/iodine_helpers.c +0 -282
- data/ext/iodine/iodine_helpers.h +0 -12
- data/ext/iodine/iodine_http.c +0 -1181
- data/ext/iodine/iodine_http.h +0 -23
- data/ext/iodine/iodine_json.c +0 -302
- data/ext/iodine/iodine_mustache.c +0 -567
- data/ext/iodine/iodine_pubsub.c +0 -580
- data/ext/iodine/iodine_pubsub.h +0 -26
- data/ext/iodine/iodine_rack_io.c +0 -273
- data/ext/iodine/iodine_rack_io.h +0 -20
- data/ext/iodine/iodine_store.c +0 -146
- data/ext/iodine/iodine_tcp.c +0 -346
- data/ext/iodine/iodine_tcp.h +0 -13
- data/ext/iodine/iodine_tls.c +0 -261
- data/ext/iodine/mustache_parser.h +0 -1546
- data/ext/iodine/redis_engine.c +0 -957
- data/ext/iodine/redis_engine.h +0 -79
- data/ext/iodine/resp_parser.h +0 -317
- data/ext/iodine/websocket_parser.h +0 -506
- data/ext/iodine/websockets.c +0 -743
- data/ext/iodine/websockets.h +0 -185
- data/lib/iodine/connection.rb +0 -61
- data/lib/iodine/json.rb +0 -42
- data/lib/iodine/mustache.rb +0 -113
- data/lib/iodine/pubsub.rb +0 -55
- data/lib/iodine/rack_utils.rb +0 -43
- data/lib/iodine/tls.rb +0 -16
- data/lib/rack/handler/iodine.rb +0 -33
- data/logo.png +0 -0
data/ext/iodine/iodine_defer.h
CHANGED
|
@@ -1,6 +1,227 @@
|
|
|
1
|
-
#ifndef
|
|
2
|
-
#define
|
|
1
|
+
#ifndef H___IODINE_DEFER___H
|
|
2
|
+
#define H___IODINE_DEFER___H
|
|
3
|
+
#include "iodine.h"
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
/* *****************************************************************************
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
Iodine's `defer` and `run_after` functions
|
|
8
|
+
|
|
9
|
+
***************************************************************************** */
|
|
10
|
+
|
|
11
|
+
/* *****************************************************************************
|
|
12
|
+
Iodine's `on_state`
|
|
13
|
+
***************************************************************************** */
|
|
14
|
+
|
|
15
|
+
static ID IODINE_STATE_PRE_START;
|
|
16
|
+
static ID IODINE_STATE_BEFORE_FORK;
|
|
17
|
+
static ID IODINE_STATE_AFTER_FORK;
|
|
18
|
+
static ID IODINE_STATE_ENTER_CHILD;
|
|
19
|
+
static ID IODINE_STATE_ENTER_MASTER;
|
|
20
|
+
static ID IODINE_STATE_ON_START;
|
|
21
|
+
static ID IODINE_STATE_ON_PARENT_CRUSH;
|
|
22
|
+
static ID IODINE_STATE_ON_CHILD_CRUSH;
|
|
23
|
+
static ID IODINE_STATE_ON_SHUTDOWN;
|
|
24
|
+
static ID IODINE_STATE_ON_STOP;
|
|
25
|
+
static ID IODINE_STATE_ON_IDLE;
|
|
26
|
+
static ID IODINE_STATE_ON_EXIT;
|
|
27
|
+
|
|
28
|
+
/* performs a Ruby state callback without clearing the Ruby object's memory */
|
|
29
|
+
static void iodine_perform_state_callback_persist(void *blk_) {
|
|
30
|
+
VALUE blk = (VALUE)blk_;
|
|
31
|
+
// iodine_caller_result_s r =
|
|
32
|
+
iodine_ruby_call_anywhere(blk, IODINE_CALL_ID, 0, NULL);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// clang-format off
|
|
36
|
+
/**
|
|
37
|
+
Sets a block of code to run when Iodine's core state is updated.
|
|
38
|
+
|
|
39
|
+
@param [Symbol] event the state event for which the block should run (see list).
|
|
40
|
+
|
|
41
|
+
The state event Symbol can be any of the following:
|
|
42
|
+
|
|
43
|
+
| | |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `:pre_start` | the block will be called once before starting up the IO reactor. |
|
|
46
|
+
| `:before_fork` | the block will be called before each time the IO reactor forks a new worker. |
|
|
47
|
+
| `:after_fork` | the block will be called after each fork (both in parent and workers). |
|
|
48
|
+
| `:enter_child` | the block will be called by a worker process right after forking. |
|
|
49
|
+
| `:enter_master` | the block will be called by the master process after spawning a worker (after forking). |
|
|
50
|
+
| `:start` | the block will be called every time a *worker* process starts. In single process mode, the master process is also a worker. |
|
|
51
|
+
| `:idle` | the block will be called when the IO reactor is idling. |
|
|
52
|
+
| `:parent_crush` | the block will be called by each worker the moment it detects the master process crashed. |
|
|
53
|
+
| `:child_crush` | the block will be called by the parent (master) after a worker process crashed. |
|
|
54
|
+
| `:shutdown` | the block will be called before starting the shutdown sequence. |
|
|
55
|
+
| `:stop` | the block will be called just before stopping iodine (both on child and parent processes). |
|
|
56
|
+
| `:exit` | the block will be called during iodine library cleanup, similar to a Ruby `at_exit` callback. |
|
|
57
|
+
|
|
58
|
+
Code runs in both the parent and the child.
|
|
59
|
+
*/
|
|
60
|
+
static VALUE iodine_on_state(VALUE self, VALUE event) { // clang-format on
|
|
61
|
+
|
|
62
|
+
rb_need_block();
|
|
63
|
+
Check_Type(event, T_SYMBOL);
|
|
64
|
+
VALUE block = rb_block_proc();
|
|
65
|
+
STORE.hold(block);
|
|
66
|
+
ID state = rb_sym2id(event);
|
|
67
|
+
|
|
68
|
+
if (state == IODINE_STATE_PRE_START) {
|
|
69
|
+
fio_state_callback_add(FIO_CALL_PRE_START,
|
|
70
|
+
iodine_perform_state_callback_persist,
|
|
71
|
+
(void *)block);
|
|
72
|
+
} else if (state == IODINE_STATE_BEFORE_FORK) {
|
|
73
|
+
fio_state_callback_add(FIO_CALL_BEFORE_FORK,
|
|
74
|
+
iodine_perform_state_callback_persist,
|
|
75
|
+
(void *)block);
|
|
76
|
+
} else if (state == IODINE_STATE_AFTER_FORK) {
|
|
77
|
+
fio_state_callback_add(FIO_CALL_AFTER_FORK,
|
|
78
|
+
iodine_perform_state_callback_persist,
|
|
79
|
+
(void *)block);
|
|
80
|
+
} else if (state == IODINE_STATE_ENTER_CHILD) {
|
|
81
|
+
fio_state_callback_add(FIO_CALL_IN_CHILD,
|
|
82
|
+
iodine_perform_state_callback_persist,
|
|
83
|
+
(void *)block);
|
|
84
|
+
} else if (state == IODINE_STATE_ENTER_MASTER) {
|
|
85
|
+
fio_state_callback_add(FIO_CALL_IN_MASTER,
|
|
86
|
+
iodine_perform_state_callback_persist,
|
|
87
|
+
(void *)block);
|
|
88
|
+
} else if (state == IODINE_STATE_ON_START) {
|
|
89
|
+
fio_state_callback_add(FIO_CALL_ON_START,
|
|
90
|
+
iodine_perform_state_callback_persist,
|
|
91
|
+
(void *)block);
|
|
92
|
+
} else if (state == IODINE_STATE_ON_PARENT_CRUSH) {
|
|
93
|
+
fio_state_callback_add(FIO_CALL_ON_PARENT_CRUSH,
|
|
94
|
+
iodine_perform_state_callback_persist,
|
|
95
|
+
(void *)block);
|
|
96
|
+
} else if (state == IODINE_STATE_ON_CHILD_CRUSH) {
|
|
97
|
+
fio_state_callback_add(FIO_CALL_ON_CHILD_CRUSH,
|
|
98
|
+
iodine_perform_state_callback_persist,
|
|
99
|
+
(void *)block);
|
|
100
|
+
} else if (state == IODINE_STATE_ON_IDLE) {
|
|
101
|
+
fio_state_callback_add(FIO_CALL_ON_IDLE,
|
|
102
|
+
iodine_perform_state_callback_persist,
|
|
103
|
+
(void *)block);
|
|
104
|
+
} else if (state == IODINE_STATE_ON_SHUTDOWN) {
|
|
105
|
+
fio_state_callback_add(FIO_CALL_ON_SHUTDOWN,
|
|
106
|
+
iodine_perform_state_callback_persist,
|
|
107
|
+
(void *)block);
|
|
108
|
+
} else if (state == IODINE_STATE_ON_STOP) {
|
|
109
|
+
fio_state_callback_add(FIO_CALL_ON_STOP,
|
|
110
|
+
iodine_perform_state_callback_persist,
|
|
111
|
+
(void *)block);
|
|
112
|
+
} else if (state == IODINE_STATE_ON_EXIT) {
|
|
113
|
+
fio_state_callback_add(FIO_CALL_AT_EXIT,
|
|
114
|
+
iodine_perform_state_callback_persist,
|
|
115
|
+
(void *)block);
|
|
116
|
+
} else {
|
|
117
|
+
STORE.release(block);
|
|
118
|
+
rb_raise(rb_eTypeError, "unknown event in Iodine.on_state");
|
|
119
|
+
}
|
|
120
|
+
return block;
|
|
121
|
+
(void)self;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* *****************************************************************************
|
|
125
|
+
Task performance
|
|
126
|
+
***************************************************************************** */
|
|
127
|
+
|
|
128
|
+
static void iodine_defer_performe_once(void *block, void *ignr) {
|
|
129
|
+
iodine_ruby_call_anywhere((VALUE)block, IODINE_CALL_ID, 0, NULL);
|
|
130
|
+
STORE.release((VALUE)block);
|
|
131
|
+
(void)ignr;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static int iodine_defer_run_timer(void *block, void *ignr) {
|
|
135
|
+
iodine_caller_result_s r =
|
|
136
|
+
iodine_ruby_call_anywhere((VALUE)block, IODINE_CALL_ID, 0, NULL);
|
|
137
|
+
return 0 - (r.exception || (r.result == Qfalse));
|
|
138
|
+
(void)ignr;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static void iodine_defer_after_timer(void *block, void *ignr) {
|
|
142
|
+
STORE.release((VALUE)block);
|
|
143
|
+
(void)ignr;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* *****************************************************************************
|
|
147
|
+
Defer API
|
|
148
|
+
***************************************************************************** */
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Runs a block of code synchronously (adds the code to the IO event queue).
|
|
152
|
+
*
|
|
153
|
+
* Always returns the block of code to executed (Proc object).
|
|
154
|
+
*
|
|
155
|
+
* Code will be executed only while Iodine is running (after {Iodine.start}).
|
|
156
|
+
*
|
|
157
|
+
* Code blocks that where scheduled to run before Iodine enters cluster mode
|
|
158
|
+
* will run on all child processes.
|
|
159
|
+
*/
|
|
160
|
+
static VALUE iodine_defer_run(VALUE self) {
|
|
161
|
+
rb_need_block();
|
|
162
|
+
VALUE block = rb_block_proc();
|
|
163
|
+
STORE.hold(block);
|
|
164
|
+
fio_io_defer(iodine_defer_performe_once, (void *)block, NULL);
|
|
165
|
+
return block;
|
|
166
|
+
(void)self;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Runs a block of code asynchronously (adds the code to the async event queue).
|
|
171
|
+
*
|
|
172
|
+
* Always returns the block of code to executed (Proc object).
|
|
173
|
+
*
|
|
174
|
+
* Code will be executed only while Iodine is running (after {Iodine.start}).
|
|
175
|
+
*
|
|
176
|
+
* Code blocks that where scheduled to run before Iodine enters cluster mode
|
|
177
|
+
* will run on all child processes.
|
|
178
|
+
*/
|
|
179
|
+
static VALUE iodine_defer_run_async(VALUE self) {
|
|
180
|
+
rb_need_block();
|
|
181
|
+
VALUE block = rb_block_proc();
|
|
182
|
+
STORE.hold(block);
|
|
183
|
+
IODINE_DEFER_BLOCK(block);
|
|
184
|
+
return block;
|
|
185
|
+
(void)self;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// clang-format off
|
|
189
|
+
/**
|
|
190
|
+
Runs the required block after the specified number of milliseconds have passed.
|
|
191
|
+
Time is counted only once Iodine started running (using {Iodine.start}).
|
|
192
|
+
|
|
193
|
+
Accepts:
|
|
194
|
+
|
|
195
|
+
| | |
|
|
196
|
+
|---|---|
|
|
197
|
+
| `:milliseconds` | the number of milliseconds between event repetitions.|
|
|
198
|
+
| `:repetitions` | the number of event repetitions. Defaults to 1 (performed once). Set to 0 for never ending. |
|
|
199
|
+
| `:block` | (required) a block is required, as otherwise there is nothing to|
|
|
200
|
+
perform.
|
|
201
|
+
|
|
202
|
+
The event will repeat itself until the number of repetitions had been delpeted.
|
|
203
|
+
|
|
204
|
+
Always returns a copy of the block object.
|
|
205
|
+
*/
|
|
206
|
+
static VALUE iodine_defer_run_after(int argc, VALUE *argv, VALUE self) {
|
|
207
|
+
// clang-format on
|
|
208
|
+
(void)(self);
|
|
209
|
+
int64_t milli = 0;
|
|
210
|
+
int64_t repeat = 1;
|
|
211
|
+
VALUE block = Qnil;
|
|
212
|
+
iodine_rb2c_arg(argc,
|
|
213
|
+
argv,
|
|
214
|
+
IODINE_ARG_NUM(milli, 0, "milliseconds", 1), // required
|
|
215
|
+
IODINE_ARG_NUM(repeat, 0, "repetitions", 0),
|
|
216
|
+
IODINE_ARG_PROC(block, 0, "block", 1));
|
|
217
|
+
STORE.hold(block);
|
|
218
|
+
repeat -= 1;
|
|
219
|
+
fio_io_run_every(.every = (uint32_t)milli,
|
|
220
|
+
.repetitions = (int32_t)repeat,
|
|
221
|
+
.fn = iodine_defer_run_timer,
|
|
222
|
+
.udata1 = (void *)block,
|
|
223
|
+
.on_finish = iodine_defer_after_timer);
|
|
224
|
+
return block;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
#endif /* H___IODINE_DEFER___H */
|