nio4r 2.4.0 → 2.5.4
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/.github/workflows/workflow.yml +43 -0
- data/.rubocop.yml +30 -11
- data/CHANGES.md +46 -0
- data/Gemfile +1 -1
- data/README.md +56 -30
- data/examples/echo_server.rb +2 -2
- data/ext/libev/Changes +20 -1
- data/ext/libev/README +2 -1
- data/ext/libev/ev.c +112 -64
- data/ext/libev/ev.h +12 -11
- data/ext/libev/ev_epoll.c +25 -14
- data/ext/libev/ev_kqueue.c +11 -5
- data/ext/libev/ev_linuxaio.c +642 -0
- data/ext/libev/ev_poll.c +13 -8
- data/ext/libev/ev_port.c +5 -2
- data/ext/libev/ev_vars.h +12 -1
- data/ext/libev/ev_wrap.h +16 -0
- data/ext/nio4r/.clang-format +16 -0
- data/ext/nio4r/bytebuffer.c +27 -28
- data/ext/nio4r/extconf.rb +4 -0
- data/ext/nio4r/libev.h +1 -3
- data/ext/nio4r/monitor.c +34 -31
- data/ext/nio4r/nio4r.h +7 -12
- data/ext/nio4r/org/nio4r/Selector.java +5 -1
- data/ext/nio4r/selector.c +50 -51
- data/lib/nio/bytebuffer.rb +4 -0
- data/lib/nio/monitor.rb +1 -1
- data/lib/nio/selector.rb +1 -1
- data/lib/nio/version.rb +1 -1
- data/nio4r.gemspec +10 -2
- data/spec/nio/bytebuffer_spec.rb +0 -1
- data/spec/nio/selectables/ssl_socket_spec.rb +3 -1
- data/spec/nio/selectables/udp_socket_spec.rb +2 -2
- data/spec/nio/selector_spec.rb +23 -5
- metadata +16 -12
- data/.travis.yml +0 -29
- data/Guardfile +0 -10
- data/LICENSE.txt +0 -20
- data/appveyor.yml +0 -40
data/ext/nio4r/nio4r.h
CHANGED
@@ -6,12 +6,11 @@
|
|
6
6
|
#ifndef NIO4R_H
|
7
7
|
#define NIO4R_H
|
8
8
|
|
9
|
+
#include "libev.h"
|
9
10
|
#include "ruby.h"
|
10
11
|
#include "ruby/io.h"
|
11
|
-
#include "libev.h"
|
12
12
|
|
13
|
-
struct NIO_Selector
|
14
|
-
{
|
13
|
+
struct NIO_Selector {
|
15
14
|
struct ev_loop *ev_loop;
|
16
15
|
struct ev_timer timer; /* for timeouts */
|
17
16
|
struct ev_io wakeup;
|
@@ -24,31 +23,27 @@ struct NIO_Selector
|
|
24
23
|
VALUE ready_array;
|
25
24
|
};
|
26
25
|
|
27
|
-
struct NIO_callback_data
|
28
|
-
{
|
26
|
+
struct NIO_callback_data {
|
29
27
|
VALUE *monitor;
|
30
28
|
struct NIO_Selector *selector;
|
31
29
|
};
|
32
30
|
|
33
|
-
struct NIO_Monitor
|
34
|
-
{
|
31
|
+
struct NIO_Monitor {
|
35
32
|
VALUE self;
|
36
33
|
int interests, revents;
|
37
34
|
struct ev_io ev_io;
|
38
35
|
struct NIO_Selector *selector;
|
39
36
|
};
|
40
37
|
|
41
|
-
struct NIO_ByteBuffer
|
42
|
-
{
|
38
|
+
struct NIO_ByteBuffer {
|
43
39
|
char *buffer;
|
44
40
|
int position, limit, capacity, mark;
|
45
41
|
};
|
46
42
|
|
47
|
-
|
48
43
|
#ifdef GetReadFile
|
49
|
-
#
|
44
|
+
#define FPTR_TO_FD(fptr) (fileno(GetReadFile(fptr)))
|
50
45
|
#else
|
51
|
-
#
|
46
|
+
#define FPTR_TO_FD(fptr) fptr->fd
|
52
47
|
#endif /* GetReadFile */
|
53
48
|
|
54
49
|
/* Thunk between libev callbacks in NIO::Monitors and NIO::Selectors */
|
@@ -19,6 +19,7 @@ import org.jruby.anno.JRubyMethod;
|
|
19
19
|
import org.jruby.runtime.Block;
|
20
20
|
import org.jruby.runtime.ThreadContext;
|
21
21
|
import org.jruby.runtime.builtin.IRubyObject;
|
22
|
+
import org.jruby.util.io.OpenFile;
|
22
23
|
|
23
24
|
import org.nio4r.Monitor;
|
24
25
|
|
@@ -136,7 +137,10 @@ public class Selector extends RubyObject {
|
|
136
137
|
@JRubyMethod
|
137
138
|
public IRubyObject deregister(ThreadContext context, IRubyObject io) {
|
138
139
|
Ruby runtime = context.getRuntime();
|
139
|
-
|
140
|
+
OpenFile file = RubyIO.convertToIO(context, io).getOpenFileInitialized();
|
141
|
+
if (file.fd() == null)
|
142
|
+
return context.nil;
|
143
|
+
Channel rawChannel = file.channel();
|
140
144
|
|
141
145
|
if(!(rawChannel instanceof SelectableChannel)) {
|
142
146
|
throw runtime.newArgumentError("not a selectable IO object");
|
data/ext/nio4r/selector.c
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
#include "nio4r.h"
|
7
7
|
#ifdef HAVE_RUBYSIG_H
|
8
|
-
#
|
8
|
+
#include "rubysig.h"
|
9
9
|
#endif
|
10
10
|
|
11
11
|
#ifdef HAVE_UNISTD_H
|
@@ -14,11 +14,11 @@
|
|
14
14
|
#include <io.h>
|
15
15
|
#endif
|
16
16
|
|
17
|
-
#include <fcntl.h>
|
18
17
|
#include <assert.h>
|
18
|
+
#include <fcntl.h>
|
19
19
|
|
20
20
|
static VALUE mNIO = Qnil;
|
21
|
-
static VALUE cNIO_Monitor
|
21
|
+
static VALUE cNIO_Monitor = Qnil;
|
22
22
|
static VALUE cNIO_Selector = Qnil;
|
23
23
|
|
24
24
|
/* Allocator/deallocator */
|
@@ -80,7 +80,7 @@ void Init_NIO_Selector()
|
|
80
80
|
rb_define_method(cNIO_Selector, "closed?", NIO_Selector_closed, 0);
|
81
81
|
rb_define_method(cNIO_Selector, "empty?", NIO_Selector_is_empty, 0);
|
82
82
|
|
83
|
-
cNIO_Monitor = rb_define_class_under(mNIO, "Monitor",
|
83
|
+
cNIO_Monitor = rb_define_class_under(mNIO, "Monitor", rb_cObject);
|
84
84
|
}
|
85
85
|
|
86
86
|
/* Create the libev event loop and incoming event buffer */
|
@@ -95,13 +95,12 @@ static VALUE NIO_Selector_allocate(VALUE klass)
|
|
95
95
|
safety. Pipes are nice and safe to use between threads.
|
96
96
|
|
97
97
|
Note that Java NIO uses this same mechanism */
|
98
|
-
if(pipe(fds) < 0) {
|
98
|
+
if (pipe(fds) < 0) {
|
99
99
|
rb_sys_fail("pipe");
|
100
100
|
}
|
101
101
|
|
102
102
|
/* Use non-blocking reads/writes during wakeup, in case the buffer is full */
|
103
|
-
if(fcntl(fds[0], F_SETFL, O_NONBLOCK) < 0 ||
|
104
|
-
fcntl(fds[1], F_SETFL, O_NONBLOCK) < 0) {
|
103
|
+
if (fcntl(fds[0], F_SETFL, O_NONBLOCK) < 0 || fcntl(fds[1], F_SETFL, O_NONBLOCK) < 0) {
|
105
104
|
rb_sys_fail("fcntl");
|
106
105
|
}
|
107
106
|
|
@@ -127,7 +126,7 @@ static VALUE NIO_Selector_allocate(VALUE klass)
|
|
127
126
|
/* NIO selectors store all Ruby objects in instance variables so mark is a stub */
|
128
127
|
static void NIO_Selector_mark(struct NIO_Selector *selector)
|
129
128
|
{
|
130
|
-
if(selector->ready_array != Qnil) {
|
129
|
+
if (selector->ready_array != Qnil) {
|
131
130
|
rb_gc_mark(selector->ready_array);
|
132
131
|
}
|
133
132
|
}
|
@@ -136,14 +135,14 @@ static void NIO_Selector_mark(struct NIO_Selector *selector)
|
|
136
135
|
Called by both NIO::Selector#close and the finalizer below */
|
137
136
|
static void NIO_Selector_shutdown(struct NIO_Selector *selector)
|
138
137
|
{
|
139
|
-
if(selector->closed) {
|
138
|
+
if (selector->closed) {
|
140
139
|
return;
|
141
140
|
}
|
142
141
|
|
143
142
|
close(selector->wakeup_reader);
|
144
143
|
close(selector->wakeup_writer);
|
145
144
|
|
146
|
-
if(selector->ev_loop) {
|
145
|
+
if (selector->ev_loop) {
|
147
146
|
ev_loop_destroy(selector->ev_loop);
|
148
147
|
selector->ev_loop = 0;
|
149
148
|
}
|
@@ -159,27 +158,28 @@ static void NIO_Selector_free(struct NIO_Selector *selector)
|
|
159
158
|
}
|
160
159
|
|
161
160
|
/* Return an array of symbols for supported backends */
|
162
|
-
static VALUE NIO_Selector_supported_backends(VALUE klass)
|
161
|
+
static VALUE NIO_Selector_supported_backends(VALUE klass)
|
162
|
+
{
|
163
163
|
unsigned int backends = ev_supported_backends();
|
164
164
|
VALUE result = rb_ary_new();
|
165
165
|
|
166
|
-
if(backends & EVBACKEND_EPOLL) {
|
166
|
+
if (backends & EVBACKEND_EPOLL) {
|
167
167
|
rb_ary_push(result, ID2SYM(rb_intern("epoll")));
|
168
168
|
}
|
169
169
|
|
170
|
-
if(backends & EVBACKEND_POLL) {
|
170
|
+
if (backends & EVBACKEND_POLL) {
|
171
171
|
rb_ary_push(result, ID2SYM(rb_intern("poll")));
|
172
172
|
}
|
173
173
|
|
174
|
-
if(backends & EVBACKEND_KQUEUE) {
|
174
|
+
if (backends & EVBACKEND_KQUEUE) {
|
175
175
|
rb_ary_push(result, ID2SYM(rb_intern("kqueue")));
|
176
176
|
}
|
177
177
|
|
178
|
-
if(backends & EVBACKEND_SELECT) {
|
178
|
+
if (backends & EVBACKEND_SELECT) {
|
179
179
|
rb_ary_push(result, ID2SYM(rb_intern("select")));
|
180
180
|
}
|
181
181
|
|
182
|
-
if(backends & EVBACKEND_PORT) {
|
182
|
+
if (backends & EVBACKEND_PORT) {
|
183
183
|
rb_ary_push(result, ID2SYM(rb_intern("port")));
|
184
184
|
}
|
185
185
|
|
@@ -201,27 +201,25 @@ static VALUE NIO_Selector_initialize(int argc, VALUE *argv, VALUE self)
|
|
201
201
|
|
202
202
|
rb_scan_args(argc, argv, "01", &backend);
|
203
203
|
|
204
|
-
if(backend != Qnil) {
|
205
|
-
if(!rb_ary_includes(NIO_Selector_supported_backends(CLASS_OF(self)), backend)) {
|
206
|
-
rb_raise(rb_eArgError, "unsupported backend: %s",
|
207
|
-
RSTRING_PTR(rb_funcall(backend, rb_intern("inspect"), 0)));
|
204
|
+
if (backend != Qnil) {
|
205
|
+
if (!rb_ary_includes(NIO_Selector_supported_backends(CLASS_OF(self)), backend)) {
|
206
|
+
rb_raise(rb_eArgError, "unsupported backend: %s", RSTRING_PTR(rb_funcall(backend, rb_intern("inspect"), 0)));
|
208
207
|
}
|
209
208
|
|
210
209
|
backend_id = SYM2ID(backend);
|
211
210
|
|
212
|
-
if(backend_id == rb_intern("epoll")) {
|
211
|
+
if (backend_id == rb_intern("epoll")) {
|
213
212
|
flags = EVBACKEND_EPOLL;
|
214
|
-
} else if(backend_id == rb_intern("poll")) {
|
213
|
+
} else if (backend_id == rb_intern("poll")) {
|
215
214
|
flags = EVBACKEND_POLL;
|
216
|
-
} else if(backend_id == rb_intern("kqueue")) {
|
215
|
+
} else if (backend_id == rb_intern("kqueue")) {
|
217
216
|
flags = EVBACKEND_KQUEUE;
|
218
|
-
} else if(backend_id == rb_intern("select")) {
|
217
|
+
} else if (backend_id == rb_intern("select")) {
|
219
218
|
flags = EVBACKEND_SELECT;
|
220
|
-
} else if(backend_id == rb_intern("port")) {
|
219
|
+
} else if (backend_id == rb_intern("port")) {
|
221
220
|
flags = EVBACKEND_PORT;
|
222
221
|
} else {
|
223
|
-
rb_raise(rb_eArgError, "unsupported backend: %s",
|
224
|
-
RSTRING_PTR(rb_funcall(backend, rb_intern("inspect"), 0)));
|
222
|
+
rb_raise(rb_eArgError, "unsupported backend: %s", RSTRING_PTR(rb_funcall(backend, rb_intern("inspect"), 0)));
|
225
223
|
}
|
226
224
|
}
|
227
225
|
|
@@ -229,7 +227,7 @@ static VALUE NIO_Selector_initialize(int argc, VALUE *argv, VALUE self)
|
|
229
227
|
assert(!selector->ev_loop);
|
230
228
|
|
231
229
|
selector->ev_loop = ev_loop_new(flags);
|
232
|
-
if(!selector->ev_loop) {
|
230
|
+
if (!selector->ev_loop) {
|
233
231
|
rb_raise(rb_eIOError, "error initializing event loop");
|
234
232
|
}
|
235
233
|
|
@@ -245,11 +243,12 @@ static VALUE NIO_Selector_initialize(int argc, VALUE *argv, VALUE self)
|
|
245
243
|
return Qnil;
|
246
244
|
}
|
247
245
|
|
248
|
-
static VALUE NIO_Selector_backend(VALUE self)
|
246
|
+
static VALUE NIO_Selector_backend(VALUE self)
|
247
|
+
{
|
249
248
|
struct NIO_Selector *selector;
|
250
249
|
|
251
250
|
Data_Get_Struct(self, struct NIO_Selector, selector);
|
252
|
-
if(selector->closed) {
|
251
|
+
if (selector->closed) {
|
253
252
|
rb_raise(rb_eIOError, "selector is closed");
|
254
253
|
}
|
255
254
|
|
@@ -277,7 +276,7 @@ static VALUE NIO_Selector_synchronize(VALUE self, VALUE (*func)(VALUE *args), VA
|
|
277
276
|
current_thread = rb_thread_current();
|
278
277
|
lock_holder = rb_ivar_get(self, rb_intern("lock_holder"));
|
279
278
|
|
280
|
-
if(lock_holder != current_thread) {
|
279
|
+
if (lock_holder != current_thread) {
|
281
280
|
lock = rb_ivar_get(self, rb_intern("lock"));
|
282
281
|
rb_funcall(lock, rb_intern("lock"), 0);
|
283
282
|
rb_ivar_set(self, rb_intern("lock_holder"), current_thread);
|
@@ -306,7 +305,7 @@ static VALUE NIO_Selector_unlock(VALUE self)
|
|
306
305
|
/* Register an IO object with the selector for the given interests */
|
307
306
|
static VALUE NIO_Selector_register(VALUE self, VALUE io, VALUE interests)
|
308
307
|
{
|
309
|
-
VALUE args[3] = {self, io, interests};
|
308
|
+
VALUE args[3] = { self, io, interests };
|
310
309
|
return NIO_Selector_synchronize(self, NIO_Selector_register_synchronized, args);
|
311
310
|
}
|
312
311
|
|
@@ -322,14 +321,14 @@ static VALUE NIO_Selector_register_synchronized(VALUE *args)
|
|
322
321
|
interests = args[2];
|
323
322
|
|
324
323
|
Data_Get_Struct(self, struct NIO_Selector, selector);
|
325
|
-
if(selector->closed) {
|
324
|
+
if (selector->closed) {
|
326
325
|
rb_raise(rb_eIOError, "selector is closed");
|
327
326
|
}
|
328
327
|
|
329
328
|
selectables = rb_ivar_get(self, rb_intern("selectables"));
|
330
329
|
monitor = rb_hash_lookup(selectables, io);
|
331
330
|
|
332
|
-
if(monitor != Qnil)
|
331
|
+
if (monitor != Qnil)
|
333
332
|
rb_raise(rb_eArgError, "this IO is already registered with selector");
|
334
333
|
|
335
334
|
/* Create a new NIO::Monitor */
|
@@ -346,7 +345,7 @@ static VALUE NIO_Selector_register_synchronized(VALUE *args)
|
|
346
345
|
/* Deregister an IO object from the selector */
|
347
346
|
static VALUE NIO_Selector_deregister(VALUE self, VALUE io)
|
348
347
|
{
|
349
|
-
VALUE args[2] = {self, io};
|
348
|
+
VALUE args[2] = { self, io };
|
350
349
|
return NIO_Selector_synchronize(self, NIO_Selector_deregister_synchronized, args);
|
351
350
|
}
|
352
351
|
|
@@ -361,7 +360,7 @@ static VALUE NIO_Selector_deregister_synchronized(VALUE *args)
|
|
361
360
|
selectables = rb_ivar_get(self, rb_intern("selectables"));
|
362
361
|
monitor = rb_hash_delete(selectables, io);
|
363
362
|
|
364
|
-
if(monitor != Qnil) {
|
363
|
+
if (monitor != Qnil) {
|
365
364
|
rb_funcall(monitor, rb_intern("close"), 1, Qfalse);
|
366
365
|
}
|
367
366
|
|
@@ -385,7 +384,7 @@ static VALUE NIO_Selector_select(int argc, VALUE *argv, VALUE self)
|
|
385
384
|
|
386
385
|
rb_scan_args(argc, argv, "01", &timeout);
|
387
386
|
|
388
|
-
if(timeout != Qnil && NUM2DBL(timeout) < 0) {
|
387
|
+
if (timeout != Qnil && NUM2DBL(timeout) < 0) {
|
389
388
|
rb_raise(rb_eArgError, "time interval must be positive");
|
390
389
|
}
|
391
390
|
|
@@ -404,26 +403,26 @@ static VALUE NIO_Selector_select_synchronized(VALUE *args)
|
|
404
403
|
|
405
404
|
Data_Get_Struct(args[0], struct NIO_Selector, selector);
|
406
405
|
|
407
|
-
if(selector->closed) {
|
406
|
+
if (selector->closed) {
|
408
407
|
rb_raise(rb_eIOError, "selector is closed");
|
409
408
|
}
|
410
409
|
|
411
|
-
if(!rb_block_given_p()) {
|
410
|
+
if (!rb_block_given_p()) {
|
412
411
|
selector->ready_array = rb_ary_new();
|
413
412
|
}
|
414
413
|
|
415
414
|
ready = NIO_Selector_run(selector, args[1]);
|
416
415
|
|
417
416
|
/* Timeout */
|
418
|
-
if(ready < 0) {
|
419
|
-
if(!rb_block_given_p()) {
|
417
|
+
if (ready < 0) {
|
418
|
+
if (!rb_block_given_p()) {
|
420
419
|
selector->ready_array = Qnil;
|
421
420
|
}
|
422
421
|
|
423
422
|
return Qnil;
|
424
423
|
}
|
425
424
|
|
426
|
-
if(rb_block_given_p()) {
|
425
|
+
if (rb_block_given_p()) {
|
427
426
|
return INT2NUM(ready);
|
428
427
|
} else {
|
429
428
|
ready_array = selector->ready_array;
|
@@ -441,12 +440,12 @@ static int NIO_Selector_run(struct NIO_Selector *selector, VALUE timeout)
|
|
441
440
|
selector->selecting = 1;
|
442
441
|
selector->wakeup_fired = 0;
|
443
442
|
|
444
|
-
if(timeout == Qnil) {
|
443
|
+
if (timeout == Qnil) {
|
445
444
|
/* Don't fire a wakeup timeout if we weren't passed one */
|
446
445
|
ev_timer_stop(selector->ev_loop, &selector->timer);
|
447
446
|
} else {
|
448
447
|
timeout_val = NUM2DBL(timeout);
|
449
|
-
if(timeout_val == 0) {
|
448
|
+
if (timeout_val == 0) {
|
450
449
|
/* If we've been given an explicit timeout of 0, perform a non-blocking
|
451
450
|
select operation */
|
452
451
|
ev_run_flags = EVRUN_NOWAIT;
|
@@ -462,7 +461,7 @@ static int NIO_Selector_run(struct NIO_Selector *selector, VALUE timeout)
|
|
462
461
|
result = selector->ready_count;
|
463
462
|
selector->selecting = selector->ready_count = 0;
|
464
463
|
|
465
|
-
if(result > 0 || selector->wakeup_fired) {
|
464
|
+
if (result > 0 || selector->wakeup_fired) {
|
466
465
|
selector->wakeup_fired = 0;
|
467
466
|
return result;
|
468
467
|
} else {
|
@@ -476,7 +475,7 @@ static VALUE NIO_Selector_wakeup(VALUE self)
|
|
476
475
|
struct NIO_Selector *selector;
|
477
476
|
Data_Get_Struct(self, struct NIO_Selector, selector);
|
478
477
|
|
479
|
-
if(selector->closed) {
|
478
|
+
if (selector->closed) {
|
480
479
|
rb_raise(rb_eIOError, "selector is closed");
|
481
480
|
}
|
482
481
|
|
@@ -489,7 +488,7 @@ static VALUE NIO_Selector_wakeup(VALUE self)
|
|
489
488
|
/* Close the selector and free system resources */
|
490
489
|
static VALUE NIO_Selector_close(VALUE self)
|
491
490
|
{
|
492
|
-
VALUE args[1] = {self};
|
491
|
+
VALUE args[1] = { self };
|
493
492
|
return NIO_Selector_synchronize(self, NIO_Selector_close_synchronized, args);
|
494
493
|
}
|
495
494
|
|
@@ -507,7 +506,7 @@ static VALUE NIO_Selector_close_synchronized(VALUE *args)
|
|
507
506
|
/* Is the selector closed? */
|
508
507
|
static VALUE NIO_Selector_closed(VALUE self)
|
509
508
|
{
|
510
|
-
VALUE args[1] = {self};
|
509
|
+
VALUE args[1] = { self };
|
511
510
|
return NIO_Selector_synchronize(self, NIO_Selector_closed_synchronized, args);
|
512
511
|
}
|
513
512
|
|
@@ -528,7 +527,6 @@ static VALUE NIO_Selector_is_empty(VALUE self)
|
|
528
527
|
return rb_funcall(selectables, rb_intern("empty?"), 0) == Qtrue ? Qtrue : Qfalse;
|
529
528
|
}
|
530
529
|
|
531
|
-
|
532
530
|
/* Called whenever a timeout fires on the event loop */
|
533
531
|
static void NIO_Selector_timeout_callback(struct ev_loop *ev_loop, struct ev_timer *timer, int revents)
|
534
532
|
{
|
@@ -542,7 +540,8 @@ static void NIO_Selector_wakeup_callback(struct ev_loop *ev_loop, struct ev_io *
|
|
542
540
|
selector->selecting = 0;
|
543
541
|
|
544
542
|
/* Drain the wakeup pipe, giving us level-triggered behavior */
|
545
|
-
while(read(selector->wakeup_reader, buffer, 128) > 0)
|
543
|
+
while (read(selector->wakeup_reader, buffer, 128) > 0)
|
544
|
+
;
|
546
545
|
}
|
547
546
|
|
548
547
|
/* libev callback fired whenever a monitor gets an event */
|
@@ -558,7 +557,7 @@ void NIO_Selector_monitor_callback(struct ev_loop *ev_loop, struct ev_io *io, in
|
|
558
557
|
selector->ready_count++;
|
559
558
|
monitor_data->revents = revents;
|
560
559
|
|
561
|
-
if(rb_block_given_p()) {
|
560
|
+
if (rb_block_given_p()) {
|
562
561
|
rb_yield(monitor);
|
563
562
|
} else {
|
564
563
|
assert(selector->ready_array != Qnil);
|
data/lib/nio/bytebuffer.rb
CHANGED
@@ -24,6 +24,7 @@ module NIO
|
|
24
24
|
# @return [NIO::ByteBuffer]
|
25
25
|
def initialize(capacity)
|
26
26
|
raise TypeError, "no implicit conversion of #{capacity.class} to Integer" unless capacity.is_a?(Integer)
|
27
|
+
|
27
28
|
@capacity = capacity
|
28
29
|
clear
|
29
30
|
end
|
@@ -119,9 +120,11 @@ module NIO
|
|
119
120
|
# @return [self]
|
120
121
|
def put(str)
|
121
122
|
raise TypeError, "expected String, got #{str.class}" unless str.respond_to?(:to_str)
|
123
|
+
|
122
124
|
str = str.to_str
|
123
125
|
|
124
126
|
raise OverflowError, "buffer is full" if str.length > @limit - @position
|
127
|
+
|
125
128
|
@buffer[@position...str.length] = str
|
126
129
|
@position += str.length
|
127
130
|
self
|
@@ -188,6 +191,7 @@ module NIO
|
|
188
191
|
# @raise [NIO::ByteBuffer::MarkUnsetError] mark has not been set (call `#mark` first)
|
189
192
|
def reset
|
190
193
|
raise MarkUnsetError, "mark has not been set" unless @mark
|
194
|
+
|
191
195
|
@position = @mark
|
192
196
|
self
|
193
197
|
end
|
data/lib/nio/monitor.rb
CHANGED
data/lib/nio/selector.rb
CHANGED
@@ -44,7 +44,7 @@ module NIO
|
|
44
44
|
# * :w - is the IO writeable?
|
45
45
|
# * :rw - is the IO either readable or writeable?
|
46
46
|
def register(io, interest)
|
47
|
-
unless io.is_a?
|
47
|
+
unless defined?(::OpenSSL) && io.is_a?(::OpenSSL::SSL::SSLSocket)
|
48
48
|
io = IO.try_convert(io)
|
49
49
|
end
|
50
50
|
|
data/lib/nio/version.rb
CHANGED