nio4r 2.6.0-java → 2.7.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mailmap +16 -0
- data/Gemfile +4 -2
- data/changes.md +14 -0
- data/examples/echo_server.rb +7 -0
- data/ext/nio4r/bytebuffer.c +46 -28
- data/ext/nio4r/extconf.rb +14 -0
- data/ext/nio4r/monitor.c +33 -19
- data/ext/nio4r/nio4r.h +2 -0
- data/ext/nio4r/selector.c +43 -18
- data/lib/nio/bytebuffer.rb +6 -0
- data/lib/nio/monitor.rb +7 -0
- data/lib/nio/selector.rb +15 -0
- data/lib/nio/version.rb +6 -1
- data/lib/nio.rb +9 -0
- data/lib/nio4r.rb +4 -0
- data/lib/nio4r_ext.jar +0 -0
- data/license.md +50 -39
- data/nio4r.gemspec +4 -3
- data/readme.md +38 -55
- data/spec/nio/acceptables_spec.rb +4 -0
- data/spec/nio/bytebuffer_spec.rb +6 -0
- data/spec/nio/monitor_spec.rb +7 -0
- data/spec/nio/selectables/pipe_spec.rb +6 -0
- data/spec/nio/selectables/ssl_socket_spec.rb +7 -0
- data/spec/nio/selectables/tcp_socket_spec.rb +7 -0
- data/spec/nio/selectables/udp_socket_spec.rb +7 -0
- data/spec/nio/selector_spec.rb +12 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/selectable_examples.rb +8 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cdb31e29b75c47edcaad23f72e8363b0e64d1f81468e1ccab403d63720494ee
|
4
|
+
data.tar.gz: 24544bb9ff3f736f20cbfa4fe088935701acde8d79716c6cc7561ca113e755fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6bcab88b066b81de764b9b9abb13e968d085de5c5d620801b959d5bc3ccf04e093b6ad302ce4b0ab2beee2dcbb15d0380f69cd967cf5b8cd2827a012da41e5f
|
7
|
+
data.tar.gz: fbbb9f39195c268a26634db94388b0cc6df5e865c0e2cc04d866c74743889d7fb772e3be8fd20aadb08ba149421b6e07a131611fdff1f7461e252cfd9e5ea7a9
|
data/.mailmap
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Sadayuki Furuhashi <frsyuki@users.sourceforge.jp>
|
2
|
+
Shannon Skipper <shannonskipper@gmail.com>
|
3
|
+
Anatol Pomozov <anatol.pomozov@gmail.com>
|
4
|
+
Hiroshi Shibata <shibata.hiroshi@gmail.com>
|
5
|
+
John Thornton <ubergeek3141@gmail.com>
|
6
|
+
Upekshe Jayasekera <usmj000@gmail.com>
|
7
|
+
Upekshe Jayasekera <upekshej.11@cse.mrt.ac.lk>
|
8
|
+
Usaku Nakamura <usa@garbagecollect.jp>
|
9
|
+
Tomoya Ishida <tomoyapenguin@gmail.com>
|
10
|
+
Tiago Cardoso <cardoso_tiago@hotmail.com>
|
11
|
+
Ravil Bayramgalin <brainopia@evilmartians.com>
|
12
|
+
Gregory Longtin <Greg.mpls@gmail.com>
|
13
|
+
Gregory Longtin <Greg.mpls@gmail.com> <MSP-Greg@users.noreply.github.com>
|
14
|
+
Elad Eyal <elad.eyal@intel.com>
|
15
|
+
Boaz Segev <bo@bowild.com>
|
16
|
+
Tao Luo <luotao.ruby@gmail.com>
|
data/Gemfile
CHANGED
data/changes.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## 2.6.2
|
2
|
+
|
3
|
+
* Convert NIO objects to TypedData API.
|
4
|
+
|
5
|
+
## 2.6.1
|
6
|
+
|
7
|
+
* Don't update `io` which is subsequently stored. Retain the original.
|
8
|
+
|
9
|
+
## 2.6.0
|
10
|
+
|
11
|
+
* Fix conversion loses int precision.
|
12
|
+
* Avoid direct access to IO internals.
|
13
|
+
* Resolve issue loading both nio and nio4r gems.
|
14
|
+
|
1
15
|
## 2.5.9 (2023-04-02)
|
2
16
|
|
3
17
|
https://github.com/socketry/nio4r/compare/v2.5.8..v2.5.9
|
data/examples/echo_server.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
# Released under the MIT License.
|
5
|
+
# Copyright, 2012-2016, by Tony Arcieri.
|
6
|
+
# Copyright, 2016, by Jun Aruga.
|
7
|
+
# Copyright, 2019, by Zhang Kang.
|
8
|
+
# Copyright, 2020, by Thomas Dziedzic.
|
9
|
+
# Copyright, 2023, by Samuel Williams.
|
10
|
+
|
4
11
|
$LOAD_PATH.push File.expand_path("../lib", __dir__)
|
5
12
|
require "nio"
|
6
13
|
require "socket"
|
data/ext/nio4r/bytebuffer.c
CHANGED
@@ -8,8 +8,8 @@ static VALUE cNIO_ByteBuffer_MarkUnsetError = Qnil;
|
|
8
8
|
|
9
9
|
/* Allocator/deallocator */
|
10
10
|
static VALUE NIO_ByteBuffer_allocate(VALUE klass);
|
11
|
-
static void
|
12
|
-
static
|
11
|
+
static void NIO_ByteBuffer_free(void *data);
|
12
|
+
static size_t NIO_ByteBuffer_memsize(const void *data);
|
13
13
|
|
14
14
|
/* Methods */
|
15
15
|
static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity);
|
@@ -92,28 +92,46 @@ void Init_NIO_ByteBuffer()
|
|
92
92
|
rb_define_method(cNIO_ByteBuffer, "inspect", NIO_ByteBuffer_inspect, 0);
|
93
93
|
}
|
94
94
|
|
95
|
+
static const rb_data_type_t NIO_ByteBuffer_type = {
|
96
|
+
"NIO::ByteBuffer",
|
97
|
+
{
|
98
|
+
NULL, // Nothing to mark
|
99
|
+
NIO_ByteBuffer_free,
|
100
|
+
NIO_ByteBuffer_memsize,
|
101
|
+
},
|
102
|
+
0,
|
103
|
+
0,
|
104
|
+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
|
105
|
+
};
|
106
|
+
|
95
107
|
static VALUE NIO_ByteBuffer_allocate(VALUE klass)
|
96
108
|
{
|
97
109
|
struct NIO_ByteBuffer *bytebuffer = (struct NIO_ByteBuffer *)xmalloc(sizeof(struct NIO_ByteBuffer));
|
98
110
|
bytebuffer->buffer = NULL;
|
99
|
-
return
|
111
|
+
return TypedData_Wrap_Struct(klass, &NIO_ByteBuffer_type, bytebuffer);
|
100
112
|
}
|
101
113
|
|
102
|
-
static void
|
114
|
+
static void NIO_ByteBuffer_free(void *data)
|
103
115
|
{
|
116
|
+
struct NIO_ByteBuffer *buffer = (struct NIO_ByteBuffer *)data;
|
117
|
+
if (buffer->buffer)
|
118
|
+
xfree(buffer->buffer);
|
119
|
+
xfree(buffer);
|
104
120
|
}
|
105
121
|
|
106
|
-
static
|
122
|
+
static size_t NIO_ByteBuffer_memsize(const void *data)
|
107
123
|
{
|
124
|
+
const struct NIO_ByteBuffer *buffer = (const struct NIO_ByteBuffer *)data;
|
125
|
+
size_t memsize = sizeof(struct NIO_ByteBuffer);
|
108
126
|
if (buffer->buffer)
|
109
|
-
|
110
|
-
|
127
|
+
memsize += buffer->capacity;
|
128
|
+
return memsize;
|
111
129
|
}
|
112
130
|
|
113
131
|
static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity)
|
114
132
|
{
|
115
133
|
struct NIO_ByteBuffer *buffer;
|
116
|
-
|
134
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
117
135
|
|
118
136
|
buffer->capacity = NUM2INT(capacity);
|
119
137
|
buffer->buffer = xmalloc(buffer->capacity);
|
@@ -126,7 +144,7 @@ static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity)
|
|
126
144
|
static VALUE NIO_ByteBuffer_clear(VALUE self)
|
127
145
|
{
|
128
146
|
struct NIO_ByteBuffer *buffer;
|
129
|
-
|
147
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
130
148
|
|
131
149
|
memset(buffer->buffer, 0, buffer->capacity);
|
132
150
|
|
@@ -140,7 +158,7 @@ static VALUE NIO_ByteBuffer_clear(VALUE self)
|
|
140
158
|
static VALUE NIO_ByteBuffer_get_position(VALUE self)
|
141
159
|
{
|
142
160
|
struct NIO_ByteBuffer *buffer;
|
143
|
-
|
161
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
144
162
|
|
145
163
|
return INT2NUM(buffer->position);
|
146
164
|
}
|
@@ -149,7 +167,7 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)
|
|
149
167
|
{
|
150
168
|
int pos;
|
151
169
|
struct NIO_ByteBuffer *buffer;
|
152
|
-
|
170
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
153
171
|
|
154
172
|
pos = NUM2INT(new_position);
|
155
173
|
|
@@ -173,7 +191,7 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)
|
|
173
191
|
static VALUE NIO_ByteBuffer_get_limit(VALUE self)
|
174
192
|
{
|
175
193
|
struct NIO_ByteBuffer *buffer;
|
176
|
-
|
194
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
177
195
|
|
178
196
|
return INT2NUM(buffer->limit);
|
179
197
|
}
|
@@ -182,7 +200,7 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)
|
|
182
200
|
{
|
183
201
|
int lim;
|
184
202
|
struct NIO_ByteBuffer *buffer;
|
185
|
-
|
203
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
186
204
|
|
187
205
|
lim = NUM2INT(new_limit);
|
188
206
|
|
@@ -210,7 +228,7 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)
|
|
210
228
|
static VALUE NIO_ByteBuffer_capacity(VALUE self)
|
211
229
|
{
|
212
230
|
struct NIO_ByteBuffer *buffer;
|
213
|
-
|
231
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
214
232
|
|
215
233
|
return INT2NUM(buffer->capacity);
|
216
234
|
}
|
@@ -218,7 +236,7 @@ static VALUE NIO_ByteBuffer_capacity(VALUE self)
|
|
218
236
|
static VALUE NIO_ByteBuffer_remaining(VALUE self)
|
219
237
|
{
|
220
238
|
struct NIO_ByteBuffer *buffer;
|
221
|
-
|
239
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
222
240
|
|
223
241
|
return INT2NUM(buffer->limit - buffer->position);
|
224
242
|
}
|
@@ -226,7 +244,7 @@ static VALUE NIO_ByteBuffer_remaining(VALUE self)
|
|
226
244
|
static VALUE NIO_ByteBuffer_full(VALUE self)
|
227
245
|
{
|
228
246
|
struct NIO_ByteBuffer *buffer;
|
229
|
-
|
247
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
230
248
|
|
231
249
|
return buffer->position == buffer->limit ? Qtrue : Qfalse;
|
232
250
|
}
|
@@ -236,7 +254,7 @@ static VALUE NIO_ByteBuffer_get(int argc, VALUE *argv, VALUE self)
|
|
236
254
|
int len;
|
237
255
|
VALUE length, result;
|
238
256
|
struct NIO_ByteBuffer *buffer;
|
239
|
-
|
257
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
240
258
|
|
241
259
|
rb_scan_args(argc, argv, "01", &length);
|
242
260
|
|
@@ -264,7 +282,7 @@ static VALUE NIO_ByteBuffer_fetch(VALUE self, VALUE index)
|
|
264
282
|
{
|
265
283
|
int i;
|
266
284
|
struct NIO_ByteBuffer *buffer;
|
267
|
-
|
285
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
268
286
|
|
269
287
|
i = NUM2INT(index);
|
270
288
|
|
@@ -283,7 +301,7 @@ static VALUE NIO_ByteBuffer_put(VALUE self, VALUE string)
|
|
283
301
|
{
|
284
302
|
long length;
|
285
303
|
struct NIO_ByteBuffer *buffer;
|
286
|
-
|
304
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
287
305
|
|
288
306
|
StringValue(string);
|
289
307
|
length = RSTRING_LEN(string);
|
@@ -303,7 +321,7 @@ static VALUE NIO_ByteBuffer_read_from(VALUE self, VALUE io)
|
|
303
321
|
struct NIO_ByteBuffer *buffer;
|
304
322
|
ssize_t nbytes, bytes_read;
|
305
323
|
|
306
|
-
|
324
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
307
325
|
|
308
326
|
io = rb_convert_type(io, T_FILE, "IO", "to_io");
|
309
327
|
io_set_nonblock(io);
|
@@ -333,7 +351,7 @@ static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
|
|
333
351
|
struct NIO_ByteBuffer *buffer;
|
334
352
|
ssize_t nbytes, bytes_written;
|
335
353
|
|
336
|
-
|
354
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
337
355
|
io = rb_convert_type(io, T_FILE, "IO", "to_io");
|
338
356
|
io_set_nonblock(io);
|
339
357
|
|
@@ -360,7 +378,7 @@ static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
|
|
360
378
|
static VALUE NIO_ByteBuffer_flip(VALUE self)
|
361
379
|
{
|
362
380
|
struct NIO_ByteBuffer *buffer;
|
363
|
-
|
381
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
364
382
|
|
365
383
|
buffer->limit = buffer->position;
|
366
384
|
buffer->position = 0;
|
@@ -372,7 +390,7 @@ static VALUE NIO_ByteBuffer_flip(VALUE self)
|
|
372
390
|
static VALUE NIO_ByteBuffer_rewind(VALUE self)
|
373
391
|
{
|
374
392
|
struct NIO_ByteBuffer *buffer;
|
375
|
-
|
393
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
376
394
|
|
377
395
|
buffer->position = 0;
|
378
396
|
buffer->mark = MARK_UNSET;
|
@@ -383,7 +401,7 @@ static VALUE NIO_ByteBuffer_rewind(VALUE self)
|
|
383
401
|
static VALUE NIO_ByteBuffer_mark(VALUE self)
|
384
402
|
{
|
385
403
|
struct NIO_ByteBuffer *buffer;
|
386
|
-
|
404
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
387
405
|
|
388
406
|
buffer->mark = buffer->position;
|
389
407
|
return self;
|
@@ -392,7 +410,7 @@ static VALUE NIO_ByteBuffer_mark(VALUE self)
|
|
392
410
|
static VALUE NIO_ByteBuffer_reset(VALUE self)
|
393
411
|
{
|
394
412
|
struct NIO_ByteBuffer *buffer;
|
395
|
-
|
413
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
396
414
|
|
397
415
|
if (buffer->mark < 0) {
|
398
416
|
rb_raise(cNIO_ByteBuffer_MarkUnsetError, "mark has not been set");
|
@@ -406,7 +424,7 @@ static VALUE NIO_ByteBuffer_reset(VALUE self)
|
|
406
424
|
static VALUE NIO_ByteBuffer_compact(VALUE self)
|
407
425
|
{
|
408
426
|
struct NIO_ByteBuffer *buffer;
|
409
|
-
|
427
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
410
428
|
|
411
429
|
memmove(buffer->buffer, buffer->buffer + buffer->position, buffer->limit - buffer->position);
|
412
430
|
buffer->position = buffer->limit - buffer->position;
|
@@ -419,7 +437,7 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
|
|
419
437
|
{
|
420
438
|
int i;
|
421
439
|
struct NIO_ByteBuffer *buffer;
|
422
|
-
|
440
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
423
441
|
|
424
442
|
if (rb_block_given_p()) {
|
425
443
|
for (i = 0; i < buffer->limit; i++) {
|
@@ -435,7 +453,7 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
|
|
435
453
|
static VALUE NIO_ByteBuffer_inspect(VALUE self)
|
436
454
|
{
|
437
455
|
struct NIO_ByteBuffer *buffer;
|
438
|
-
|
456
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
439
457
|
|
440
458
|
return rb_sprintf(
|
441
459
|
"#<%s:%p @position=%d @limit=%d @capacity=%d>",
|
data/ext/nio4r/extconf.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2011-2020, by Tony Arcieri.
|
5
|
+
# Copyright, 2014, by Hiroshi Shibata.
|
6
|
+
# Copyright, 2014, by Sergey Avseyev.
|
7
|
+
# Copyright, 2015, by Daniel Berger.
|
8
|
+
# Copyright, 2017, by Jun Aruga.
|
9
|
+
# Copyright, 2017, by Usaku Nakamura.
|
10
|
+
# Copyright, 2017, by Lars Kanis.
|
11
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
12
|
+
# Copyright, 2020, by Gregory Longtin.
|
13
|
+
# Copyright, 2020, by Boaz Segev.
|
14
|
+
# Copyright, 2020, by Joao Fernandes.
|
15
|
+
# Copyright, 2021, by Jeffrey Martin.
|
16
|
+
|
3
17
|
require "rubygems"
|
4
18
|
|
5
19
|
# Write a dummy Makefile on Windows because we use the pure Ruby implementation there
|
data/ext/nio4r/monitor.c
CHANGED
@@ -11,8 +11,8 @@ static VALUE cNIO_Monitor = Qnil;
|
|
11
11
|
|
12
12
|
/* Allocator/deallocator */
|
13
13
|
static VALUE NIO_Monitor_allocate(VALUE klass);
|
14
|
-
static void NIO_Monitor_mark(
|
15
|
-
static
|
14
|
+
static void NIO_Monitor_mark(void *data);
|
15
|
+
static size_t NIO_Monitor_memsize(const void *data);
|
16
16
|
|
17
17
|
/* Methods */
|
18
18
|
static VALUE NIO_Monitor_initialize(VALUE self, VALUE selector, VALUE io, VALUE interests);
|
@@ -70,22 +70,36 @@ void Init_NIO_Monitor()
|
|
70
70
|
rb_define_method(cNIO_Monitor, "writeable?", NIO_Monitor_is_writable, 0);
|
71
71
|
}
|
72
72
|
|
73
|
+
static const rb_data_type_t NIO_Monitor_type = {
|
74
|
+
"NIO::Monitor",
|
75
|
+
{
|
76
|
+
NIO_Monitor_mark,
|
77
|
+
RUBY_TYPED_DEFAULT_FREE,
|
78
|
+
NIO_Monitor_memsize,
|
79
|
+
},
|
80
|
+
0,
|
81
|
+
0,
|
82
|
+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
|
83
|
+
};
|
84
|
+
|
73
85
|
static VALUE NIO_Monitor_allocate(VALUE klass)
|
74
86
|
{
|
75
87
|
struct NIO_Monitor *monitor = (struct NIO_Monitor *)xmalloc(sizeof(struct NIO_Monitor));
|
76
88
|
assert(monitor);
|
77
89
|
*monitor = (struct NIO_Monitor){.self = Qnil};
|
78
|
-
return
|
90
|
+
return TypedData_Wrap_Struct(klass, &NIO_Monitor_type, monitor);
|
79
91
|
}
|
80
92
|
|
81
|
-
static void NIO_Monitor_mark(
|
93
|
+
static void NIO_Monitor_mark(void *data)
|
82
94
|
{
|
95
|
+
struct NIO_Monitor *monitor = (struct NIO_Monitor *)data;
|
83
96
|
rb_gc_mark(monitor->self);
|
84
97
|
}
|
85
98
|
|
86
|
-
static
|
99
|
+
static size_t NIO_Monitor_memsize(const void *data)
|
87
100
|
{
|
88
|
-
|
101
|
+
const struct NIO_Monitor *monitor = (const struct NIO_Monitor *)data;
|
102
|
+
return sizeof(*monitor);
|
89
103
|
}
|
90
104
|
|
91
105
|
static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE selector_obj)
|
@@ -96,7 +110,7 @@ static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE
|
|
96
110
|
|
97
111
|
interests_id = SYM2ID(interests);
|
98
112
|
|
99
|
-
|
113
|
+
TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
|
100
114
|
|
101
115
|
if (interests_id == rb_intern("r")) {
|
102
116
|
monitor->interests = EV_READ;
|
@@ -108,16 +122,16 @@ static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE
|
|
108
122
|
rb_raise(rb_eArgError, "invalid event type %s (must be :r, :w, or :rw)", RSTRING_PTR(rb_funcall(interests, rb_intern("inspect"), 0)));
|
109
123
|
}
|
110
124
|
|
111
|
-
|
112
|
-
ev_io_init(&monitor->ev_io, NIO_Selector_monitor_callback,
|
125
|
+
int descriptor = rb_io_descriptor(rb_convert_type(io, T_FILE, "IO", "to_io"));
|
126
|
+
ev_io_init(&monitor->ev_io, NIO_Selector_monitor_callback, descriptor, monitor->interests);
|
113
127
|
|
114
128
|
rb_ivar_set(self, rb_intern("io"), io);
|
115
129
|
rb_ivar_set(self, rb_intern("interests"), interests);
|
116
130
|
rb_ivar_set(self, rb_intern("selector"), selector_obj);
|
117
131
|
|
118
|
-
|
132
|
+
selector = NIO_Selector_unwrap(selector_obj);
|
119
133
|
|
120
|
-
monitor->self
|
134
|
+
RB_OBJ_WRITE(self, &monitor->self, self);
|
121
135
|
monitor->ev_io.data = (void *)monitor;
|
122
136
|
|
123
137
|
/* We can safely hang onto this as we also hang onto a reference to the
|
@@ -135,7 +149,7 @@ static VALUE NIO_Monitor_close(int argc, VALUE *argv, VALUE self)
|
|
135
149
|
{
|
136
150
|
VALUE deregister, selector;
|
137
151
|
struct NIO_Monitor *monitor;
|
138
|
-
|
152
|
+
TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
|
139
153
|
|
140
154
|
rb_scan_args(argc, argv, "01", &deregister);
|
141
155
|
selector = rb_ivar_get(self, rb_intern("selector"));
|
@@ -161,7 +175,7 @@ static VALUE NIO_Monitor_close(int argc, VALUE *argv, VALUE self)
|
|
161
175
|
static VALUE NIO_Monitor_is_closed(VALUE self)
|
162
176
|
{
|
163
177
|
struct NIO_Monitor *monitor;
|
164
|
-
|
178
|
+
TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
|
165
179
|
|
166
180
|
return monitor->selector == 0 ? Qtrue : Qfalse;
|
167
181
|
}
|
@@ -190,7 +204,7 @@ static VALUE NIO_Monitor_set_interests(VALUE self, VALUE interests)
|
|
190
204
|
static VALUE NIO_Monitor_add_interest(VALUE self, VALUE interest)
|
191
205
|
{
|
192
206
|
struct NIO_Monitor *monitor;
|
193
|
-
|
207
|
+
TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
|
194
208
|
|
195
209
|
interest = monitor->interests | NIO_Monitor_symbol2interest(interest);
|
196
210
|
NIO_Monitor_update_interests(self, (int)interest);
|
@@ -201,7 +215,7 @@ static VALUE NIO_Monitor_add_interest(VALUE self, VALUE interest)
|
|
201
215
|
static VALUE NIO_Monitor_remove_interest(VALUE self, VALUE interest)
|
202
216
|
{
|
203
217
|
struct NIO_Monitor *monitor;
|
204
|
-
|
218
|
+
TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
|
205
219
|
|
206
220
|
interest = monitor->interests & ~NIO_Monitor_symbol2interest(interest);
|
207
221
|
NIO_Monitor_update_interests(self, (int)interest);
|
@@ -227,7 +241,7 @@ static VALUE NIO_Monitor_set_value(VALUE self, VALUE obj)
|
|
227
241
|
static VALUE NIO_Monitor_readiness(VALUE self)
|
228
242
|
{
|
229
243
|
struct NIO_Monitor *monitor;
|
230
|
-
|
244
|
+
TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
|
231
245
|
|
232
246
|
if ((monitor->revents & (EV_READ | EV_WRITE)) == (EV_READ | EV_WRITE)) {
|
233
247
|
return ID2SYM(rb_intern("rw"));
|
@@ -243,7 +257,7 @@ static VALUE NIO_Monitor_readiness(VALUE self)
|
|
243
257
|
static VALUE NIO_Monitor_is_readable(VALUE self)
|
244
258
|
{
|
245
259
|
struct NIO_Monitor *monitor;
|
246
|
-
|
260
|
+
TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
|
247
261
|
|
248
262
|
if (monitor->revents & EV_READ) {
|
249
263
|
return Qtrue;
|
@@ -255,7 +269,7 @@ static VALUE NIO_Monitor_is_readable(VALUE self)
|
|
255
269
|
static VALUE NIO_Monitor_is_writable(VALUE self)
|
256
270
|
{
|
257
271
|
struct NIO_Monitor *monitor;
|
258
|
-
|
272
|
+
TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
|
259
273
|
|
260
274
|
if (monitor->revents & EV_WRITE) {
|
261
275
|
return Qtrue;
|
@@ -286,7 +300,7 @@ static void NIO_Monitor_update_interests(VALUE self, int interests)
|
|
286
300
|
{
|
287
301
|
ID interests_id;
|
288
302
|
struct NIO_Monitor *monitor;
|
289
|
-
|
303
|
+
TypedData_Get_Struct(self, struct NIO_Monitor, &NIO_Monitor_type, monitor);
|
290
304
|
|
291
305
|
if (NIO_Monitor_is_closed(self) == Qtrue) {
|
292
306
|
rb_raise(rb_eEOFError, "monitor is closed");
|
data/ext/nio4r/nio4r.h
CHANGED
@@ -40,6 +40,8 @@ struct NIO_ByteBuffer {
|
|
40
40
|
int position, limit, capacity, mark;
|
41
41
|
};
|
42
42
|
|
43
|
+
struct NIO_Selector *NIO_Selector_unwrap(VALUE selector);
|
44
|
+
|
43
45
|
/* Thunk between libev callbacks in NIO::Monitors and NIO::Selectors */
|
44
46
|
void NIO_Selector_monitor_callback(struct ev_loop *ev_loop, struct ev_io *io, int revents);
|
45
47
|
|
data/ext/nio4r/selector.c
CHANGED
@@ -23,9 +23,10 @@ static VALUE cNIO_Selector = Qnil;
|
|
23
23
|
|
24
24
|
/* Allocator/deallocator */
|
25
25
|
static VALUE NIO_Selector_allocate(VALUE klass);
|
26
|
-
static void NIO_Selector_mark(
|
26
|
+
static void NIO_Selector_mark(void *data);
|
27
27
|
static void NIO_Selector_shutdown(struct NIO_Selector *selector);
|
28
|
-
static void NIO_Selector_free(
|
28
|
+
static void NIO_Selector_free(void *data);
|
29
|
+
static size_t NIO_Selector_memsize(const void *data);
|
29
30
|
|
30
31
|
/* Class methods */
|
31
32
|
static VALUE NIO_Selector_supported_backends(VALUE klass);
|
@@ -83,6 +84,18 @@ void Init_NIO_Selector(void)
|
|
83
84
|
cNIO_Monitor = rb_define_class_under(mNIO, "Monitor", rb_cObject);
|
84
85
|
}
|
85
86
|
|
87
|
+
static const rb_data_type_t NIO_Selector_type = {
|
88
|
+
"NIO::Selector",
|
89
|
+
{
|
90
|
+
NIO_Selector_mark,
|
91
|
+
NIO_Selector_free,
|
92
|
+
NIO_Selector_memsize,
|
93
|
+
},
|
94
|
+
0,
|
95
|
+
0,
|
96
|
+
RUBY_TYPED_WB_PROTECTED // Don't free immediately because of shutdown
|
97
|
+
};
|
98
|
+
|
86
99
|
/* Create the libev event loop and incoming event buffer */
|
87
100
|
static VALUE NIO_Selector_allocate(VALUE klass)
|
88
101
|
{
|
@@ -104,8 +117,7 @@ static VALUE NIO_Selector_allocate(VALUE klass)
|
|
104
117
|
rb_sys_fail("fcntl");
|
105
118
|
}
|
106
119
|
|
107
|
-
|
108
|
-
|
120
|
+
VALUE obj = TypedData_Make_Struct(klass, struct NIO_Selector, &NIO_Selector_type, selector);
|
109
121
|
/* Defer initializing the loop to #initialize */
|
110
122
|
selector->ev_loop = 0;
|
111
123
|
|
@@ -118,14 +130,21 @@ static VALUE NIO_Selector_allocate(VALUE klass)
|
|
118
130
|
selector->wakeup.data = (void *)selector;
|
119
131
|
|
120
132
|
selector->closed = selector->selecting = selector->wakeup_fired = selector->ready_count = 0;
|
121
|
-
selector->ready_array
|
133
|
+
RB_OBJ_WRITE(obj, &selector->ready_array, Qnil);
|
134
|
+
return obj;
|
135
|
+
}
|
122
136
|
|
123
|
-
|
137
|
+
struct NIO_Selector *NIO_Selector_unwrap(VALUE self)
|
138
|
+
{
|
139
|
+
struct NIO_Selector *selector;
|
140
|
+
TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
|
141
|
+
return selector;
|
124
142
|
}
|
125
143
|
|
126
144
|
/* NIO selectors store all Ruby objects in instance variables so mark is a stub */
|
127
|
-
static void NIO_Selector_mark(
|
145
|
+
static void NIO_Selector_mark(void *data)
|
128
146
|
{
|
147
|
+
struct NIO_Selector *selector = (struct NIO_Selector *)data;
|
129
148
|
if (selector->ready_array != Qnil) {
|
130
149
|
rb_gc_mark(selector->ready_array);
|
131
150
|
}
|
@@ -151,12 +170,18 @@ static void NIO_Selector_shutdown(struct NIO_Selector *selector)
|
|
151
170
|
}
|
152
171
|
|
153
172
|
/* Ruby finalizer for selector objects */
|
154
|
-
static void NIO_Selector_free(
|
173
|
+
static void NIO_Selector_free(void *data)
|
155
174
|
{
|
175
|
+
struct NIO_Selector *selector = (struct NIO_Selector *)data;
|
156
176
|
NIO_Selector_shutdown(selector);
|
157
177
|
xfree(selector);
|
158
178
|
}
|
159
179
|
|
180
|
+
static size_t NIO_Selector_memsize(const void *data)
|
181
|
+
{
|
182
|
+
return sizeof(struct NIO_Selector);
|
183
|
+
}
|
184
|
+
|
160
185
|
/* Return an array of symbols for supported backends */
|
161
186
|
static VALUE NIO_Selector_supported_backends(VALUE klass)
|
162
187
|
{
|
@@ -205,7 +230,7 @@ static VALUE NIO_Selector_initialize(int argc, VALUE *argv, VALUE self)
|
|
205
230
|
struct NIO_Selector *selector;
|
206
231
|
unsigned int flags = 0;
|
207
232
|
|
208
|
-
|
233
|
+
TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
|
209
234
|
|
210
235
|
rb_scan_args(argc, argv, "01", &backend);
|
211
236
|
|
@@ -259,7 +284,7 @@ static VALUE NIO_Selector_backend(VALUE self)
|
|
259
284
|
{
|
260
285
|
struct NIO_Selector *selector;
|
261
286
|
|
262
|
-
|
287
|
+
TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
|
263
288
|
if (selector->closed) {
|
264
289
|
rb_raise(rb_eIOError, "selector is closed");
|
265
290
|
}
|
@@ -337,7 +362,7 @@ static VALUE NIO_Selector_register_synchronized(VALUE _args)
|
|
337
362
|
io = args[1];
|
338
363
|
interests = args[2];
|
339
364
|
|
340
|
-
|
365
|
+
TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
|
341
366
|
if (selector->closed) {
|
342
367
|
rb_raise(rb_eIOError, "selector is closed");
|
343
368
|
}
|
@@ -418,14 +443,14 @@ static VALUE NIO_Selector_select_synchronized(VALUE _args)
|
|
418
443
|
|
419
444
|
VALUE *args = (VALUE *)_args;
|
420
445
|
|
421
|
-
|
446
|
+
TypedData_Get_Struct(args[0], struct NIO_Selector, &NIO_Selector_type, selector);
|
422
447
|
|
423
448
|
if (selector->closed) {
|
424
449
|
rb_raise(rb_eIOError, "selector is closed");
|
425
450
|
}
|
426
451
|
|
427
452
|
if (!rb_block_given_p()) {
|
428
|
-
selector->ready_array
|
453
|
+
RB_OBJ_WRITE(args[0], &selector->ready_array, rb_ary_new());
|
429
454
|
}
|
430
455
|
|
431
456
|
ready = NIO_Selector_run(selector, args[1]);
|
@@ -433,7 +458,7 @@ static VALUE NIO_Selector_select_synchronized(VALUE _args)
|
|
433
458
|
/* Timeout */
|
434
459
|
if (ready < 0) {
|
435
460
|
if (!rb_block_given_p()) {
|
436
|
-
selector->ready_array
|
461
|
+
RB_OBJ_WRITE(args[0], &selector->ready_array, Qnil);
|
437
462
|
}
|
438
463
|
|
439
464
|
return Qnil;
|
@@ -443,7 +468,7 @@ static VALUE NIO_Selector_select_synchronized(VALUE _args)
|
|
443
468
|
return INT2NUM(ready);
|
444
469
|
} else {
|
445
470
|
ready_array = selector->ready_array;
|
446
|
-
selector->ready_array
|
471
|
+
RB_OBJ_WRITE(args[0], &selector->ready_array, Qnil);
|
447
472
|
return ready_array;
|
448
473
|
}
|
449
474
|
}
|
@@ -490,7 +515,7 @@ static int NIO_Selector_run(struct NIO_Selector *selector, VALUE timeout)
|
|
490
515
|
static VALUE NIO_Selector_wakeup(VALUE self)
|
491
516
|
{
|
492
517
|
struct NIO_Selector *selector;
|
493
|
-
|
518
|
+
TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
|
494
519
|
|
495
520
|
if (selector->closed) {
|
496
521
|
rb_raise(rb_eIOError, "selector is closed");
|
@@ -512,7 +537,7 @@ static VALUE NIO_Selector_close_synchronized(VALUE self)
|
|
512
537
|
{
|
513
538
|
struct NIO_Selector *selector;
|
514
539
|
|
515
|
-
|
540
|
+
TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
|
516
541
|
|
517
542
|
NIO_Selector_shutdown(selector);
|
518
543
|
|
@@ -529,7 +554,7 @@ static VALUE NIO_Selector_closed_synchronized(VALUE self)
|
|
529
554
|
{
|
530
555
|
struct NIO_Selector *selector;
|
531
556
|
|
532
|
-
|
557
|
+
TypedData_Get_Struct(self, struct NIO_Selector, &NIO_Selector_type, selector);
|
533
558
|
|
534
559
|
return selector->closed ? Qtrue : Qfalse;
|
535
560
|
}
|
data/lib/nio/bytebuffer.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2016, by Upekshe Jayasekera.
|
5
|
+
# Copyright, 2016-2017, by Tony Arcieri.
|
6
|
+
# Copyright, 2020, by Thomas Dziedzic.
|
7
|
+
# Copyright, 2023, by Samuel Williams.
|
8
|
+
|
3
9
|
module NIO
|
4
10
|
# Efficient byte buffers for performant I/O operations
|
5
11
|
class ByteBuffer
|
data/lib/nio/monitor.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2011-2018, by Tony Arcieri.
|
5
|
+
# Copyright, 2015, by Upekshe Jayasekera.
|
6
|
+
# Copyright, 2015, by Vladimir Kochnev.
|
7
|
+
# Copyright, 2018-2023, by Samuel Williams.
|
8
|
+
# Copyright, 2019-2020, by Gregory Longtin.
|
9
|
+
|
3
10
|
module NIO
|
4
11
|
# Monitors watch IO objects for specific events
|
5
12
|
class Monitor
|
data/lib/nio/selector.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2011-2017, by Tony Arcieri.
|
5
|
+
# Copyright, 2012, by Logan Bowers.
|
6
|
+
# Copyright, 2013, by Sadayuki Furuhashi.
|
7
|
+
# Copyright, 2013, by Stephen von Takach.
|
8
|
+
# Copyright, 2013, by Tim Carey-Smith.
|
9
|
+
# Copyright, 2013, by Ravil Bayramgalin.
|
10
|
+
# Copyright, 2014, by Sergey Avseyev.
|
11
|
+
# Copyright, 2014, by John Thornton.
|
12
|
+
# Copyright, 2015, by Vladimir Kochnev.
|
13
|
+
# Copyright, 2015, by Upekshe Jayasekera.
|
14
|
+
# Copyright, 2019-2020, by Gregory Longtin.
|
15
|
+
# Copyright, 2020-2021, by Joao Fernandes.
|
16
|
+
# Copyright, 2023, by Samuel Williams.
|
17
|
+
|
3
18
|
require "set"
|
4
19
|
|
5
20
|
module NIO
|
data/lib/nio/version.rb
CHANGED
data/lib/nio.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2011-2017, by Tony Arcieri.
|
5
|
+
# Copyright, 2013, by Stephen von Takach.
|
6
|
+
# Copyright, 2013, by Per Lundberg.
|
7
|
+
# Copyright, 2014, by Marek Kowalcze.
|
8
|
+
# Copyright, 2016, by Upekshe Jayasekera.
|
9
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
10
|
+
# Copyright, 2021, by Jun Jiang.
|
11
|
+
|
3
12
|
require "socket"
|
4
13
|
require "nio/version"
|
5
14
|
|
data/lib/nio4r.rb
CHANGED
data/lib/nio4r_ext.jar
CHANGED
Binary file
|
data/license.md
CHANGED
@@ -1,43 +1,53 @@
|
|
1
1
|
# MIT License
|
2
2
|
|
3
|
-
Copyright, 2011-2020, by Tony Arcieri.
|
4
|
-
Copyright, 2012, by
|
5
|
-
Copyright,
|
6
|
-
Copyright,
|
7
|
-
Copyright, 2013, by
|
8
|
-
Copyright, 2013, by
|
9
|
-
Copyright, 2013, by
|
10
|
-
Copyright,
|
11
|
-
Copyright,
|
12
|
-
Copyright,
|
13
|
-
Copyright,
|
14
|
-
Copyright,
|
15
|
-
Copyright,
|
16
|
-
Copyright,
|
17
|
-
Copyright,
|
18
|
-
Copyright,
|
19
|
-
Copyright,
|
20
|
-
Copyright,
|
21
|
-
Copyright,
|
22
|
-
Copyright,
|
23
|
-
Copyright,
|
24
|
-
Copyright,
|
25
|
-
Copyright,
|
26
|
-
Copyright,
|
27
|
-
Copyright,
|
28
|
-
Copyright,
|
29
|
-
Copyright,
|
30
|
-
Copyright,
|
31
|
-
Copyright,
|
32
|
-
Copyright,
|
33
|
-
Copyright,
|
34
|
-
Copyright, 2020, by
|
35
|
-
Copyright,
|
36
|
-
Copyright,
|
37
|
-
Copyright,
|
38
|
-
Copyright,
|
39
|
-
Copyright,
|
40
|
-
Copyright,
|
3
|
+
Copyright, 2011-2020, by Tony Arcieri.
|
4
|
+
Copyright, 2012, by Bernd Ahlers.
|
5
|
+
Copyright, 2012, by Logan Bowers.
|
6
|
+
Copyright, 2012, by Dirkjan Bussink.
|
7
|
+
Copyright, 2013, by Sadayuki Furuhashi.
|
8
|
+
Copyright, 2013, by Shannon Skipper.
|
9
|
+
Copyright, 2013, by Stephen von Takach.
|
10
|
+
Copyright, 2013, by Tim Carey-Smith.
|
11
|
+
Copyright, 2013, by Per Lundberg.
|
12
|
+
Copyright, 2013, by Ravil Bayramgalin.
|
13
|
+
Copyright, 2013, by Luis Lavena.
|
14
|
+
Copyright, 2014, by Anatol Pomozov.
|
15
|
+
Copyright, 2014, by Hiroshi Shibata.
|
16
|
+
Copyright, 2014, by Marek Kowalcze.
|
17
|
+
Copyright, 2014, by Sergey Avseyev.
|
18
|
+
Copyright, 2014, by John Thornton.
|
19
|
+
Copyright, 2015-2017, by Tiago Cardoso.
|
20
|
+
Copyright, 2015, by Daniel Berger.
|
21
|
+
Copyright, 2015-2016, by Upekshe Jayasekera.
|
22
|
+
Copyright, 2015, by Vladimir Kochnev.
|
23
|
+
Copyright, 2016-2018, by Jun Aruga.
|
24
|
+
Copyright, 2016, by Omer Katz.
|
25
|
+
Copyright, 2016, by Denis Washington.
|
26
|
+
Copyright, 2016-2021, by Olle Jonsson.
|
27
|
+
Copyright, 2017, by Tao Luo.
|
28
|
+
Copyright, 2017, by Usaku Nakamura.
|
29
|
+
Copyright, 2017-2022, by Gregory Longtin.
|
30
|
+
Copyright, 2017, by Lars Kanis.
|
31
|
+
Copyright, 2017, by Tomoya Ishida.
|
32
|
+
Copyright, 2018-2023, by Samuel Williams.
|
33
|
+
Copyright, 2019, by Cédric Boutillier.
|
34
|
+
Copyright, 2019-2020, by Benoit Daloze.
|
35
|
+
Copyright, 2019, by Jesús Burgos Maciá.
|
36
|
+
Copyright, 2019, by Thomas Kuntz.
|
37
|
+
Copyright, 2019, by Orien Madgwick.
|
38
|
+
Copyright, 2019, by Zhang Kang.
|
39
|
+
Copyright, 2020, by Thomas Dziedzic.
|
40
|
+
Copyright, 2020, by Elad Eyal.
|
41
|
+
Copyright, 2020, by Pedro Paiva.
|
42
|
+
Copyright, 2020, by Boaz Segev.
|
43
|
+
Copyright, 2020, by Charles Oliver Nutter.
|
44
|
+
Copyright, 2020-2021, by Joao Fernandes.
|
45
|
+
Copyright, 2021, by Jun Jiang.
|
46
|
+
Copyright, 2021, by Pavel Lobashov.
|
47
|
+
Copyright, 2021, by Jeffrey Martin.
|
48
|
+
Copyright, 2023, by Pavel Rosický.
|
49
|
+
Copyright, 2023, by Tsimnuj Hawj.
|
50
|
+
Copyright, 2023, by Phillip Aldridge.
|
41
51
|
|
42
52
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
43
53
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -59,7 +69,8 @@ SOFTWARE.
|
|
59
69
|
|
60
70
|
## libev
|
61
71
|
|
62
|
-
Released under the BSD
|
72
|
+
Released under the BSD-2-Clause OR GPL-2.0-or-later license.
|
73
|
+
See [ext/libev/LICENSE] for details.
|
63
74
|
|
64
75
|
Copyright, 2007-2019, by Marc Alexander Lehmann.
|
65
76
|
|
data/nio4r.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["Tony Arcieri"]
|
7
7
|
spec.email = ["bascule@gmail.com"]
|
8
8
|
spec.homepage = "https://github.com/socketry/nio4r"
|
9
|
-
spec.license = "MIT"
|
9
|
+
spec.license = "MIT AND (BSD-2-Clause OR GPL-2.0-or-later)"
|
10
10
|
spec.summary = "New IO for Ruby"
|
11
11
|
spec.description = <<-DESCRIPTION.strip.gsub(/\s+/, " ")
|
12
12
|
Cross-platform asynchronous I/O primitives for scalable network clients
|
@@ -22,10 +22,11 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.metadata = {
|
24
24
|
"bug_tracker_uri" => "https://github.com/socketry/nio4r/issues",
|
25
|
-
"changelog_uri" => "https://github.com/socketry/nio4r/blob/
|
25
|
+
"changelog_uri" => "https://github.com/socketry/nio4r/blob/main/changes.md",
|
26
26
|
"documentation_uri" => "https://www.rubydoc.info/gems/nio4r/#{spec.version}",
|
27
27
|
"source_code_uri" => "https://github.com/socketry/nio4r/tree/v#{spec.version}",
|
28
|
-
"wiki_uri" => "https://github.com/socketry/nio4r/wiki"
|
28
|
+
"wiki_uri" => "https://github.com/socketry/nio4r/wiki",
|
29
|
+
"funding_uri" => "https://github.com/sponsors/ioquatix/",
|
29
30
|
}
|
30
31
|
|
31
32
|
spec.required_ruby_version = ">= 2.4"
|
data/readme.md
CHANGED
@@ -16,93 +16,76 @@ writing.
|
|
16
16
|
|
17
17
|
## Projects using nio4r
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
[ActionCable]: https://rubygems.org/gems/actioncable
|
25
|
-
[Celluloid]: https://github.com/celluloid/celluloid-io
|
26
|
-
[Async]: https://github.com/socketry/async
|
27
|
-
[Puma]: https://github.com/puma/puma
|
19
|
+
- [ActionCable](https://rubygems.org/gems/actioncable): Rails 5 WebSocket protocol, uses nio4r for a WebSocket server
|
20
|
+
- [Celluloid](https://github.com/celluloid/celluloid-io): Actor-based concurrency framework, uses nio4r for async I/O
|
21
|
+
- [Async](https://github.com/socketry/async): Asynchronous I/O framework for Ruby
|
22
|
+
- [Puma](https://github.com/puma/puma): Ruby/Rack web server built for concurrency
|
28
23
|
|
29
24
|
## Goals
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
- Expose high-level interfaces for stateful IO selectors
|
27
|
+
- Keep the API small to maximize both portability and performance across many
|
28
|
+
different OSes and Ruby VMs
|
29
|
+
- Provide inherently thread-safe facilities for working with IO objects
|
35
30
|
|
36
31
|
## Supported platforms
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
33
|
+
- Ruby 2.4
|
34
|
+
- Ruby 2.5
|
35
|
+
- Ruby 2.6
|
36
|
+
- Ruby 2.7
|
37
|
+
- Ruby 3.0
|
38
|
+
- [JRuby](https://github.com/jruby/jruby)
|
39
|
+
- [TruffleRuby](https://github.com/oracle/truffleruby)
|
45
40
|
|
46
41
|
## Supported backends
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
- **libev**: MRI C extension targeting multiple native IO selector APIs (e.g epoll, kqueue)
|
44
|
+
- **Java NIO**: JRuby extension which wraps the Java NIO subsystem
|
45
|
+
- **Pure Ruby**: `Kernel.select`-based backend that should work on any Ruby interpreter
|
51
46
|
|
52
47
|
## Documentation
|
53
48
|
|
54
49
|
[Please see the nio4r wiki](https://github.com/socketry/nio4r/wiki)
|
55
50
|
for more detailed documentation and usage notes:
|
56
51
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
[Getting Started]: https://github.com/socketry/nio4r/wiki/Getting-Started
|
63
|
-
[Selectors]: https://github.com/socketry/nio4r/wiki/Selectors
|
64
|
-
[Monitors]: https://github.com/socketry/nio4r/wiki/Monitors
|
65
|
-
[Byte Buffers]: https://github.com/socketry/nio4r/wiki/Byte-Buffers
|
52
|
+
- [Getting Started](https://github.com/socketry/nio4r/wiki/Getting-Started): Introduction to nio4r's components
|
53
|
+
- [Selectors](https://github.com/socketry/nio4r/wiki/Selectors): monitor multiple `IO` objects for readiness events
|
54
|
+
- [Monitors](https://github.com/socketry/nio4r/wiki/Monitors): control interests and inspect readiness for specific `IO` objects
|
55
|
+
- [Byte Buffers](https://github.com/socketry/nio4r/wiki/Byte-Buffers): fixed-size native buffers for high-performance I/O
|
66
56
|
|
67
57
|
See also:
|
68
58
|
|
69
|
-
|
59
|
+
- [YARD API documentation](http://www.rubydoc.info/gems/nio4r/frames)
|
70
60
|
|
71
61
|
## Non-goals
|
72
62
|
|
73
|
-
**nio4r** is not a full-featured event framework like [EventMachine] or [Cool.io].
|
63
|
+
**nio4r** is not a full-featured event framework like [EventMachine](https://github.com/eventmachine/eventmachine) or [Cool.io](https://coolio.github.io/).
|
74
64
|
Instead, nio4r is the sort of thing you might write a library like that on
|
75
65
|
top of. nio4r provides a minimal API such that individual Ruby implementers
|
76
66
|
may choose to produce optimized versions for their platform, without having
|
77
67
|
to maintain a large codebase.
|
78
68
|
|
79
|
-
[EventMachine]: https://github.com/eventmachine/eventmachine
|
80
|
-
[Cool.io]: https://coolio.github.io/
|
81
|
-
|
82
69
|
## Releases
|
83
70
|
|
84
71
|
### CRuby
|
85
72
|
|
86
|
-
|
87
|
-
rake
|
88
|
-
rake release
|
89
|
-
```
|
73
|
+
rake clean
|
74
|
+
rake release
|
90
75
|
|
91
76
|
### JRuby
|
92
77
|
|
93
78
|
You might need to delete `Gemfile.lock` before trying to `bundle install`.
|
94
79
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
rake
|
106
|
-
rake
|
107
|
-
rake release
|
108
|
-
```
|
80
|
+
# Ensure you have the correct JDK:
|
81
|
+
pacman -Syu jdk-openjdk
|
82
|
+
archlinux-java set java-19-openjdk
|
83
|
+
|
84
|
+
# Ensure you are using jruby:
|
85
|
+
chruby jruby
|
86
|
+
bundle update
|
87
|
+
|
88
|
+
# Build the package:
|
89
|
+
rake clean
|
90
|
+
rake compile
|
91
|
+
rake release
|
data/spec/nio/bytebuffer_spec.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2016, by Upekshe Jayasekera.
|
5
|
+
# Copyright, 2016-2017, by Tony Arcieri.
|
6
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
7
|
+
# Copyright, 2020, by Thomas Dziedzic.
|
8
|
+
|
3
9
|
require "spec_helper"
|
4
10
|
|
5
11
|
RSpec.describe NIO::ByteBuffer do
|
data/spec/nio/monitor_spec.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2011-2018, by Tony Arcieri.
|
5
|
+
# Copyright, 2012, by Logan Bowers.
|
6
|
+
# Copyright, 2015, by Tiago Cardoso.
|
7
|
+
# Copyright, 2015, by Upekshe Jayasekera.
|
8
|
+
# Copyright, 2018-2023, by Samuel Williams.
|
9
|
+
|
3
10
|
require "spec_helper"
|
4
11
|
require "socket"
|
5
12
|
|
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2012-2017, by Tony Arcieri.
|
5
|
+
# Copyright, 2012, by Logan Bowers.
|
6
|
+
# Copyright, 2017, by Gregory Longtin.
|
7
|
+
# Copyright, 2023, by Samuel Williams.
|
8
|
+
|
3
9
|
require "spec_helper"
|
4
10
|
|
5
11
|
RSpec.describe "IO.pipe" do
|
@@ -1,5 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2012-2017, by Tony Arcieri.
|
5
|
+
# Copyright, 2012, by Logan Bowers.
|
6
|
+
# Copyright, 2017-2020, by Gregory Longtin.
|
7
|
+
# Copyright, 2019, by Cédric Boutillier.
|
8
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
9
|
+
|
3
10
|
require "spec_helper"
|
4
11
|
require "openssl"
|
5
12
|
|
@@ -1,5 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2012-2017, by Tony Arcieri.
|
5
|
+
# Copyright, 2012, by Bernd Ahlers.
|
6
|
+
# Copyright, 2012, by Logan Bowers.
|
7
|
+
# Copyright, 2013, by Tim Carey-Smith.
|
8
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
9
|
+
|
3
10
|
require "spec_helper"
|
4
11
|
|
5
12
|
RSpec.describe TCPSocket do
|
@@ -1,5 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2012-2017, by Tony Arcieri.
|
5
|
+
# Copyright, 2017, by Gregory Longtin.
|
6
|
+
# Copyright, 2017, by Olle Jonsson.
|
7
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
8
|
+
# Copyright, 2020, by Thomas Dziedzic.
|
9
|
+
|
3
10
|
require "spec_helper"
|
4
11
|
|
5
12
|
RSpec.describe UDPSocket, if: !defined?(JRUBY_VERSION) do
|
data/spec/nio/selector_spec.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2011-2017, by Tony Arcieri.
|
5
|
+
# Copyright, 2012, by Logan Bowers.
|
6
|
+
# Copyright, 2013, by Ravil Bayramgalin.
|
7
|
+
# Copyright, 2013, by Tim Carey-Smith.
|
8
|
+
# Copyright, 2015, by Vladimir Kochnev.
|
9
|
+
# Copyright, 2016, by Tiago Cardoso.
|
10
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
11
|
+
# Copyright, 2019, by Jesús Burgos Maciá.
|
12
|
+
# Copyright, 2020, by Thomas Dziedzic.
|
13
|
+
# Copyright, 2021, by Joao Fernandes.
|
14
|
+
|
3
15
|
require "spec_helper"
|
4
16
|
require "timeout"
|
5
17
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2011-2017, by Tony Arcieri.
|
5
|
+
# Copyright, 2017, by Gregory Longtin.
|
6
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
7
|
+
# Copyright, 2021, by Joao Fernandes.
|
8
|
+
|
3
9
|
require "nio"
|
4
10
|
require "support/selectable_examples"
|
5
11
|
|
@@ -1,5 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2012-2017, by Tony Arcieri.
|
5
|
+
# Copyright, 2012, by Logan Bowers.
|
6
|
+
# Copyright, 2013, by Tim Carey-Smith.
|
7
|
+
# Copyright, 2017-2019, by Gregory Longtin.
|
8
|
+
# Copyright, 2017, by Tiago Cardoso.
|
9
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
10
|
+
|
3
11
|
RSpec.shared_context NIO::Selector do
|
4
12
|
let(:selector) {@selector = NIO::Selector.new}
|
5
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nio4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,6 +48,7 @@ extra_rdoc_files: []
|
|
48
48
|
files:
|
49
49
|
- ".github/workflows/workflow.yml"
|
50
50
|
- ".gitignore"
|
51
|
+
- ".mailmap"
|
51
52
|
- ".rspec"
|
52
53
|
- ".rubocop.yml"
|
53
54
|
- Gemfile
|
@@ -107,13 +108,14 @@ files:
|
|
107
108
|
- spec/support/selectable_examples.rb
|
108
109
|
homepage: https://github.com/socketry/nio4r
|
109
110
|
licenses:
|
110
|
-
- MIT
|
111
|
+
- MIT AND (BSD-2-Clause OR GPL-2.0-or-later)
|
111
112
|
metadata:
|
112
113
|
bug_tracker_uri: https://github.com/socketry/nio4r/issues
|
113
|
-
changelog_uri: https://github.com/socketry/nio4r/blob/
|
114
|
-
documentation_uri: https://www.rubydoc.info/gems/nio4r/2.
|
115
|
-
source_code_uri: https://github.com/socketry/nio4r/tree/v2.
|
114
|
+
changelog_uri: https://github.com/socketry/nio4r/blob/main/changes.md
|
115
|
+
documentation_uri: https://www.rubydoc.info/gems/nio4r/2.7.0
|
116
|
+
source_code_uri: https://github.com/socketry/nio4r/tree/v2.7.0
|
116
117
|
wiki_uri: https://github.com/socketry/nio4r/wiki
|
118
|
+
funding_uri: https://github.com/sponsors/ioquatix/
|
117
119
|
post_install_message:
|
118
120
|
rdoc_options: []
|
119
121
|
require_paths:
|