sleepy_penguin 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v1.3.0.GIT
4
+ DEF_VER=v1.3.1.GIT
5
5
 
6
6
  LF='
7
7
  '
@@ -289,11 +289,15 @@ fallback_add:
289
289
  static VALUE delete(VALUE self, VALUE io)
290
290
  {
291
291
  struct rb_epoll *ep = ep_get(self);
292
- int fd = my_fileno(io);
292
+ int fd;
293
293
  int rv;
294
294
  VALUE cur_io;
295
295
 
296
296
  ep_check(ep);
297
+ if (my_io_closed(io))
298
+ goto out;
299
+
300
+ fd = my_fileno(io);
297
301
  cur_io = rb_ary_entry(ep->marks, fd);
298
302
  if (NIL_P(cur_io) || my_io_closed(cur_io))
299
303
  return Qnil;
@@ -308,6 +312,7 @@ static VALUE delete(VALUE self, VALUE io)
308
312
  rb_sys_fail("epoll_ctl - del");
309
313
  }
310
314
  }
315
+ out:
311
316
  rb_ary_store(ep->marks, fd, Qnil);
312
317
  rb_ary_store(ep->flag_cache, fd, Qnil);
313
318
 
@@ -26,18 +26,37 @@
26
26
  # endif
27
27
  #endif
28
28
 
29
+ static int fixint_closed_p(VALUE io)
30
+ {
31
+ return (fcntl(FIX2INT(io), F_GETFD) == -1 && errno == EBADF);
32
+ }
33
+
29
34
  #if defined(RFILE) && defined(HAVE_ST_FD)
30
- static int my_io_closed(VALUE io)
35
+ static int my_rb_io_closed(VALUE io)
31
36
  {
32
37
  return RFILE(io)->fptr->fd < 0;
33
38
  }
34
39
  #else
35
- static int my_io_closed(VALUE io)
40
+ static int my_rb_io_closed(VALUE io)
36
41
  {
37
42
  return rb_funcall(io, rb_intern("closed?"), 0) == Qtrue;
38
43
  }
39
44
  #endif
40
45
 
46
+ static int my_io_closed(VALUE io)
47
+ {
48
+ switch (TYPE(io)) {
49
+ case T_FIXNUM:
50
+ return fixint_closed_p(io);
51
+ case T_FILE:
52
+ break;
53
+ default:
54
+ io = rb_convert_type(io, T_FILE, "IO", "to_io");
55
+ }
56
+
57
+ return my_rb_io_closed(io);
58
+ }
59
+
41
60
  static int my_fileno(VALUE io)
42
61
  {
43
62
  rb_io_t *fptr;
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
2
  module SleepyPenguin
3
3
 
4
- # the version of sleepy_penguin, currently 1.3.0
5
- SLEEPY_PENGUIN_VERSION = '1.3.0'
4
+ # the version of sleepy_penguin, currently 1.3.1
5
+ SLEEPY_PENGUIN_VERSION = '1.3.1'
6
6
  end
7
7
  require 'sleepy_penguin_ext'
@@ -83,6 +83,30 @@ class TestEpollOptimizations < Test::Unit::TestCase
83
83
  assert_equal 0, lines.grep(/^epoll_ctl/).size
84
84
  end
85
85
 
86
+ def test_delete_closed_proxy
87
+ obj = Struct.new(:to_io).new(@wr)
88
+ rv = nil
89
+ @ep.add(obj, Epoll::OUT)
90
+ @wr.close
91
+ io, err = Strace.me { rv = @ep.delete(obj) }
92
+ lines = io.readlines; io.close
93
+ assert_nil err
94
+ assert_equal obj, rv
95
+ assert_equal 0, lines.grep(/^epoll_ctl/).size
96
+ end
97
+
98
+ def test_delete_closed_fileno
99
+ fileno = @wr.fileno
100
+ @ep.add(fileno, Epoll::OUT)
101
+ @wr.close
102
+ rv = nil
103
+ io, err = Strace.me { rv = @ep.delete(fileno) }
104
+ lines = io.readlines; io.close
105
+ assert_nil err
106
+ assert_equal fileno, rv
107
+ assert_equal 0, lines.grep(/^epoll_ctl/).size
108
+ end
109
+
86
110
  def test_delete_aliased_a
87
111
  tmp = IO.for_fd @wr.fileno
88
112
  IO_PURGATORY << tmp
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleepy_penguin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 0
10
- version: 1.3.0
9
+ - 1
10
+ version: 1.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - sleepy_penguin hackers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-21 00:00:00 +00:00
18
+ date: 2011-01-22 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency