nio4r 0.2.0 → 2.7.5

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.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/libev/Changes +232 -3
  4. data/ext/libev/LICENSE +2 -1
  5. data/ext/libev/README +11 -10
  6. data/ext/libev/ev.c +2249 -473
  7. data/ext/libev/ev.h +165 -135
  8. data/ext/libev/ev_epoll.c +68 -36
  9. data/ext/libev/ev_iouring.c +694 -0
  10. data/ext/libev/ev_kqueue.c +44 -18
  11. data/ext/libev/ev_linuxaio.c +620 -0
  12. data/ext/libev/ev_poll.c +28 -20
  13. data/ext/libev/ev_port.c +23 -10
  14. data/ext/libev/ev_select.c +18 -12
  15. data/ext/libev/ev_vars.h +65 -19
  16. data/ext/libev/ev_win32.c +16 -7
  17. data/ext/libev/ev_wrap.h +236 -160
  18. data/ext/nio4r/.clang-format +16 -0
  19. data/ext/nio4r/bytebuffer.c +465 -0
  20. data/ext/nio4r/extconf.rb +44 -35
  21. data/ext/nio4r/libev.h +3 -4
  22. data/ext/nio4r/monitor.c +186 -54
  23. data/ext/nio4r/nio4r.h +17 -23
  24. data/ext/nio4r/nio4r_ext.c +11 -3
  25. data/ext/nio4r/org/nio4r/ByteBuffer.java +295 -0
  26. data/ext/nio4r/org/nio4r/Monitor.java +176 -0
  27. data/ext/nio4r/org/nio4r/Nio4r.java +104 -0
  28. data/ext/nio4r/org/nio4r/Selector.java +297 -0
  29. data/ext/nio4r/selector.c +350 -182
  30. data/lib/nio/bytebuffer.rb +235 -0
  31. data/lib/nio/monitor.rb +100 -8
  32. data/lib/nio/selector.rb +110 -44
  33. data/lib/nio/version.rb +8 -1
  34. data/lib/nio.rb +47 -16
  35. data/lib/nio4r.rb +7 -0
  36. data/license.md +80 -0
  37. data/readme.md +91 -0
  38. data/releases.md +343 -0
  39. data.tar.gz.sig +2 -0
  40. metadata +114 -79
  41. metadata.gz.sig +0 -0
  42. data/.gitignore +0 -20
  43. data/.rspec +0 -4
  44. data/.travis.yml +0 -7
  45. data/CHANGES.md +0 -10
  46. data/Gemfile +0 -4
  47. data/LICENSE.txt +0 -20
  48. data/README.md +0 -171
  49. data/Rakefile +0 -9
  50. data/examples/echo_server.rb +0 -38
  51. data/ext/libev/README.embed +0 -3
  52. data/ext/libev/test_libev_win32.c +0 -123
  53. data/lib/nio/jruby/monitor.rb +0 -42
  54. data/lib/nio/jruby/selector.rb +0 -135
  55. data/nio4r.gemspec +0 -22
  56. data/spec/nio/monitor_spec.rb +0 -46
  57. data/spec/nio/selector_spec.rb +0 -269
  58. data/spec/spec_helper.rb +0 -3
  59. data/tasks/extension.rake +0 -10
  60. data/tasks/rspec.rake +0 -7
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libev kqueue backend
3
3
  *
4
- * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de>
4
+ * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,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-
@@ -43,11 +43,12 @@
43
43
  #include <string.h>
44
44
  #include <errno.h>
45
45
 
46
- void inline_speed
46
+ inline_speed
47
+ void
47
48
  kqueue_change (EV_P_ int fd, int filter, int flags, int fflags)
48
49
  {
49
50
  ++kqueue_changecnt;
50
- array_needsize (struct kevent, kqueue_changes, kqueue_changemax, kqueue_changecnt, EMPTY2);
51
+ array_needsize (struct kevent, kqueue_changes, kqueue_changemax, kqueue_changecnt, array_needsize_noinit);
51
52
 
52
53
  EV_SET (&kqueue_changes [kqueue_changecnt - 1], fd, filter, flags, fflags, 0, 0);
53
54
  }
@@ -102,10 +103,10 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
102
103
  EV_ACQUIRE_CB;
103
104
  kqueue_changecnt = 0;
104
105
 
