nio4r 2.5.2 → 2.5.7

Sign up to get free protection for your applications and to get access to all the features.
data/ext/libev/ev_vars.h CHANGED
@@ -118,6 +118,35 @@ VARx(int, linuxaio_submitmax)
118
118
  VARx(ev_io, linuxaio_epoll_w)
119
119
  #endif
120
120
 
121
+ #if EV_USE_IOURING || EV_GENWRAP
122
+ VARx(int, iouring_fd)
123
+ VARx(unsigned, iouring_to_submit);
124
+ VARx(int, iouring_entries)
125
+ VARx(int, iouring_max_entries)
126
+ VARx(void *, iouring_sq_ring)
127
+ VARx(void *, iouring_cq_ring)
128
+ VARx(void *, iouring_sqes)
129
+ VARx(uint32_t, iouring_sq_ring_size)
130
+ VARx(uint32_t, iouring_cq_ring_size)
131
+ VARx(uint32_t, iouring_sqes_size)
132
+ VARx(uint32_t, iouring_sq_head)
133
+ VARx(uint32_t, iouring_sq_tail)
134
+ VARx(uint32_t, iouring_sq_ring_mask)
135
+ VARx(uint32_t, iouring_sq_ring_entries)
136
+ VARx(uint32_t, iouring_sq_flags)
137
+ VARx(uint32_t, iouring_sq_dropped)
138
+ VARx(uint32_t, iouring_sq_array)
139
+ VARx(uint32_t, iouring_cq_head)
140
+ VARx(uint32_t, iouring_cq_tail)
141
+ VARx(uint32_t, iouring_cq_ring_mask)
142
+ VARx(uint32_t, iouring_cq_ring_entries)
143
+ VARx(uint32_t, iouring_cq_overflow)
144
+ VARx(uint32_t, iouring_cq_cqes)
145
+ VARx(ev_tstamp, iouring_tfd_to)
146
+ VARx(int, iouring_tfd)
147
+ VARx(ev_io, iouring_tfd_w)
148
+ #endif
149
+
121
150
  #if EV_USE_KQUEUE || EV_GENWRAP
122
151
  VARx(pid_t, kqueue_fd_pid)
123
152
  VARx(struct kevent *, kqueue_changes)
@@ -198,6 +227,11 @@ VARx(ev_io, sigfd_w)
198
227
  VARx(sigset_t, sigfd_set)
199
228
  #endif
200
229
 
230
+ #if EV_USE_TIMERFD || EV_GENWRAP
231
+ VARx(int, timerfd) /* timerfd for time jump detection */
232
+ VARx(ev_io, timerfd_w)
233
+ #endif
234
+
201
235
  VARx(unsigned int, origflags) /* original loop flags */
202
236
 
203
237
  #if EV_FEATURE_API || EV_GENWRAP
data/ext/libev/ev_win32.c CHANGED
@@ -154,8 +154,8 @@ ev_time (void)
154
154
  ui.u.LowPart = ft.dwLowDateTime;
155
155
  ui.u.HighPart = ft.dwHighDateTime;
156
156
 
157
- /* msvc cannot convert ulonglong to double... yes, it is that sucky */
158
- return (LONGLONG)(ui.QuadPart - 116444736000000000) * 1e-7;
157
+ /* also, msvc cannot convert ulonglong to double... yes, it is that sucky */
158
+ return EV_TS_FROM_USEC (((LONGLONG)(ui.QuadPart - 116444736000000000) * 1e-1));
159
159
  }
160
160
 
161
161
  #endif
data/ext/libev/ev_wrap.h CHANGED
@@ -44,6 +44,32 @@
44
44
  #define invoke_cb ((loop)->invoke_cb)
45
45
  #define io_blocktime ((loop)->io_blocktime)
46
46
  #define iocp ((loop)->iocp)
