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.
- 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 -21
- 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 -148
- 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_caller.c
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
#include "iodine_caller.h"
|
|
2
|
-
|
|
3
|
-
#include <ruby/thread.h>
|
|
4
|
-
#include <string.h>
|
|
5
|
-
|
|
6
|
-
#include <fio.h>
|
|
7
|
-
|
|
8
|
-
#include <pthread.h>
|
|
9
|
-
|
|
10
|
-
static pthread_key_t iodine_GVL_state_key;
|
|
11
|
-
static pthread_once_t iodine_GVL_state_once = PTHREAD_ONCE_INIT;
|
|
12
|
-
static void init_iodine_GVL_state_key(void) {
|
|
13
|
-
pthread_key_create(&iodine_GVL_state_key, NULL);
|
|
14
|
-
}
|
|
15
|
-
static void init_iodine_GVL_state_init(void) {
|
|
16
|
-
uint8_t *gvl = malloc(sizeof(uint8_t));
|
|
17
|
-
FIO_ASSERT_ALLOC(gvl);
|
|
18
|
-
*gvl = 1;
|
|
19
|
-
pthread_setspecific(iodine_GVL_state_key, gvl);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/* *****************************************************************************
|
|
23
|
-
Calling protected Ruby methods
|
|
24
|
-
***************************************************************************** */
|
|
25
|
-
|
|
26
|
-
/* task container */
|
|
27
|
-
typedef struct {
|
|
28
|
-
VALUE obj;
|
|
29
|
-
int argc;
|
|
30
|
-
VALUE *argv;
|
|
31
|
-
ID method;
|
|
32
|
-
int exception;
|
|
33
|
-
VALUE (*protected_task)(VALUE tsk_);
|
|
34
|
-
VALUE (*each_func)(VALUE block_arg, VALUE data, int argc, VALUE *argv);
|
|
35
|
-
VALUE each_udata;
|
|
36
|
-
} iodine_rb_task_s;
|
|
37
|
-
|
|
38
|
-
/* printout backtrace in case of exceptions */
|
|
39
|
-
static void *iodine_handle_exception(void *ignr) {
|
|
40
|
-
(void)ignr;
|
|
41
|
-
VALUE exc = rb_errinfo();
|
|
42
|
-
if (exc != Qnil && rb_respond_to(exc, rb_intern("message")) &&
|
|
43
|
-
rb_respond_to(exc, rb_intern("backtrace"))) {
|
|
44
|
-
VALUE msg = rb_funcall2(exc, rb_intern("message"), 0, NULL);
|
|
45
|
-
VALUE exc_class = rb_class_name(CLASS_OF(exc));
|
|
46
|
-
VALUE bt = rb_funcall2(exc, rb_intern("backtrace"), 0, NULL);
|
|
47
|
-
if (TYPE(bt) == T_ARRAY) {
|
|
48
|
-
bt = rb_ary_join(bt, rb_str_new_literal("\n"));
|
|
49
|
-
FIO_LOG_ERROR("Iodine caught an unprotected exception - %.*s: %.*s\n%s",
|
|
50
|
-
(int)RSTRING_LEN(exc_class),
|
|
51
|
-
RSTRING_PTR(exc_class),
|
|
52
|
-
(int)RSTRING_LEN(msg),
|
|
53
|
-
RSTRING_PTR(msg),
|
|
54
|
-
StringValueCStr(bt));
|
|
55
|
-
} else {
|
|
56
|
-
FIO_LOG_ERROR("Iodine caught an unprotected exception - %.*s: %.*s\n"
|
|
57
|
-
"No backtrace available.\n",
|
|
58
|
-
(int)RSTRING_LEN(exc_class),
|
|
59
|
-
RSTRING_PTR(exc_class),
|
|
60
|
-
(int)RSTRING_LEN(msg),
|
|
61
|
-
RSTRING_PTR(msg));
|
|
62
|
-
}
|
|
63
|
-
rb_backtrace();
|
|
64
|
-
FIO_LOG_ERROR("\n");
|
|
65
|
-
rb_set_errinfo(Qnil);
|
|
66
|
-
} else if (exc != Qnil) {
|
|
67
|
-
FIO_LOG_ERROR(
|
|
68
|
-
"Iodine caught an unprotected exception - NO MESSAGE / DATA AVAILABLE");
|
|
69
|
-
}
|
|
70
|
-
return (void *)Qnil;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/* calls the Ruby each method within the protection block */
|
|
74
|
-
static VALUE iodine_ruby_caller_perform_block(VALUE tsk_) {
|
|
75
|
-
iodine_rb_task_s *task = (void *)tsk_;
|
|
76
|
-
return rb_block_call(task->obj,
|
|
77
|
-
task->method,
|
|
78
|
-
task->argc,
|
|
79
|
-
task->argv,
|
|
80
|
-
(rb_block_call_func_t)(task->each_func),
|
|
81
|
-
task->each_udata);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/* calls the Ruby method within the protection block */
|
|
85
|
-
static VALUE iodine_ruby_caller_perform(VALUE tsk_) {
|
|
86
|
-
iodine_rb_task_s *task = (void *)tsk_;
|
|
87
|
-
return rb_funcall2(task->obj, task->method, task->argc, task->argv);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/* wrap the function call in exception handling block (uses longjmp) */
|
|
91
|
-
static void *iodine_protect_ruby_call(void *task_) {
|
|
92
|
-
int state = 0;
|
|
93
|
-
VALUE ret = rb_protect(((iodine_rb_task_s *)task_)->protected_task,
|
|
94
|
-
(VALUE)(task_),
|
|
95
|
-
&state);
|
|
96
|
-
if (state) {
|
|
97
|
-
iodine_handle_exception(NULL);
|
|
98
|
-
}
|
|
99
|
-
return (void *)ret;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/* *****************************************************************************
|
|
103
|
-
API
|
|
104
|
-
***************************************************************************** */
|
|
105
|
-
|
|
106
|
-
/** Calls a C function within the GVL. */
|
|
107
|
-
static void *iodine_enterGVL(void *(*func)(void *), void *arg) {
|
|
108
|
-
pthread_once(&iodine_GVL_state_once, init_iodine_GVL_state_key);
|
|
109
|
-
uint8_t *iodine_GVL_state = pthread_getspecific(iodine_GVL_state_key);
|
|
110
|
-
if (!iodine_GVL_state) {
|
|
111
|
-
init_iodine_GVL_state_init();
|
|
112
|
-
iodine_GVL_state = pthread_getspecific(iodine_GVL_state_key);
|
|
113
|
-
}
|
|
114
|
-
if (*iodine_GVL_state) {
|
|
115
|
-
return func(arg);
|
|
116
|
-
}
|
|
117
|
-
void *rv = NULL;
|
|
118
|
-
*iodine_GVL_state = 1;
|
|
119
|
-
rv = rb_thread_call_with_gvl(func, arg);
|
|
120
|
-
*iodine_GVL_state = 0;
|
|
121
|
-
return rv;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** Calls a C function outside the GVL. */
|
|
125
|
-
static void *iodine_leaveGVL(void *(*func)(void *), void *arg) {
|
|
126
|
-
pthread_once(&iodine_GVL_state_once, init_iodine_GVL_state_key);
|
|
127
|
-
uint8_t *iodine_GVL_state = pthread_getspecific(iodine_GVL_state_key);
|
|
128
|
-
if (!iodine_GVL_state) {
|
|
129
|
-
init_iodine_GVL_state_init();
|
|
130
|
-
iodine_GVL_state = pthread_getspecific(iodine_GVL_state_key);
|
|
131
|
-
}
|
|
132
|
-
if (!*iodine_GVL_state) {
|
|
133
|
-
return func(arg);
|
|
134
|
-
}
|
|
135
|
-
void *rv = NULL;
|
|
136
|
-
*iodine_GVL_state = 0;
|
|
137
|
-
rv = rb_thread_call_without_gvl(func, arg, NULL, NULL);
|
|
138
|
-
*iodine_GVL_state = 1;
|
|
139
|
-
return rv;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** Calls a Ruby method on a given object, protecting against exceptions. */
|
|
143
|
-
static VALUE iodine_call(VALUE obj, ID method) {
|
|
144
|
-
iodine_rb_task_s task = {
|
|
145
|
-
.obj = obj,
|
|
146
|
-
.argc = 0,
|
|
147
|
-
.argv = NULL,
|
|
148
|
-
.method = method,
|
|
149
|
-
.protected_task = iodine_ruby_caller_perform,
|
|
150
|
-
};
|
|
151
|
-
void *rv = iodine_enterGVL(iodine_protect_ruby_call, &task);
|
|
152
|
-
return (VALUE)rv;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** Calls a Ruby method on a given object, protecting against exceptions. */
|
|
156
|
-
static VALUE iodine_call2(VALUE obj, ID method, int argc, VALUE *argv) {
|
|
157
|
-
iodine_rb_task_s task = {
|
|
158
|
-
.obj = obj,
|
|
159
|
-
.argc = argc,
|
|
160
|
-
.argv = argv,
|
|
161
|
-
.method = method,
|
|
162
|
-
.protected_task = iodine_ruby_caller_perform,
|
|
163
|
-
};
|
|
164
|
-
void *rv = iodine_enterGVL(iodine_protect_ruby_call, &task);
|
|
165
|
-
return (VALUE)rv;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** Calls a Ruby method on a given object, protecting against exceptions. */
|
|
169
|
-
static VALUE iodine_call_block(
|
|
170
|
-
VALUE obj,
|
|
171
|
-
ID method,
|
|
172
|
-
int argc,
|
|
173
|
-
VALUE *argv,
|
|
174
|
-
VALUE udata,
|
|
175
|
-
VALUE(each_func)(VALUE block_arg, VALUE udata, int argc, VALUE *argv)) {
|
|
176
|
-
iodine_rb_task_s task = {
|
|
177
|
-
.obj = obj,
|
|
178
|
-
.argc = argc,
|
|
179
|
-
.argv = argv,
|
|
180
|
-
.method = method,
|
|
181
|
-
.protected_task = iodine_ruby_caller_perform_block,
|
|
182
|
-
.each_func = each_func,
|
|
183
|
-
.each_udata = udata,
|
|
184
|
-
};
|
|
185
|
-
void *rv = iodine_enterGVL(iodine_protect_ruby_call, &task);
|
|
186
|
-
return (VALUE)rv;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** Returns the GVL state flag. */
|
|
190
|
-
static uint8_t iodine_in_GVL(void) {
|
|
191
|
-
pthread_once(&iodine_GVL_state_once, init_iodine_GVL_state_key);
|
|
192
|
-
uint8_t *iodine_GVL_state = pthread_getspecific(iodine_GVL_state_key);
|
|
193
|
-
if (!iodine_GVL_state) {
|
|
194
|
-
init_iodine_GVL_state_init();
|
|
195
|
-
iodine_GVL_state = pthread_getspecific(iodine_GVL_state_key);
|
|
196
|
-
}
|
|
197
|
-
return *iodine_GVL_state;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/** Forces the GVL state flag. */
|
|
201
|
-
static void iodine_set_GVL(uint8_t state) {
|
|
202
|
-
pthread_once(&iodine_GVL_state_once, init_iodine_GVL_state_key);
|
|
203
|
-
uint8_t *iodine_GVL_state = pthread_getspecific(iodine_GVL_state_key);
|
|
204
|
-
if (!iodine_GVL_state) {
|
|
205
|
-
init_iodine_GVL_state_init();
|
|
206
|
-
iodine_GVL_state = pthread_getspecific(iodine_GVL_state_key);
|
|
207
|
-
}
|
|
208
|
-
*iodine_GVL_state = state;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/* *****************************************************************************
|
|
212
|
-
Caller Initialization
|
|
213
|
-
***************************************************************************** */
|
|
214
|
-
|
|
215
|
-
struct IodineCaller_s IodineCaller = {
|
|
216
|
-
/** Calls a C function within the GVL. */
|
|
217
|
-
.enterGVL = iodine_enterGVL,
|
|
218
|
-
/** Calls a C function outside the GVL. */
|
|
219
|
-
.leaveGVL = iodine_leaveGVL,
|
|
220
|
-
/** Calls a Ruby method on a given object, protecting against exceptions. */
|
|
221
|
-
.call_with_block = iodine_call_block,
|
|
222
|
-
/** Calls a Ruby method on a given object, protecting against exceptions. */
|
|
223
|
-
.call = iodine_call,
|
|
224
|
-
/** Calls a Ruby method on a given object, protecting against exceptions. */
|
|
225
|
-
.call2 = iodine_call2,
|
|
226
|
-
/** Returns the GVL state flag. */
|
|
227
|
-
.in_GVL = iodine_in_GVL,
|
|
228
|
-
/** Forces the GVL state flag. */
|
|
229
|
-
.set_GVL = iodine_set_GVL,
|
|
230
|
-
};
|