105
- if (expect_false (res < 0))
106
+ if (ecb_expect_false (res < 0))
106
107
  {
107
108
  if (errno != EINTR)
108
- ev_syserr ("(libev) kevent");
109
+ ev_syserr ("(libev) kqueue kevent");
109
110
 
110
111
  return;
111
112
  }
@@ -114,7 +115,7 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
114
115
  {
115
116
  int fd = kqueue_events [i].ident;
116
117
 
117
- if (expect_false (kqueue_events [i].flags & EV_ERROR))
118
+ if (ecb_expect_false (kqueue_events [i].flags & EV_ERROR))
118
119
  {
119
120
  int err = kqueue_events [i].data;
120
121
 
@@ -128,10 +129,16 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
128
129
  if (fd_valid (fd))
129
130
  kqueue_modify (EV_A_ fd, 0, anfds [fd].events);
130
131
  else
131
- fd_kill (EV_A_ fd);
132
+ {
133
+ assert (("libev: kqueue found invalid fd", 0));
134
+ fd_kill (EV_A_ fd);
135
+ }
132
136
  }
133
137
  else /* on all other errors, we error out on the fd */
134
- fd_kill (EV_A_ fd);
138
+ {
139
+ assert (("libev: kqueue found invalid fd", 0));
140
+ fd_kill (EV_A_ fd);
141
+ }
135
142
  }
136
143
  }
137
144
  else
@@ -144,7 +151,7 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
144
151
  );
145
152
  }
146
153
 
147
- if (expect_false (res == kqueue_eventmax))
154
+ if (ecb_expect_false (res == kqueue_eventmax))
148
155
  {
149
156
  ev_free (kqueue_events);
150
157
  kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_eventmax + 1);
@@ -152,18 +159,20 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
152
159
  }
153
160
  }
154
161
 
155
- int inline_size
162
+ inline_size
163
+ int
156
164
  kqueue_init (EV_P_ int flags)
157
165
  {
158
- /* Initialize the kernel queue */
166
+ /* initialize the kernel queue */
167
+ kqueue_fd_pid = getpid ();
159
168
  if ((backend_fd = kqueue ()) < 0)
160
169
  return 0;
161
170
 
162
171
  fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */
163
172
 
164
- backend_fudge = 0.;
165
- backend_modify = kqueue_modify;
166
- backend_poll = kqueue_poll;
173
+ backend_mintime = EV_TS_CONST (1e-9); /* apparently, they did the right thing in freebsd */
174
+ backend_modify = kqueue_modify;
175
+ backend_poll = kqueue_poll;
167
176
 
168
177
  kqueue_eventmax = 64; /* initial number of events receivable per poll */
169
178
  kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
@@ -175,18 +184,32 @@ kqueue_init (EV_P_ int flags)
175
184
  return EVBACKEND_KQUEUE;
176
185
  }
177
186
 
178
- void inline_size
187
+ inline_size
188
+ void
179
189
  kqueue_destroy (EV_P)
180
190
  {
181
191
  ev_free (kqueue_events);
182
192
  ev_free (kqueue_changes);
183
193
  }
184
194
 
185
- void inline_size
195
+ inline_size
196
+ void
186
197
  kqueue_fork (EV_P)
187
198
  {
188
- close (backend_fd);
189
-
199
+ /* some BSD kernels don't just destroy the kqueue itself,
200
+ * but also close the fd, which isn't documented, and
201
+ * impossible to support properly.
202
+ * we remember the pid of the kqueue call and only close
203
+ * the fd if the pid is still the same.
204
+ * this leaks fds on sane kernels, but BSD interfaces are
205
+ * notoriously buggy and rarely get fixed.
206
+ */
207
+ pid_t newpid = getpid ();
208
+
209
+ if (newpid == kqueue_fd_pid)
210
+ close (backend_fd);
211
+
212
+ kqueue_fd_pid = newpid;
190
213
  while ((backend_fd = kqueue ()) < 0)
191
214
  ev_syserr ("(libev) kqueue");
192
215
 
@@ -196,3 +219,6 @@ kqueue_fork (EV_P)
196
219
  fd_rearm_all (EV_A);
197
220
  }
198
221
 
222
+ /* sys/event.h defines EV_ERROR */
223
+ #undef EV_ERROR
224
+