47
+ #define iouring_cq_cqes ((loop)->iouring_cq_cqes)
48
+ #define iouring_cq_head ((loop)->iouring_cq_head)
49
+ #define iouring_cq_overflow ((loop)->iouring_cq_overflow)
50
+ #define iouring_cq_ring ((loop)->iouring_cq_ring)
51
+ #define iouring_cq_ring_entries ((loop)->iouring_cq_ring_entries)
52
+ #define iouring_cq_ring_mask ((loop)->iouring_cq_ring_mask)
53
+ #define iouring_cq_ring_size ((loop)->iouring_cq_ring_size)
54
+ #define iouring_cq_tail ((loop)->iouring_cq_tail)
55
+ #define iouring_entries ((loop)->iouring_entries)
56
+ #define iouring_fd ((loop)->iouring_fd)
57
+ #define iouring_max_entries ((loop)->iouring_max_entries)
58
+ #define iouring_sq_array ((loop)->iouring_sq_array)
59
+ #define iouring_sq_dropped ((loop)->iouring_sq_dropped)
60
+ #define iouring_sq_flags ((loop)->iouring_sq_flags)
61
+ #define iouring_sq_head ((loop)->iouring_sq_head)
62
+ #define iouring_sq_ring ((loop)->iouring_sq_ring)
63
+ #define iouring_sq_ring_entries ((loop)->iouring_sq_ring_entries)
64
+ #define iouring_sq_ring_mask ((loop)->iouring_sq_ring_mask)
65
+ #define iouring_sq_ring_size ((loop)->iouring_sq_ring_size)
66
+ #define iouring_sq_tail ((loop)->iouring_sq_tail)
67
+ #define iouring_sqes ((loop)->iouring_sqes)
68
+ #define iouring_sqes_size ((loop)->iouring_sqes_size)
69
+ #define iouring_tfd ((loop)->iouring_tfd)
70
+ #define iouring_tfd_to ((loop)->iouring_tfd_to)
71
+ #define iouring_tfd_w ((loop)->iouring_tfd_w)
72
+ #define iouring_to_submit ((loop)->iouring_to_submit)
47
73
  #define kqueue_changecnt ((loop)->kqueue_changecnt)
48
74
  #define kqueue_changemax ((loop)->kqueue_changemax)
49
75
  #define kqueue_changes ((loop)->kqueue_changes)
@@ -97,6 +123,8 @@
97
123
  #define sigfd_w ((loop)->sigfd_w)
98
124
  #define timeout_blocktime ((loop)->timeout_blocktime)
99
125
  #define timercnt ((loop)->timercnt)
126
+ #define timerfd ((loop)->timerfd)
127
+ #define timerfd_w ((loop)->timerfd_w)
100
128
  #define timermax ((loop)->timermax)
101
129
  #define timers ((loop)->timers)
102
130
  #define userdata ((loop)->userdata)
@@ -151,6 +179,32 @@
151
179
  #undef invoke_cb
152
180
  #undef io_blocktime
153
181
  #undef iocp
182
+ #undef iouring_cq_cqes
183
+ #undef iouring_cq_head
184
+ #undef iouring_cq_overflow
185
+ #undef iouring_cq_ring
186
+ #undef iouring_cq_ring_entries
187
+ #undef iouring_cq_ring_mask
188
+ #undef iouring_cq_ring_size
189
+ #undef iouring_cq_tail
190
+ #undef iouring_entries
191
+ #undef iouring_fd
192
+ #undef iouring_max_entries
193
+ #undef iouring_sq_array
194
+ #undef iouring_sq_dropped
195
+ #undef iouring_sq_flags
196
+ #undef iouring_sq_head
197
+ #undef iouring_sq_ring
198
+ #undef iouring_sq_ring_entries
199
+ #undef iouring_sq_ring_mask
200
+ #undef iouring_sq_ring_size
201
+ #undef iouring_sq_tail
202
+ #undef iouring_sqes
203
+ #undef iouring_sqes_size
204
+ #undef iouring_tfd
205
+ #undef iouring_tfd_to
206
+ #undef iouring_tfd_w
207
+ #undef iouring_to_submit
154
208
  #undef kqueue_changecnt
155
209
  #undef kqueue_changemax
156
210
  #undef kqueue_changes
@@ -204,6 +258,8 @@
204
258
  #undef sigfd_w
205
259
  #undef timeout_blocktime
206
260
  #undef timercnt
261
+ #undef timerfd
262
+ #undef timerfd_w
207
263
  #undef timermax
208
264
  #undef timers
209
265
  #undef userdata
