nio4r 0.4.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,6 +48,16 @@
48
48
  /* for the crt to do something about it */
49
49
  volatile double SIGFPE_REQ = 0.0f;
50
50
 
51
+ static SOCKET
52
+ ev_tcp_socket (void)
53
+ {
54
+ #if EV_USE_WSASOCKET
55
+ return WSASocket (AF_INET, SOCK_STREAM, 0, 0, 0, 0);
56
+ #else
57
+ return socket (AF_INET, SOCK_STREAM, 0);
58
+ #endif
59
+ }
60
+
51
61
  /* oh, the humanity! */
52
62
  static int
53
63
  ev_pipe (int filedes [2])
@@ -59,7 +69,7 @@ ev_pipe (int filedes [2])
59
69
  SOCKET listener;
60
70
  SOCKET sock [2] = { -1, -1 };
61
71
 
62
- if ((listener = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
72
+ if ((listener = ev_tcp_socket ()) == INVALID_SOCKET)
63
73
  return -1;
64
74
 
65
75
  addr.sin_family = AF_INET;
@@ -75,7 +85,7 @@ ev_pipe (int filedes [2])
75
85
  if (listen (listener, 1))
76
86
  goto fail;
77
87
 
78
- if ((sock [0] = socket (AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
88
+ if ((sock [0] = ev_tcp_socket ()) == INVALID_SOCKET)
79
89
  goto fail;
80
90
 
81
91
  if (connect (sock [0], (struct sockaddr *)&addr, addr_size))
@@ -1,198 +1,200 @@
1
1
  /* DO NOT EDIT, automatically generated by update_ev_wrap */
2
2
  #ifndef EV_WRAP_H
3
3
  #define EV_WRAP_H
4
- #define now_floor ((loop)->now_floor)
5
- #define mn_now ((loop)->mn_now)
6
- #define rtmn_diff ((loop)->rtmn_diff)
7
- #define io_blocktime ((loop)->io_blocktime)
8
- #define timeout_blocktime ((loop)->timeout_blocktime)
9
- #define backend ((loop)->backend)
4
+ #define acquire_cb ((loop)->acquire_cb)
10
5
  #define activecnt ((loop)->activecnt)
11
- #define loop_done ((loop)->loop_done)
6
+ #define anfdmax ((loop)->anfdmax)
7
+ #define anfds ((loop)->anfds)
8
+ #define async_pending ((loop)->async_pending)
9
+ #define asynccnt ((loop)->asynccnt)
10
+ #define asyncmax ((loop)->asyncmax)
11
+ #define asyncs ((loop)->asyncs)
12
+ #define backend ((loop)->backend)
12
13
  #define backend_fd ((loop)->backend_fd)
13
14
  #define backend_mintime ((loop)->backend_mintime)
14
15
  #define backend_modify ((loop)->backend_modify)
15
16
  #define backend_poll ((loop)->backend_poll)
16
- #define anfds ((loop)->anfds)
17
- #define anfdmax ((loop)->anfdmax)
18
- #define pendings ((loop)->pendings)
19
- #define pendingmax ((loop)->pendingmax)
20
- #define pendingcnt ((loop)->pendingcnt)
21
- #define pending_w ((loop)->pending_w)
22
- #define rfeeds ((loop)->rfeeds)
23
- #define rfeedmax ((loop)->rfeedmax)
24
- #define rfeedcnt ((loop)->rfeedcnt)
25
- #define evfd ((loop)->evfd)
26
- #define evpipe ((loop)->evpipe)
27
- #define pipe_w ((loop)->pipe_w)
28
- #define pipe_write_wanted ((loop)->pipe_write_wanted)
29
- #define pipe_write_skipped ((loop)->pipe_write_skipped)
17
+ #define checkcnt ((loop)->checkcnt)
18
+ #define checkmax ((loop)->checkmax)
19
+ #define checks ((loop)->checks)
20
+ #define cleanupcnt ((loop)->cleanupcnt)
21
+ #define cleanupmax ((loop)->cleanupmax)
22
+ #define cleanups ((loop)->cleanups)
30
23
  #define curpid ((loop)->curpid)
31
- #define postfork ((loop)->postfork)
32
- #define vec_ri ((loop)->vec_ri)
33
- #define vec_ro ((loop)->vec_ro)
34
- #define vec_wi ((loop)->vec_wi)
35
- #define vec_wo ((loop)->vec_wo)
36
- #define vec_eo ((loop)->vec_eo)
37
- #define vec_max ((loop)->vec_max)
38
- #define polls ((loop)->polls)
39
- #define pollmax ((loop)->pollmax)
40
- #define pollcnt ((loop)->pollcnt)
41
- #define pollidxs ((loop)->pollidxs)
42
- #define pollidxmax ((loop)->pollidxmax)
43
- #define epoll_events ((loop)->epoll_events)
44
- #define epoll_eventmax ((loop)->epoll_eventmax)
45
- #define epoll_eperms ((loop)->epoll_eperms)
46
24
  #define epoll_epermcnt ((loop)->epoll_epermcnt)
47
25
  #define epoll_epermmax ((loop)->epoll_epermmax)
48
- #define kqueue_changes ((loop)->kqueue_changes)
49
- #define kqueue_changemax ((loop)->kqueue_changemax)
50
- #define kqueue_changecnt ((loop)->kqueue_changecnt)
51
- #define kqueue_events ((loop)->kqueue_events)
52
- #define kqueue_eventmax ((loop)->kqueue_eventmax)
53
- #define port_events ((loop)->port_events)
54
- #define port_eventmax ((loop)->port_eventmax)
55
- #define iocp ((loop)->iocp)
56
- #define fdchanges ((loop)->fdchanges)
57
- #define fdchangemax ((loop)->fdchangemax)
26
+ #define epoll_eperms ((loop)->epoll_eperms)
27
+ #define epoll_eventmax ((loop)->epoll_eventmax)
28
+ #define epoll_events ((loop)->epoll_events)
29
+ #define evpipe ((loop)->evpipe)
58
30
  #define fdchangecnt ((loop)->fdchangecnt)
59
- #define timers ((loop)->timers)
60
- #define timermax ((loop)->timermax)
61
- #define timercnt ((loop)->timercnt)
62
- #define periodics ((loop)->periodics)
63
- #define periodicmax ((loop)->periodicmax)
64
- #define periodiccnt ((loop)->periodiccnt)
65
- #define idles ((loop)->idles)
66
- #define idlemax ((loop)->idlemax)
67
- #define idlecnt ((loop)->idlecnt)
68
- #define idleall ((loop)->idleall)
69
- #define prepares ((loop)->prepares)
70
- #define preparemax ((loop)->preparemax)
71
- #define preparecnt ((loop)->preparecnt)
72
- #define checks ((loop)->checks)
73
- #define checkmax ((loop)->checkmax)
74
- #define checkcnt ((loop)->checkcnt)
75
- #define forks ((loop)->forks)
76
- #define forkmax ((loop)->forkmax)
31
+ #define fdchangemax ((loop)->fdchangemax)
32
+ #define fdchanges ((loop)->fdchanges)
77
33
  #define forkcnt ((loop)->forkcnt)
78
- #define cleanups ((loop)->cleanups)
79
- #define cleanupmax ((loop)->cleanupmax)
80
- #define cleanupcnt ((loop)->cleanupcnt)
81
- #define async_pending ((loop)->async_pending)
82
- #define asyncs ((loop)->asyncs)
83
- #define asyncmax ((loop)->asyncmax)
84
- #define asynccnt ((loop)->asynccnt)
85
- #define fs_fd ((loop)->fs_fd)
86
- #define fs_w ((loop)->fs_w)
34
+ #define forkmax ((loop)->forkmax)
35
+ #define forks ((loop)->forks)
87
36
  #define fs_2625 ((loop)->fs_2625)
37
+ #define fs_fd ((loop)->fs_fd)
88
38
  #define fs_hash ((loop)->fs_hash)
39
+ #define fs_w ((loop)->fs_w)
40
+ #define idleall ((loop)->idleall)
41
+ #define idlecnt ((loop)->idlecnt)
42
+ #define idlemax ((loop)->idlemax)
43
+ #define idles ((loop)->idles)
44
+ #define invoke_cb ((loop)->invoke_cb)
45
+ #define io_blocktime ((loop)->io_blocktime)
46
+ #define iocp ((loop)->iocp)
47
+ #define kqueue_changecnt ((loop)->kqueue_changecnt)
48
+ #define kqueue_changemax ((loop)->kqueue_changemax)
49
+ #define kqueue_changes ((loop)->kqueue_changes)
50
+ #define kqueue_eventmax ((loop)->kqueue_eventmax)
51
+ #define kqueue_events ((loop)->kqueue_events)
52
+ #define kqueue_fd_pid ((loop)->kqueue_fd_pid)
53
+ #define loop_count ((loop)->loop_count)
54
+ #define loop_depth ((loop)->loop_depth)
55
+ #define loop_done ((loop)->loop_done)
56
+ #define mn_now ((loop)->mn_now)
57
+ #define now_floor ((loop)->now_floor)
58
+ #define origflags ((loop)->origflags)
59
+ #define pending_w ((loop)->pending_w)
60
+ #define pendingcnt ((loop)->pendingcnt)
61
+ #define pendingmax ((loop)->pendingmax)
62
+ #define pendingpri ((loop)->pendingpri)
63
+ #define pendings ((loop)->pendings)
64
+ #define periodiccnt ((loop)->periodiccnt)
65
+ #define periodicmax ((loop)->periodicmax)
66
+ #define periodics ((loop)->periodics)
67
+ #define pipe_w ((loop)->pipe_w)
68
+ #define pipe_write_skipped ((loop)->pipe_write_skipped)
69
+ #define pipe_write_wanted ((loop)->pipe_write_wanted)
70
+ #define pollcnt ((loop)->pollcnt)
71
+ #define pollidxmax ((loop)->pollidxmax)
72
+ #define pollidxs ((loop)->pollidxs)
73
+ #define pollmax ((loop)->pollmax)
74
+ #define polls ((loop)->polls)
75
+ #define port_eventmax ((loop)->port_eventmax)
76
+ #define port_events ((loop)->port_events)
77
+ #define postfork ((loop)->postfork)
78
+ #define preparecnt ((loop)->preparecnt)
79
+ #define preparemax ((loop)->preparemax)
80
+ #define prepares ((loop)->prepares)
81
+ #define release_cb ((loop)->release_cb)
82
+ #define rfeedcnt ((loop)->rfeedcnt)
83
+ #define rfeedmax ((loop)->rfeedmax)
84
+ #define rfeeds ((loop)->rfeeds)
85
+ #define rtmn_diff ((loop)->rtmn_diff)
89
86
  #define sig_pending ((loop)->sig_pending)
90
87
  #define sigfd ((loop)->sigfd)
91
- #define sigfd_w ((loop)->sigfd_w)
92
88
  #define sigfd_set ((loop)->sigfd_set)
93
- #define origflags ((loop)->origflags)
94
- #define loop_count ((loop)->loop_count)
95
- #define loop_depth ((loop)->loop_depth)
89
+ #define sigfd_w ((loop)->sigfd_w)
90
+ #define timeout_blocktime ((loop)->timeout_blocktime)
91
+ #define timercnt ((loop)->timercnt)
92
+ #define timermax ((loop)->timermax)
93
+ #define timers ((loop)->timers)
96
94
  #define userdata ((loop)->userdata)
97
- #define release_cb ((loop)->release_cb)
98
- #define acquire_cb ((loop)->acquire_cb)
99
- #define invoke_cb ((loop)->invoke_cb)
95
+ #define vec_eo ((loop)->vec_eo)
96
+ #define vec_max ((loop)->vec_max)
97
+ #define vec_ri ((loop)->vec_ri)
98
+ #define vec_ro ((loop)->vec_ro)
99
+ #define vec_wi ((loop)->vec_wi)
100
+ #define vec_wo ((loop)->vec_wo)
100
101
  #else
101
102
  #undef EV_WRAP_H
102
- #undef now_floor
103
- #undef mn_now
104
- #undef rtmn_diff
105
- #undef io_blocktime
106
- #undef timeout_blocktime
107
- #undef backend
103
+ #undef acquire_cb
108
104
  #undef activecnt
109
- #undef loop_done
105
+ #undef anfdmax
106
+ #undef anfds
107
+ #undef async_pending
108
+ #undef asynccnt
109
+ #undef asyncmax
110
+ #undef asyncs
111
+ #undef backend
110
112
  #undef backend_fd
111
113
  #undef backend_mintime
112
114
  #undef backend_modify
113
115
  #undef backend_poll
114
- #undef anfds
115
- #undef anfdmax
116
- #undef pendings
117
- #undef pendingmax
118
- #undef pendingcnt
119
- #undef pending_w
120
- #undef rfeeds
121
- #undef rfeedmax
122
- #undef rfeedcnt
123
- #undef evfd
124
- #undef evpipe
125
- #undef pipe_w
126
- #undef pipe_write_wanted
127
- #undef pipe_write_skipped
116
+ #undef checkcnt
117
+ #undef checkmax
118
+ #undef checks
119
+ #undef cleanupcnt
120
+ #undef cleanupmax
121
+ #undef cleanups
128
122
  #undef curpid
129
- #undef postfork
130
- #undef vec_ri
131
- #undef vec_ro
132
- #undef vec_wi
133
- #undef vec_wo
134
- #undef vec_eo
135
- #undef vec_max
136
- #undef polls
137
- #undef pollmax
138
- #undef pollcnt
139
- #undef pollidxs
140
- #undef pollidxmax
141
- #undef epoll_events
142
- #undef epoll_eventmax
143
- #undef epoll_eperms
144
123
  #undef epoll_epermcnt
145
124
  #undef epoll_epermmax
146
- #undef kqueue_changes
147
- #undef kqueue_changemax
148
- #undef kqueue_changecnt
149
- #undef kqueue_events
150
- #undef kqueue_eventmax
151
- #undef port_events
152
- #undef port_eventmax
153
- #undef iocp
154
- #undef fdchanges
155
- #undef fdchangemax
125
+ #undef epoll_eperms
126
+ #undef epoll_eventmax
127
+ #undef epoll_events
128
+ #undef evpipe
156
129
  #undef fdchangecnt
157
- #undef timers
158
- #undef timermax
159
- #undef timercnt
160
- #undef periodics
161
- #undef periodicmax
162
- #undef periodiccnt
163
- #undef idles
164
- #undef idlemax
165
- #undef idlecnt
166
- #undef idleall
167
- #undef prepares
168
- #undef preparemax
169
- #undef preparecnt
170
- #undef checks
171
- #undef checkmax
172
- #undef checkcnt
173
- #undef forks
174
- #undef forkmax
130
+ #undef fdchangemax
131
+ #undef fdchanges
175
132
  #undef forkcnt
176
- #undef cleanups
177
- #undef cleanupmax
178
- #undef cleanupcnt
179
- #undef async_pending
180
- #undef asyncs
181
- #undef asyncmax
182
- #undef asynccnt
183
- #undef fs_fd
184
- #undef fs_w
133
+ #undef forkmax
134
+ #undef forks
185
135
  #undef fs_2625
136
+ #undef fs_fd
186
137
  #undef fs_hash
138
+ #undef fs_w
139
+ #undef idleall
140
+ #undef idlecnt
141
+ #undef idlemax
142
+ #undef idles
143
+ #undef invoke_cb
144
+ #undef io_blocktime
145
+ #undef iocp
146
+ #undef kqueue_changecnt
147
+ #undef kqueue_changemax
148
+ #undef kqueue_changes
149
+ #undef kqueue_eventmax
150
+ #undef kqueue_events
151
+ #undef kqueue_fd_pid
152
+ #undef loop_count
153
+ #undef loop_depth
154
+ #undef loop_done
155
+ #undef mn_now
156
+ #undef now_floor
157
+ #undef origflags
158
+ #undef pending_w
159
+ #undef pendingcnt
160
+ #undef pendingmax
161
+ #undef pendingpri
162
+ #undef pendings
163
+ #undef periodiccnt
164
+ #undef periodicmax
165
+ #undef periodics
166
+ #undef pipe_w
167
+ #undef pipe_write_skipped
168
+ #undef pipe_write_wanted
169
+ #undef pollcnt
170
+ #undef pollidxmax
171
+ #undef pollidxs
172
+ #undef pollmax
173
+ #undef polls
174
+ #undef port_eventmax
175
+ #undef port_events
176
+ #undef postfork
177
+ #undef preparecnt
178
+ #undef preparemax
179
+ #undef prepares
180
+ #undef release_cb
181
+ #undef rfeedcnt
182
+ #undef rfeedmax
183
+ #undef rfeeds
184
+ #undef rtmn_diff
187
185
  #undef sig_pending
188
186
  #undef sigfd
189
- #undef sigfd_w
190
187
  #undef sigfd_set
191
- #undef origflags
192
- #undef loop_count
193
- #undef loop_depth
188
+ #undef sigfd_w
189
+ #undef timeout_blocktime
190
+ #undef timercnt
191
+ #undef timermax
192
+ #undef timers
194
193
  #undef userdata
195
- #undef release_cb
196
- #undef acquire_cb
197
- #undef invoke_cb
194
+ #undef vec_eo
195
+ #undef vec_max
196
+ #undef vec_ri
197
+ #undef vec_ro
198
+ #undef vec_wi
199
+ #undef vec_wo
198
200
  #endif
@@ -2,7 +2,8 @@
2
2
 
3
3
  #ifdef _WIN32
4
4
  #define EV_SELECT_IS_WINSOCKET 1
5
- #define FD_SETSIZE 512
5
+ #define EV_USE_MONOTONIC 0
6
+ #define EV_USE_REALTIME 0
6
7
  #endif
7
8
 
8
9
  #include "../libev/ev.h"
@@ -130,7 +130,7 @@ public class Nio4r implements Library {
130
130
  Ruby runtime = context.getRuntime();
131
131
  return this.selector.isOpen() ? runtime.getFalse() : runtime.getTrue();
132
132
  }
133
-
133
+
134
134
  @JRubyMethod(name = "empty?")
135
135
  public IRubyObject isEmpty(ThreadContext context) {
136
136
  Ruby runtime = context.getRuntime();
@@ -142,6 +142,10 @@ public class Nio4r implements Library {
142
142
  Ruby runtime = context.getRuntime();
143
143
  Channel rawChannel = RubyIO.convertToIO(context, io).getChannel();
144
144
 
145
+ if(!this.selector.isOpen()) {
146
+ throw context.getRuntime().newIOError("selector is closed");
147
+ }
148
+
145
149
  if(!(rawChannel instanceof SelectableChannel)) {
146
150
  throw runtime.newArgumentError("not a selectable IO object");
147
151
  }
@@ -199,11 +199,17 @@ static VALUE NIO_Selector_register_synchronized(VALUE *args)
199
199
  {
200
200
  VALUE self, io, interests, selectables, monitor;
201
201
  VALUE monitor_args[3];
202
+ struct NIO_Selector *selector;
202
203
 
203
204
  self = args[0];
204
205
  io = args[1];
205
206
  interests = args[2];
206
207
 
208
+ Data_Get_Struct(self, struct NIO_Selector, selector);
209
+ if(selector->closed) {
210
+ rb_raise(rb_eIOError, "selector is closed");
211
+ }
212
+
207
213
  selectables = rb_ivar_get(self, rb_intern("selectables"));
208
214
  monitor = rb_hash_lookup(selectables, io);
209
215
 
@@ -18,6 +18,10 @@ module NIO
18
18
  # * :rw - is the IO either readable or writeable?
19
19
  def register(io, interest)
20
20
  @lock.synchronize do
21
+ if closed?
22
+ raise IOError, "selector is closed"
23
+ end
24
+
21
25
  if monitor = @selectables[io]
22
26
  raise ArgumentError, "this IO is already registered with the selector as #{monitor.interests.inspect}"
23
27
  end
@@ -56,7 +60,7 @@ module NIO
56
60
 
57
61
  ready_readers, ready_writers = Kernel.select readers, writers, [], timeout
58
62
  return unless ready_readers # timeout or wakeup
59
-
63
+
60
64
  selected_monitors = Set.new
61
65
 
62
66
  ready_readers.each do |io|
@@ -71,7 +75,7 @@ module NIO
71
75
  selected_monitors << monitor
72
76
  end
73
77
  end
74
-
78
+
75
79
  ready_writers.each do |io|
76
80
  monitor = @selectables[io]
77
81
  monitor.readiness = case monitor.readiness
@@ -82,7 +86,7 @@ module NIO
82
86
  end
83
87
  selected_monitors << monitor
84
88
  end
85
-
89
+
86
90
  if block_given?
87
91
  selected_monitors.each do |m|
88
92
  yield m
@@ -119,7 +123,7 @@ module NIO
119
123
 
120
124
  # Is this selector closed?
121
125
  def closed?; @closed end
122
-
126
+
123
127
  def empty?
124
128
  @selectables.empty?
125
129
  end