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.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libev poll fd activity backend
3
3
  *
4
- * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
4
+ * Copyright (c) 2007,2008,2009,2010,2011,2016,2019 Marc Alexander Lehmann <libev@schmorp.de>
5
5
  * All rights reserved.
6
6
  *
7
7
  * Redistribution and use in source and binary forms, with or without modifica-
@@ -41,10 +41,12 @@
41
41
 
42
42
  inline_size
43
43
  void
44
- pollidx_init (int *base, int count)
44
+ array_needsize_pollidx (int *base, int offset, int count)
45
45
  {
46
- /* consider using memset (.., -1, ...), which is practically guaranteed
47
- * to work on all systems implementing poll */
46
+ /* using memset (.., -1, ...) is tempting, we we try
47
+ * to be ultraportable
48
+ */
49
+ base += offset;
48
50
  while (count--)
49
51
  *base++ = -1;
50
52
  }
@@ -57,14 +59,14 @@ poll_modify (EV_P_ int fd, int oev, int nev)
57
59
  if (oev == nev)
58
60
  return;
59
61
 
60
- array_needsize (int, pollidxs, pollidxmax, fd + 1, pollidx_init);
62
+ array_needsize (int, pollidxs, pollidxmax, fd + 1, array_needsize_pollidx);
61
63
 
62
64
  idx = pollidxs [fd];
63
65
 
64
66
  if (idx < 0) /* need to allocate a new pollfd */
65
67
  {
66
68
  pollidxs [fd] = idx = pollcnt++;
67
- array_needsize (struct pollfd, polls, pollmax, pollcnt, EMPTY2);
69
+ array_needsize (struct pollfd, polls, pollmax, pollcnt, array_needsize_noinit);
68
70
  polls [idx].fd = fd;
69
71
  }
70
72
 
@@ -108,14 +110,17 @@ poll_poll (EV_P_ ev_tstamp timeout)
108
110
  else
109
111
  for (p = polls; res; ++p)