@@ -0,0 +1,16 @@
1
+ ---
2
+ Language: Cpp
3
+ BasedOnStyle: WebKit
4
+ AllowAllParametersOfDeclarationOnNextLine: false
5
+ BinPackArguments: false
6
+ BinPackParameters: false
7
+ AlignConsecutiveMacros: false
8
+ AlignConsecutiveAssignments: false
9
+ BreakBeforeBraces: Linux
10
+ BraceWrapping:
11
+ AfterControlStatement: Never
12
+ IndentCaseLabels: true
13
+ PointerAlignment: Right
14
+ SpaceBeforeParens: ControlStatements
15
+ IndentWidth: 4
16
+ ...
@@ -42,7 +42,7 @@ void Init_NIO_ByteBuffer()
42
42
  cNIO_ByteBuffer = rb_define_class_under(mNIO, "ByteBuffer", rb_cObject);
43
43
  rb_define_alloc_func(cNIO_ByteBuffer, NIO_ByteBuffer_allocate);
44
44
 
45
- cNIO_ByteBuffer_OverflowError = rb_define_class_under(cNIO_ByteBuffer, "OverflowError", rb_eIOError);
45
+ cNIO_ByteBuffer_OverflowError = rb_define_class_under(cNIO_ByteBuffer, "OverflowError", rb_eIOError);
46
46
  cNIO_ByteBuffer_UnderflowError = rb_define_class_under(cNIO_ByteBuffer, "UnderflowError", rb_eIOError);
47
47
  cNIO_ByteBuffer_MarkUnsetError = rb_define_class_under(cNIO_ByteBuffer, "MarkUnsetError", rb_eIOError);
48
48
 
@@ -85,8 +85,8 @@ static void NIO_ByteBuffer_gc_mark(struct NIO_ByteBuffer *buffer)
85
85
 
86
86
  static void NIO_ByteBuffer_free(struct NIO_ByteBuffer *buffer)
87
87
  {
88
- if(buffer->buffer)
89
- xfree(buffer->buffer);
88
+ if (buffer->buffer)
89
+ xfree(buffer->buffer);
90
90
  xfree(buffer);
91
91
  }
92
92
 
@@ -133,17 +133,17 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)
133
133
 
134
134
  pos = NUM2INT(new_position);
135
135
 
