Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Raise IOError if asked to wakeup a closed selector

  • Loading branch information...
commit 9dc3c7be4f7936660eb2d881828d232fc015f9c5 1 parent 1256a56
Tony Arcieri tarcieri authored
4 CHANGES.md
Source Rendered
... ... @@ -1,3 +1,7 @@
  1 +0.2.2
  2 +-----
  3 +* Raise IOError if asked to wake up a closed selector
  4 +
1 5 0.2.1
2 6 -----
3 7 * Implement wakeup mechanism using raw pipes instead of ev_async, since
4 ext/nio4r/selector.c
@@ -406,6 +406,10 @@ static VALUE NIO_Selector_wakeup(VALUE self)
406 406 struct NIO_Selector *selector;
407 407 Data_Get_Struct(self, struct NIO_Selector, selector);
408 408
  409 + if(selector->closed) {
  410 + rb_raise(rb_eIOError, "selector is closed");
  411 + }
  412 +
409 413 write(selector->wakeup_writer, "\0", 1);
410 414
411 415 return Qnil;
1  lib/nio/jruby/selector.rb
@@ -118,6 +118,7 @@ def select_each(timeout = nil)
118 118
119 119 # Wake up the other thread that's currently blocking on this selector
120 120 def wakeup
  121 + raise IOError, "selector is closed" if closed?
121 122 @java_selector.wakeup
122 123 nil
123 124 end
43 spec/nio/selector_spec.rb
@@ -30,25 +30,25 @@
30 30 monitor.should be_closed
31 31 end
32 32
33   - context "select" do
34   - it "waits for a timeout when selecting" do
35   - reader, writer = IO.pipe
36   - monitor = subject.register(reader, :r)
37   -
38   - payload = "hi there"
39   - writer << payload
40   -
41   - timeout = 0.5
42   - started_at = Time.now
43   - subject.select(timeout).should include monitor
44   - (Time.now - started_at).should be_within(TIMEOUT_PRECISION).of(0)
45   - reader.read_nonblock(payload.size)
46   -
47   - started_at = Time.now
48   - subject.select(timeout).should be_nil
49   - (Time.now - started_at).should be_within(TIMEOUT_PRECISION).of(timeout)
50   - end
  33 + it "waits for a timeout when selecting" do
  34 + reader, writer = IO.pipe
  35 + monitor = subject.register(reader, :r)
  36 +
  37 + payload = "hi there"
  38 + writer << payload
51 39
  40 + timeout = 0.5
  41 + started_at = Time.now
  42 + subject.select(timeout).should include monitor
  43 + (Time.now - started_at).should be_within(TIMEOUT_PRECISION).of(0)
  44 + reader.read_nonblock(payload.size)
  45 +
  46 + started_at = Time.now
  47 + subject.select(timeout).should be_nil
  48 + (Time.now - started_at).should be_within(TIMEOUT_PRECISION).of(timeout)
  49 + end
  50 +
  51 + context "wakeup" do
52 52 it "wakes up if signaled to from another thread" do
53 53 pipe, _ = IO.pipe
54 54 subject.register(pipe, :r)
@@ -65,6 +65,13 @@
65 65
66 66 thread.value.should be_within(TIMEOUT_PRECISION).of(timeout)
67 67 end
  68 +
  69 + it "raises IOError if asked to wake up a closed selector" do
  70 + subject.close
  71 + subject.should be_closed
  72 +
  73 + expect { subject.wakeup }.to raise_exception IOError
  74 + end
68 75 end
69 76
70 77 context "select_each" do

0 comments on commit 9dc3c7b

Please sign in to comment.
Something went wrong with that request. Please try again.