Browse files

Raise IOError if asked to wakeup a closed selector

  • Loading branch information...
1 parent 1256a56 commit 9dc3c7be4f7936660eb2d881828d232fc015f9c5 @tarcieri tarcieri committed Jan 8, 2012
Showing with 34 additions and 18 deletions.
  1. +4 −0 CHANGES.md
  2. +4 −0 ext/nio4r/selector.c
  3. +1 −0 lib/nio/jruby/selector.rb
  4. +25 −18 spec/nio/selector_spec.rb
View
4 CHANGES.md
@@ -1,3 +1,7 @@
+0.2.2
+-----
+* Raise IOError if asked to wake up a closed selector
+
0.2.1
-----
* Implement wakeup mechanism using raw pipes instead of ev_async, since
View
4 ext/nio4r/selector.c
@@ -406,6 +406,10 @@ static VALUE NIO_Selector_wakeup(VALUE self)
struct NIO_Selector *selector;
Data_Get_Struct(self, struct NIO_Selector, selector);
+ if(selector->closed) {
+ rb_raise(rb_eIOError, "selector is closed");
+ }
+
write(selector->wakeup_writer, "\0", 1);
return Qnil;
View
1 lib/nio/jruby/selector.rb
@@ -118,6 +118,7 @@ def select_each(timeout = nil)
# Wake up the other thread that's currently blocking on this selector
def wakeup
+ raise IOError, "selector is closed" if closed?
@java_selector.wakeup
nil
end
View
43 spec/nio/selector_spec.rb
@@ -30,25 +30,25 @@
monitor.should be_closed
end
- context "select" do
- it "waits for a timeout when selecting" do
- reader, writer = IO.pipe
- monitor = subject.register(reader, :r)
-
- payload = "hi there"
- writer << payload
-
- timeout = 0.5
- started_at = Time.now
- subject.select(timeout).should include monitor
- (Time.now - started_at).should be_within(TIMEOUT_PRECISION).of(0)
- reader.read_nonblock(payload.size)
-
- started_at = Time.now
- subject.select(timeout).should be_nil
- (Time.now - started_at).should be_within(TIMEOUT_PRECISION).of(timeout)
- end
+ it "waits for a timeout when selecting" do
+ reader, writer = IO.pipe
+ monitor = subject.register(reader, :r)
+
+ payload = "hi there"
+ writer << payload
+ timeout = 0.5
+ started_at = Time.now
+ subject.select(timeout).should include monitor
+ (Time.now - started_at).should be_within(TIMEOUT_PRECISION).of(0)
+ reader.read_nonblock(payload.size)
+
+ started_at = Time.now
+ subject.select(timeout).should be_nil
+ (Time.now - started_at).should be_within(TIMEOUT_PRECISION).of(timeout)
+ end
+
+ context "wakeup" do
it "wakes up if signaled to from another thread" do
pipe, _ = IO.pipe
subject.register(pipe, :r)
@@ -65,6 +65,13 @@
thread.value.should be_within(TIMEOUT_PRECISION).of(timeout)
end
+
+ it "raises IOError if asked to wake up a closed selector" do
+ subject.close
+ subject.should be_closed
+
+ expect { subject.wakeup }.to raise_exception IOError
+ end
end
context "select_each" do

0 comments on commit 9dc3c7b

Please sign in to comment.