136
- if(pos < 0) {
136
+ if (pos < 0) {
137
137
  rb_raise(rb_eArgError, "negative position given");
138
138
  }
139
139
 
140
- if(pos > buffer->limit) {
140
+ if (pos > buffer->limit) {
141
141
  rb_raise(rb_eArgError, "specified position exceeds limit");
142
142
  }
143
143
 
144
144
  buffer->position = pos;
145
145
 
146
- if(buffer->mark > buffer->position) {
146
+ if (buffer->mark > buffer->position) {
147
147
  buffer->mark = MARK_UNSET;
148
148
  }
149
149
 
@@ -166,21 +166,21 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)
166
166
 
167
167
  lim = NUM2INT(new_limit);
168
168
 
169
- if(lim < 0) {
169
+ if (lim < 0) {
170
170
  rb_raise(rb_eArgError, "negative limit given");
171
171
  }
172
172
 
173
- if(lim > buffer->capacity) {
173
+ if (lim > buffer->capacity) {
174
174
  rb_raise(rb_eArgError, "specified limit exceeds capacity");
175
175
  }
176
176
 
177
177
  buffer->limit = lim;
178
178
 
179
- if(buffer->position > lim) {
179
+ if (buffer->position > lim) {
180
180
  buffer->position = lim;
181
181
  }
182
182
 
183
- if(buffer->mark > lim) {
183
+ if (buffer->mark > lim) {
184
184
  buffer->mark = MARK_UNSET;
185
185
  }
186
186
 
@@ -220,17 +220,17 @@ static VALUE NIO_ByteBuffer_get(int argc, VALUE *argv, VALUE self)
220
220
 
221
221
  rb_scan_args(argc, argv, "01", &length);
222
222
 
223
- if(length == Qnil) {
223
+ if (length == Qnil) {
224
224
  len = buffer->limit - buffer->position;
225
225
  } else {
226
226
  len = NUM2INT(length);
227
227
  }
228
228
 
229
- if(len < 0) {
229
+ if (len < 0) {
230
230
  rb_raise(rb_eArgError, "negative length given");
231
231
  }
232
232
 
233
- if(len > buffer->limit - buffer->position) {
233
+ if (len > buffer->limit - buffer->position) {
234
234
  rb_raise(cNIO_ByteBuffer_UnderflowError, "not enough data in buffer");
235
235
  }
236
236
 
@@ -248,11 +248,11 @@ static VALUE NIO_ByteBuffer_fetch(VALUE self, VALUE index)
248
248
 
249
249
  i = NUM2INT(index);
250
250
 
251
- if(i < 0) {
251
+ if (i < 0) {
252
252
  rb_raise(rb_eArgError, "negative index given");
253
253
  }
254
254
 
255
- if(i >= buffer->limit) {
255
+ if (i >= buffer->limit) {
256
256
  rb_raise(rb_eArgError, "specified index exceeds limit");
257
257
  }
258
258
 
@@ -268,7 +268,7 @@ static VALUE NIO_ByteBuffer_put(VALUE self, VALUE string)
268
268
  StringValue(string);
269
269
  length = RSTRING_LEN(string);
270
270
 
271
- if(length > buffer->limit - buffer->position) {
271
+ if (length > buffer->limit - buffer->position) {
272
272
  rb_raise(cNIO_ByteBuffer_OverflowError, "buffer is full");
273
273
  }
274
274
 
@@ -289,14 +289,14 @@ static VALUE NIO_ByteBuffer_read_from(VALUE self, VALUE io)
289
289
  rb_io_set_nonblock(fptr);
290
290
 
291
291
  nbytes = buffer->limit - buffer->position;
292
- if(nbytes == 0) {
292
+ if (nbytes == 0) {
293
293
  rb_raise(cNIO_ByteBuffer_OverflowError, "buffer is full");
294
294
  }
295
295
 
296
296
  bytes_read = read(FPTR_TO_FD(fptr), buffer->buffer + buffer->position, nbytes);
297
297
 
298
- if(bytes_read < 0) {
299
- if(errno == EAGAIN) {
298
+ if (bytes_read < 0) {
299
+ if (errno == EAGAIN) {
300
300
  return INT2NUM(0);
301
301
  } else {
302
302
  rb_sys_fail("write");
@@ -319,14 +319,14 @@ static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
319
319
  rb_io_set_nonblock(fptr);
320
320
 
321
321
  nbytes = buffer->limit - buffer->position;
322
- if(nbytes == 0) {
322
+ if (nbytes == 0) {
323
323
  rb_raise(cNIO_ByteBuffer_UnderflowError, "no data remaining in buffer");
324
324
  }
325
325
 
326
326
  bytes_written = write(FPTR_TO_FD(fptr), buffer->buffer + buffer->position, nbytes);
327
327
 
328
- if(bytes_written < 0) {
329
- if(errno == EAGAIN) {
328
+ if (bytes_written < 0) {
329
+ if (errno == EAGAIN) {
330
330
  return INT2NUM(0);
331
331
  } else {
332
332
  rb_sys_fail("write");
@@ -375,7 +375,7 @@ static VALUE NIO_ByteBuffer_reset(VALUE self)
375
375
  struct NIO_ByteBuffer *buffer;
376
376
  Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
377
377
 
378
- if(buffer->mark < 0) {
378
+ if (buffer->mark < 0) {
379
379
  rb_raise(cNIO_ByteBuffer_MarkUnsetError, "mark has not been set");
380
380
  } else {
381
381
  buffer->position = buffer->mark;
@@ -402,8 +402,8 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
402
402
  struct NIO_ByteBuffer *buffer;
403
403
  Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);
404
404
 
405
- if(rb_block_given_p()) {
406
- for(i = 0; i < buffer->limit; i++) {
405
+ if (rb_block_given_p()) {
406
+ for (i = 0; i < buffer->limit; i++) {
407
407
  rb_yield(INT2NUM(buffer->buffer[i]));
408
408
  }
409
409
  } else {
@@ -421,9 +421,8 @@ static VALUE NIO_ByteBuffer_inspect(VALUE self)
421
421
  return rb_sprintf(
422
422
  "#<%s:%p @position=%d @limit=%d @capacity=%d>",
423
423
  rb_class2name(CLASS_OF(self)),
424
- (void*)self,
424
+ (void *)self,
425
425
  buffer->position,
426
426
  buffer->limit,
427
- buffer->capacity
428
- );
427
+ buffer->capacity);
429
428
  }
data/ext/nio4r/extconf.rb CHANGED
@@ -4,6 +4,7 @@ require "rubygems"
4
4
 
5
5
  # Write a dummy Makefile on Windows because we use the pure Ruby implementation there
6
6
  if Gem.win_platform?
7
+ require "devkit" if RUBY_PLATFORM.include?("mingw")
7
8
  File.write("Makefile", "all install::\n")
8
9
  File.write("nio4r_ext.so", "")
9
10
  exit
@@ -14,6 +15,7 @@ require "mkmf"
14
15
  have_header("unistd.h")
15
16
 
16
17
  $defs << "-DEV_USE_LINUXAIO" if have_header("linux/aio_abi.h")
18
+ $defs << "-DEV_USE_IOURING" if have_header("linux/io_uring.h")
17
19
  $defs << "-DEV_USE_SELECT" if have_header("sys/select.h")
18
20
  $defs << "-DEV_USE_POLL" if have_type("port_event_t", "poll.h")
19
21
  $defs << "-DEV_USE_EPOLL" if have_header("sys/epoll.h")
@@ -21,7 +23,13 @@ $defs << "-DEV_USE_KQUEUE" if have_header("sys/event.h") && have_header("s
21
23
  $defs << "-DEV_USE_PORT" if have_type("port_event_t", "port.h")
22
24
  $defs << "-DHAVE_SYS_RESOURCE_H" if have_header("sys/resource.h")
23
25
 
26
+ $defs << "-DEV_STANDALONE" # prevent libev from assuming "config.h" exists
27
+
24
28
  CONFIG["optflags"] << " -fno-strict-aliasing" unless RUBY_PLATFORM =~ /mswin/
25
29
 
30
+ if RUBY_PLATFORM =~ /darwin/
31
+ $DLDFLAGS.gsub!(/\-arch\s+[^\s]+/, "")
32
+ end
33
+
26
34
  dir_config "nio4r_ext"
27
35
  create_makefile "nio4r_ext"
data/ext/nio4r/libev.h CHANGED
@@ -1,9 +1,7 @@
1
- #define EV_STANDALONE /* keeps ev from requiring config.h */
2
-
3
1
  #ifdef _WIN32
4
2
  #define EV_SELECT_IS_WINSOCKET 1
5
3
  #define EV_USE_MONOTONIC 0
6
4
  #define EV_USE_REALTIME 0
7
5
  #endif
8
6
 
9
- #include "../libev/ev.h"
7
+ #include "../libev/ev.h"
data/ext/nio4r/monitor.c CHANGED
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  #include "nio4r.h"
7
+ #include <assert.h>
7
8
 
8
9
  static VALUE mNIO = Qnil;
9
10
  static VALUE cNIO_Monitor = Qnil;
@@ -60,12 +61,14 @@ void Init_NIO_Monitor()
60
61
  static VALUE NIO_Monitor_allocate(VALUE klass)
61
62
  {
62
63
  struct NIO_Monitor *monitor = (struct NIO_Monitor *)xmalloc(sizeof(struct NIO_Monitor));
63
-
64
+ assert(monitor);
65
+ *monitor = (struct NIO_Monitor){.self = Qnil};
64
66
  return Data_Wrap_Struct(klass, NIO_Monitor_mark, NIO_Monitor_free, monitor);
65
67
  }
66
68
 
67
69
  static void NIO_Monitor_mark(struct NIO_Monitor *monitor)
68
70
  {
71
+ rb_gc_mark(monitor->self);
69
72
  }
70
73
 
71
74
  static void NIO_Monitor_free(struct NIO_Monitor *monitor)
@@ -84,15 +87,14 @@ static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE
84
87
 
85
88
  Data_Get_Struct(self, struct NIO_Monitor, monitor);
86
89
 
87
- if(interests_id == rb_intern("r")) {
90
+ if (interests_id == rb_intern("r")) {
88
91
  monitor->interests = EV_READ;
89
- } else if(interests_id == rb_intern("w")) {
92
+ } else if (interests_id == rb_intern("w")) {
90
93
  monitor->interests = EV_WRITE;
91
- } else if(interests_id == rb_intern("rw")) {
94
+ } else if (interests_id == rb_intern("rw")) {
92
95
  monitor->interests = EV_READ | EV_WRITE;
93
96
  } else {
94
- rb_raise(rb_eArgError, "invalid event type %s (must be :r, :w, or :rw)",
95
- RSTRING_PTR(rb_funcall(interests, rb_intern("inspect"), 0)));
97
+ rb_raise(rb_eArgError, "invalid event type %s (must be :r, :w, or :rw)", RSTRING_PTR(rb_funcall(interests, rb_intern("inspect"), 0)));
96
98
  }
97
99
 
98
100
  GetOpenFile(rb_convert_type(io, T_FILE, "IO", "to_io"), fptr);
@@ -112,7 +114,7 @@ static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE
112
114
  monitor->selector = selector;
113
115
 
114
116
  if (monitor->interests) {
115
- ev_io_start(selector->ev_loop, &monitor->ev_io);
117
+ ev_io_start(selector->ev_loop, &monitor->ev_io);
116
118
  }
117
119
 
118
120
  return Qnil;
@@ -127,17 +129,17 @@ static VALUE NIO_Monitor_close(int argc, VALUE *argv, VALUE self)
127
129
  rb_scan_args(argc, argv, "01", &deregister);
128
130
  selector = rb_ivar_get(self, rb_intern("selector"));
129
131
 
130
- if(selector != Qnil) {
132
+ if (selector != Qnil) {
131
133
  /* if ev_loop is 0, it means that the loop has been stopped already (see NIO_Selector_shutdown) */
132
- if(monitor->interests && monitor->selector->ev_loop) {
133
- ev_io_stop(monitor->selector->ev_loop, &monitor->ev_io);
134
+ if (monitor->interests && monitor->selector->ev_loop) {
135
+ ev_io_stop(monitor->selector->ev_loop, &monitor->ev_io);
134
136
  }
135
137
 
136
138
  monitor->selector = 0;
137
139
  rb_ivar_set(self, rb_intern("selector"), Qnil);
138
-
140
+
139
141
  /* Default value is true */
140
- if(deregister == Qtrue || deregister == Qnil) {
142
+ if (deregister == Qtrue || deregister == Qnil) {
141
143
  rb_funcall(selector, rb_intern("deregister"), 1, rb_ivar_get(self, rb_intern("io")));
142
144
  }
143
145
  }
@@ -165,7 +167,7 @@ static VALUE NIO_Monitor_interests(VALUE self)
165
167
 
166
168
  static VALUE NIO_Monitor_set_interests(VALUE self, VALUE interests)
167
169
  {
168
- if(NIL_P(interests)) {
170
+ if (NIL_P(interests)) {
169
171
  NIO_Monitor_update_interests(self, 0);
170
172
  } else {
171
173
  NIO_Monitor_update_interests(self, NIO_Monitor_symbol2interest(interests));
@@ -174,7 +176,8 @@ static VALUE NIO_Monitor_set_interests(VALUE self, VALUE interests)
174
176
  return rb_ivar_get(self, rb_intern("interests"));
175
177
  }
176
178
 
177
- static VALUE NIO_Monitor_add_interest(VALUE self, VALUE interest) {
179
+ static VALUE NIO_Monitor_add_interest(VALUE self, VALUE interest)
180
+ {
178
181
  struct NIO_Monitor *monitor;
179
182
  Data_Get_Struct(self, struct NIO_Monitor, monitor);
180
183
 
@@ -184,7 +187,8 @@ static VALUE NIO_Monitor_add_interest(VALUE self, VALUE interest) {
184
187
  return rb_ivar_get(self, rb_intern("interests"));
185
188
  }
186
189
 
187
- static VALUE NIO_Monitor_remove_interest(VALUE self, VALUE interest) {
190
+ static VALUE NIO_Monitor_remove_interest(VALUE self, VALUE interest)
191
+ {
188
192
  struct NIO_Monitor *monitor;
189
193
  Data_Get_Struct(self, struct NIO_Monitor, monitor);
190
194
 
@@ -214,11 +218,11 @@ static VALUE NIO_Monitor_readiness(VALUE self)
214
218
  struct NIO_Monitor *monitor;
215
219
  Data_Get_Struct(self, struct NIO_Monitor, monitor);
216
220
 
217
- if((monitor->revents & (EV_READ | EV_WRITE)) == (EV_READ | EV_WRITE)) {
221
+ if ((monitor->revents & (EV_READ | EV_WRITE)) == (EV_READ | EV_WRITE)) {
218
222
  return ID2SYM(rb_intern("rw"));
219
- } else if(monitor->revents & EV_READ) {
223
+ } else if (monitor->revents & EV_READ) {
220
224
  return ID2SYM(rb_intern("r"));
221
- } else if(monitor->revents & EV_WRITE) {
225
+ } else if (monitor->revents & EV_WRITE) {
222
226
  return ID2SYM(rb_intern("w"));
223
227
  } else {
224
228
  return Qnil;
@@ -230,7 +234,7 @@ static VALUE NIO_Monitor_is_readable(VALUE self)
230
234
  struct NIO_Monitor *monitor;
231
235
  Data_Get_Struct(self, struct NIO_Monitor, monitor);
232
236
 
233
- if(monitor->revents & EV_READ) {
237
+ if (monitor->revents & EV_READ) {
234
238
  return Qtrue;
235
239
  } else {
236
240
  return Qfalse;
@@ -242,7 +246,7 @@ static VALUE NIO_Monitor_is_writable(VALUE self)
242
246
  struct NIO_Monitor *monitor;
243
247
  Data_Get_Struct(self, struct NIO_Monitor, monitor);
244
248
 
245
- if(monitor->revents & EV_WRITE) {
249
+ if (monitor->revents & EV_WRITE) {
246
250
  return Qtrue;
247
251
  } else {
248
252
  return Qfalse;
@@ -256,15 +260,14 @@ static int NIO_Monitor_symbol2interest(VALUE interests)
256
260
  ID interests_id;
257
261
  interests_id = SYM2ID(interests);
258
262
 
259
- if(interests_id == rb_intern("r")) {
263
+ if (interests_id == rb_intern("r")) {
260
264
  return EV_READ;
261
- } else if(interests_id == rb_intern("w")) {
265
+ } else if (interests_id == rb_intern("w")) {
262
266
  return EV_WRITE;
263
- } else if(interests_id == rb_intern("rw")) {
267
+ } else if (interests_id == rb_intern("rw")) {
264
268
  return EV_READ | EV_WRITE;
265
269
  } else {
266
- rb_raise(rb_eArgError, "invalid interest type %s (must be :r, :w, or :rw)",
267
- RSTRING_PTR(rb_funcall(interests, rb_intern("inspect"), 0)));
270
+ rb_raise(rb_eArgError, "invalid interest type %s (must be :r, :w, or :rw)", RSTRING_PTR(rb_funcall(interests, rb_intern("inspect"), 0)));
268
271
  }
269
272
  }
270
273
 
@@ -274,12 +277,12 @@ static void NIO_Monitor_update_interests(VALUE self, int interests)
274
277
  struct NIO_Monitor *monitor;
275
278
  Data_Get_Struct(self, struct NIO_Monitor, monitor);
276
279
 
277
- if(NIO_Monitor_is_closed(self) == Qtrue) {
280
+ if (NIO_Monitor_is_closed(self) == Qtrue) {
278
281
  rb_raise(rb_eEOFError, "monitor is closed");
279
282
  }
280
283
 
281
- if(interests) {
282
- switch(interests) {
284
+ if (interests) {
285
+ switch (interests) {
283
286
  case EV_READ:
284
287
  interests_id = rb_intern("r");
285
288
  break;
@@ -298,9 +301,9 @@ static void NIO_Monitor_update_interests(VALUE self, int interests)
298
301
  rb_ivar_set(self, rb_intern("interests"), Qnil);
299
302
  }
300
303
 
301
- if(monitor->interests != interests) {
304
+ if (monitor->interests != interests) {
302
305
  // If the monitor currently has interests, we should stop it.
303
- if(monitor->interests) {
306
+ if (monitor->interests) {
304
307
  ev_io_stop(monitor->selector->ev_loop, &monitor->ev_io);
305
308
  }
306
309
 
@@ -309,7 +312,7 @@ static void NIO_Monitor_update_interests(VALUE self, int interests)
309
312
  ev_io_set(&monitor->ev_io, monitor->ev_io.fd, monitor->interests);
310
313
 
311
314
  // If we are interested in events, schedule the monitor back into the event loop:
312
- if(monitor->interests) {
315
+ if (monitor->interests) {
313
316
  ev_io_start(monitor->selector->ev_loop, &monitor->ev_io);
314
317
  }
315
318
  }