110
112
  {
111
- assert (("libev: poll() returned illegal result, broken BSD kernel?", p < polls + pollcnt));
113
+ assert (("libev: poll returned illegal result, broken BSD kernel?", p < polls + pollcnt));
112
114
 
113
115
  if (expect_false (p->revents)) /* this expect is debatable */
114
116
  {
115
117
  --res;
116
118
 
117
119
  if (expect_false (p->revents & POLLNVAL))
118
- fd_kill (EV_A_ p->fd);
120
+ {
121
+ assert (("libev: poll found invalid fd in poll set", 0));
122
+ fd_kill (EV_A_ p->fd);
123
+ }
119
124
  else
120
125
  fd_event (
121
126
  EV_A_
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libev solaris event port backend
3
3
  *
4
- * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
4
+ * Copyright (c) 2007,2008,2009,2010,2011,2019 Marc Alexander Lehmann <libev@schmorp.de>
5
5
  * All rights reserved.
6
6
  *
7
7
  * Redistribution and use in source and binary forms, with or without modifica-
@@ -69,7 +69,10 @@ port_associate_and_check (EV_P_ int fd, int ev)
69
69
  )
70
70
  {
71
71
  if (errno == EBADFD)
72
- fd_kill (EV_A_ fd);
72
+ {
73
+ assert (("libev: port_associate found invalid fd", errno != EBADFD));
74
+ fd_kill (EV_A_ fd);
75
+ }
73
76
  else
74
77
  ev_syserr ("(libev) port_associate");
75
78
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * loop member variable declarations
3
3
  *
4
- * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libev@schmorp.de>
4
+ * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2019 Marc Alexander Lehmann <libev@schmorp.de>
5
5
  * All rights reserved.
6
6
  *
7
7
  * Redistribution and use in source and binary forms, with or without modifica-
@@ -107,6 +107,17 @@ VARx(int, epoll_epermcnt)
107
107
  VARx(int, epoll_epermmax)
108
108
  #endif
109
109
 
110
+ #if EV_USE_LINUXAIO || EV_GENWRAP
111
+ VARx(aio_context_t, linuxaio_ctx)
112
+ VARx(int, linuxaio_iteration)
113
+ VARx(struct aniocb **, linuxaio_iocbps)
114
+ VARx(int, linuxaio_iocbpmax)
115
+ VARx(struct iocb **, linuxaio_submits)
116
+ VARx(int, linuxaio_submitcnt)
117
+ VARx(int, linuxaio_submitmax)
118
+ VARx(ev_io, linuxaio_epoll_w)
119
+ #endif
120
+
110
121
  #if EV_USE_KQUEUE || EV_GENWRAP
111
122
  VARx(pid_t, kqueue_fd_pid)
112
123
  VARx(struct kevent *, kqueue_changes)
@@ -50,6 +50,14 @@
50
50
  #define kqueue_eventmax ((loop)->kqueue_eventmax)
51
51
  #define kqueue_events ((loop)->kqueue_events)
52
52
  #define kqueue_fd_pid ((loop)->kqueue_fd_pid)
53
+ #define linuxaio_ctx ((loop)->linuxaio_ctx)
54
+ #define linuxaio_epoll_w ((loop)->linuxaio_epoll_w)
55
+ #define linuxaio_iocbpmax ((loop)->linuxaio_iocbpmax)
56
+ #define linuxaio_iocbps ((loop)->linuxaio_iocbps)
57
+ #define linuxaio_iteration ((loop)->linuxaio_iteration)
58
+ #define linuxaio_submitcnt ((loop)->linuxaio_submitcnt)
59
+ #define linuxaio_submitmax ((loop)->linuxaio_submitmax)
60
+ #define linuxaio_submits ((loop)->linuxaio_submits)
53
61
  #define loop_count ((loop)->loop_count)
54
62
  #define loop_depth ((loop)->loop_depth)
55
63
  #define loop_done ((loop)->loop_done)
@@ -149,6 +157,14 @@
149
157
  #undef kqueue_eventmax
150
158
  #undef kqueue_events
151
159
  #undef kqueue_fd_pid
160
+ #undef linuxaio_ctx
161
+ #undef linuxaio_epoll_w
162
+ #undef linuxaio_iocbpmax
163
+ #undef linuxaio_iocbps
164
+ #undef linuxaio_iteration
165
+ #undef linuxaio_submitcnt
166
+ #undef linuxaio_submitmax
167
+ #undef linuxaio_submits
152
168
  #undef loop_count
153
169
  #undef loop_depth
154
170
  #undef loop_done
@@ -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
  }
@@ -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
@@ -13,6 +14,7 @@ require "mkmf"
13
14
 
14
15
  have_header("unistd.h")
15
16
 
17
+ $defs << "-DEV_USE_LINUXAIO" if have_header("linux/aio_abi.h")
16
18
  $defs << "-DEV_USE_SELECT" if have_header("sys/select.h")
17
19
  $defs << "-DEV_USE_POLL" if have_type("port_event_t", "poll.h")
18
20
  $defs << "-DEV_USE_EPOLL" if have_header("sys/epoll.h")
@@ -20,6 +22,8 @@ $defs << "-DEV_USE_KQUEUE" if have_header("sys/event.h") && have_header("s
20
22
  $defs << "-DEV_USE_PORT" if have_type("port_event_t", "port.h")
21
23
  $defs << "-DHAVE_SYS_RESOURCE_H" if have_header("sys/resource.h")
22
24
 
25
+ $defs << "-DEV_STANDALONE" # prevent libev from assuming "config.h" exists
26
+
23
27
  CONFIG["optflags"] << " -fno-strict-aliasing" unless RUBY_PLATFORM =~ /mswin/
24
28
 
25
29
  dir_config "nio4r_ext"
@@ -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"
@@ -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
  }