kgio 1.3.1 → 2.0.0pre1

Sign up to get free protection for your applications and to get access to all the features.
data/GIT-VERSION-GEN CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v1.3.1.GIT
4
+ DEF_VER=v2.0.0pre1.GIT
5
5
 
6
6
  LF='
7
7
  '
data/GNUmakefile CHANGED
@@ -139,7 +139,7 @@ release: verify package $(release_notes) $(release_changes)
139
139
  # make tgz release on RubyForge
140
140
  rubyforge add_release -f -n $(release_notes) -a $(release_changes) \
141
141
  $(rfproject) $(rfpackage) $(VERSION) $(pkgtgz)
142
- # push gem to Gemcutter
142
+ # push gem to RubyGems.org
143
143
  gem push $(pkggem)
144
144
  # in case of gem downloads from RubyForge releases page
145
145
  -rubyforge add_file \
data/HACKING CHANGED
@@ -31,7 +31,7 @@ characters wide) and NOT the indentation style of Matz Ruby.
31
31
 
32
32
  Contributions are welcome in the form of patches, pull requests, code
33
33
  review, testing, documentation, user support or any other feedback. The
34
- {Unicornmailing list}[mailto:mongrel-unicorn@rubyforge.org] is the
34
+ {kgio mailing list}[mailto:kgio@librelist.com] is the
35
35
  central coordination point for all user and developer feedback and bug
36
36
  reports.
37
37
 
data/ISSUES CHANGED
@@ -1,18 +1,16 @@
1
1
  = Issues
2
2
 
3
- The Unicorn {mailing list}[mailto:mongrel-unicorn@rubyforge.org] is the best
3
+ The kgio {mailing list}[mailto:kgio@librelist.com] is the best
4
4
  place to report bugs, submit patches and/or obtain support after you
5
5
  have searched the mailing list archives and
6
6
  {documentation}[http://unicorn.bogomips.org/kgio].
7
7
 
8
- * No subscription is needed to post to the mailing list,
9
- let us know that we need to Cc: replies to you if you're unsubscribed.
10
8
  * Do not {top post}[http://catb.org/jargon/html/T/top-post.html] in replies
11
9
  * Quote only the relevant portions of the message you're replying to
12
- * Do not send HTML mail
10
+ * Do not send any HTML mail at all
13
11
 
14
12
  If your issue is of a sensitive nature or you're just shy in public,
15
- then feel free to email us privately at mailto:unicorn@bogomips.org
13
+ then feel free to email us privately at mailto:kgio@bogomips.org
16
14
  instead and your issue will be handled discreetly.
17
15
 
18
16
  If you don't get a response within a few days, we may have forgotten
@@ -26,11 +24,11 @@ guidelines for patch submission.
26
24
 
27
25
  == Mailing List Info
28
26
 
29
- * subscribe: http://rubyforge.org/mailman/listinfo/mongrel-unicorn
30
- * post: mailto:mongrel-unicorn@rubyforge.org
31
- * private: mailto:unicorn@bogomips.org
27
+ * subscribe: send a message to the mailing list
28
+ * post: mailto:kgio@librelist.com
29
+ * private: mailto:kgio@bogomips.org
32
30
 
33
- == Mailing List Archives
31
+ == Mailing List Archives (coming soon)
34
32
 
35
- * nntp://news.gmane.org/gmane.comp.lang.ruby.unicorn.general
36
- * http://rubyforge.org/pipermail/mongrel-unicorn
33
+ * http://unicorn.bogomips.org/kgio/archives/
34
+ * nntp://news.gmane.org/gmane.comp.lang.ruby.kgio.general
data/README CHANGED
@@ -8,16 +8,16 @@ applications.
8
8
  == Features
9
9
 
10
10
  * Can avoid expensive exceptions on common EAGAIN/EINPROGRESS errors,
11
- returning Kgio::WaitReadable or Kgio::WaitWritable instead.
11
+ returning :wait_readable or :wait_writable instead.
12
12
  These exceptions got more expensive to hit under Ruby 1.9.2
13
13
  (but should be fixed in Ruby 1.9.3 to 1.9.1 performance levels)
14
14
 
15
15
  * Returns the unwritten portion of the string on partial writes,
16
16
  making it ideal for buffering unwritten data.
17
17
 
18
- * May be assigned Kgio.wait_writable= and Kgio.wait_readable=
19
- methods to allow socket/pipe objects to make custom callbacks
20
- (such as adding the file descriptor to a poll set and yielding
18
+ * May call any method defined to be "kgio_wait_writable" or
19
+ "kgio_wait_readable" methods to allow socket/pipe objects to make custom
20
+ callbacks (such as adding the file descriptor to a poll set and yielding
21
21
  the current Fiber).
22
22
 
23
23
  * Uses
@@ -38,7 +38,7 @@ and run setup.rb after unpacking it:
38
38
 
39
39
  http://rubyforge.org/frs/?group_id=8977
40
40
 
41
- You may also install it via RubyGems on Gemcutter:
41
+ You may also install it via RubyGems.org:
42
42
 
43
43
  gem install kgio
44
44
 
@@ -61,8 +61,7 @@ from git.
61
61
 
62
62
  All feedback (bug reports, user/development dicussion, patches, pull
63
63
  requests) go to the mailing list/newsgroup. See the ISSUES document for
64
- information on the
65
- {Unicorn mailing list}[mailto:mongrel-unicorn@rubyforge.org].
64
+ information on the {kgio mailing list}[mailto:kgio@librelist.com]
66
65
 
67
66
  For the latest on kgio releases, you may check our NEWS page (and
68
67
  subscribe to our Atom feed).
data/ext/kgio/connect.c CHANGED
@@ -46,7 +46,7 @@ my_connect(VALUE klass, int io_wait, int domain, void *addr, socklen_t addrlen)
46
46
 
47
47
  if (io_wait) {
48
48
  errno = EAGAIN;
49
- kgio_wait_writable(io, fd);
49
+ (void)kgio_call_wait_writable(io);
50
50
  }
51
51
  return io;
52
52
  }
@@ -81,7 +81,7 @@ static VALUE tcp_connect(VALUE klass, VALUE ip, VALUE port, int io_wait)
81
81
  * Creates a new Kgio::TCPSocket object and initiates a
82
82
  * non-blocking connection.
83
83
  *
84
- * This may block and call any method assigned to Kgio.wait_writable.
84
+ * This may block and call any method defined to kgio_wait_writable.
85
85
  *
86
86
  * Unlike the TCPSocket.new in Ruby, this does NOT perform DNS
87
87
  * lookups (which is subject to a different set of timeouts and
@@ -100,7 +100,7 @@ static VALUE kgio_tcp_connect(VALUE klass, VALUE ip, VALUE port)
100
100
  * Creates a new Kgio::TCPSocket object and initiates a
101
101
  * non-blocking connection. The caller should select/poll
102
102
  * on the socket for writability before attempting to write
103
- * or optimistically attempt a write and handle Kgio::WaitWritable
103
+ * or optimistically attempt a write and handle :wait_writable
104
104
  * or Errno::EAGAIN.
105
105
  *
106
106
  * Unlike the TCPSocket.new in Ruby, this does NOT perform DNS
@@ -138,7 +138,7 @@ static VALUE unix_connect(VALUE klass, VALUE path, int io_wait)
138
138
  * Creates a new Kgio::UNIXSocket object and initiates a
139
139
  * non-blocking connection.
140
140
  *
141
- * This may block and call any method assigned to Kgio.wait_writable.
141
+ * This may block and call any method defined to kgio_wait_writable.
142
142
  */
143
143
  static VALUE kgio_unix_connect(VALUE klass, VALUE path)
144
144
  {
@@ -153,7 +153,7 @@ static VALUE kgio_unix_connect(VALUE klass, VALUE path)
153
153
  * Creates a new Kgio::UNIXSocket object and initiates a
154
154
  * non-blocking connection. The caller should select/poll
155
155
  * on the socket for writability before attempting to write
156
- * or optimistically attempt a write and handle Kgio::WaitWritable
156
+ * or optimistically attempt a write and handle :wait_writable
157
157
  * or Errno::EAGAIN.
158
158
  */
159
159
  static VALUE kgio_unix_start(VALUE klass, VALUE path)
@@ -197,7 +197,7 @@ static VALUE stream_connect(VALUE klass, VALUE addr, int io_wait)
197
197
  * Creates a generic Kgio::Socket object and initiates a
198
198
  * non-blocking connection.
199
199
  *
200
- * This may block and call any method assigned to Kgio.wait_writable.
200
+ * This may block and call any method assigned to kgio_wait_writable.
201
201
  */
202
202
  static VALUE kgio_connect(VALUE klass, VALUE addr)
203
203
  {
@@ -215,7 +215,7 @@ static VALUE kgio_connect(VALUE klass, VALUE addr)
215
215
  * Creates a generic Kgio::Socket object and initiates a
216
216
  * non-blocking connection. The caller should select/poll
217
217
  * on the socket for writability before attempting to write
218
- * or optimistically attempt a write and handle Kgio::WaitWritable
218
+ * or optimistically attempt a write and handle :wait_writable
219
219
  * or Errno::EAGAIN.
220
220
  */
221
221
  static VALUE kgio_start(VALUE klass, VALUE addr)
data/ext/kgio/kgio.h CHANGED
@@ -34,7 +34,7 @@ void init_kgio_read_write(void);
34
34
  void init_kgio_accept(void);
35
35
  void init_kgio_connect(void);
36
36
 
37
- void kgio_wait_writable(VALUE io, int fd);
38
- void kgio_wait_readable(VALUE io, int fd);
37
+ VALUE kgio_call_wait_writable(VALUE io);
38
+ VALUE kgio_call_wait_readable(VALUE io);
39
39
 
40
40
  #endif /* KGIO_H */
@@ -1,5 +1,5 @@
1
1
  #include "kgio.h"
2
- static VALUE mKgio_WaitReadable, mKgio_WaitWritable;
2
+ static VALUE sym_wait_readable, sym_wait_writable;
3
3
  static VALUE eErrno_EPIPE, eErrno_ECONNRESET;
4
4
 
5
5
  /*
@@ -26,7 +26,7 @@ static void raise_empty_bt(VALUE err, const char *msg)
26
26
 
27
27
  static void my_eof_error(void)
28
28
  {
29
- raise_empty_bt(rb_eEOFError, "");
29
+ raise_empty_bt(rb_eEOFError, "end of file reached");
30
30
  }
31
31
 
32
32
  static void wr_sys_fail(const char *msg)
@@ -67,14 +67,14 @@ static int read_check(struct io_args *a, long n, const char *msg, int io_wait)
67
67
  rb_str_set_len(a->buf, 0);
68
68
  if (errno == EAGAIN) {
69
69
  if (io_wait) {
70
- kgio_wait_readable(a->io, a->fd);
70
+ (void)kgio_call_wait_readable(a->io);
71
71
 
72
72
  /* buf may be modified in other thread/fiber */
73
73
  rb_str_resize(a->buf, a->len);
74
74
  a->ptr = RSTRING_PTR(a->buf);
75
75
  return -1;
76
76
  } else {
77
- a->buf = mKgio_WaitReadable;
77
+ a->buf = sym_wait_readable;
78
78
  return 0;
79
79
  }
80
80
  }
@@ -112,8 +112,8 @@ retry:
112
112
  * Reads at most maxlen bytes from the stream socket. Returns with a
113
113
  * newly allocated buffer, or may reuse an existing buffer if supplied.
114
114
  *
115
- * Calls the method assigned to Kgio.wait_readable, or blocks in a
116
- * thread-safe manner for writability.
115
+ * Calls whatever is is defined to be the kgio_wait_readable method
116
+ * for the class.
117
117
  *
118
118
  * Returns nil on EOF.
119
119
  *
@@ -127,7 +127,9 @@ static VALUE kgio_read(int argc, VALUE *argv, VALUE io)
127
127
 
128
128
  /*
129
129
  * Same as Kgio::PipeMethods#kgio_read, except EOFError is raised
130
- * on EOF without a backtrace
130
+ * on EOF without a backtrace. This method is intended as a
131
+ * drop-in replacement for places where IO#readpartial is used, and
132
+ * may be aliased as such.
131
133
  */
132
134
  static VALUE kgio_read_bang(int argc, VALUE *argv, VALUE io)
133
135
  {
@@ -148,7 +150,7 @@ static VALUE kgio_read_bang(int argc, VALUE *argv, VALUE io)
148
150
  *
149
151
  * Returns nil on EOF.
150
152
  *
151
- * Returns Kgio::WaitReadable if EAGAIN is encountered.
153
+ * Returns :wait_readable if EAGAIN is encountered.
152
154
  */
153
155
  static VALUE kgio_tryread(int argc, VALUE *argv, VALUE io)
154
156
  {
@@ -230,7 +232,7 @@ done:
230
232
  long written = RSTRING_LEN(a->buf) - a->len;
231
233
 
232
234
  if (io_wait) {
233
- kgio_wait_writable(a->io, a->fd);
235
+ (void)kgio_call_wait_writable(a->io);
234
236
 
235
237
  /* buf may be modified in other thread/fiber */
236
238
  a->len = RSTRING_LEN(a->buf) - written;
@@ -241,7 +243,7 @@ done:
241
243
  } else if (written > 0) {
242
244
  a->buf = rb_str_new(a->ptr, a->len);
243
245
  } else {
244
- a->buf = mKgio_WaitWritable;
246
+ a->buf = sym_wait_writable;
245
247
  }
246
248
  return 0;
247
249
  }
@@ -276,9 +278,8 @@ retry:
276
278
  *
277
279
  * Returns nil when the write completes.
278
280
  *
279
- * Calls the method Kgio.wait_writable if it is set. Otherwise this
280
- * blocks in a thread-safe manner until all data is written or a
281
- * fatal error occurs.
281
+ * Calls whatever is is defined to be the kgio_wait_writable method
282
+ * for the class.
282
283
  */
283
284
  static VALUE kgio_write(VALUE io, VALUE str)
284
285
  {
@@ -288,14 +289,14 @@ static VALUE kgio_write(VALUE io, VALUE str)
288
289
  /*
289
290
  * call-seq:
290
291
  *
291
- * io.kgio_trywrite(str) -> nil or Kgio::WaitWritable
292
+ * io.kgio_trywrite(str) -> nil or :wait_writable
292
293
  *
293
294
  * Returns nil if the write was completed in full.
294
295
  *
295
296
  * Returns a String containing the unwritten portion if EAGAIN
296
297
  * was encountered, but some portion was successfully written.
297
298
  *
298
- * Returns Kgio::WaitWritable if EAGAIN is encountered and nothing
299
+ * Returns :wait_writable if EAGAIN is encountered and nothing
299
300
  * was written.
300
301
  */
301
302
  static VALUE kgio_trywrite(VALUE io, VALUE str)
@@ -350,9 +351,10 @@ void init_kgio_read_write(void)
350
351
  {
351
352
  VALUE mPipeMethods, mSocketMethods;
352
353
  VALUE mKgio = rb_define_module("Kgio");
354
+ VALUE mWaiters = rb_const_get(mKgio, rb_intern("DefaultWaiters"));
353
355
 
354
- mKgio_WaitReadable = rb_const_get(mKgio, rb_intern("WaitReadable"));
355
- mKgio_WaitWritable = rb_const_get(mKgio, rb_intern("WaitWritable"));
356
+ sym_wait_readable = ID2SYM(rb_intern("wait_readable"));
357
+ sym_wait_writable = ID2SYM(rb_intern("wait_writable"));
356
358
 
357
359
  /*
358
360
  * Document-module: Kgio::PipeMethods
@@ -391,4 +393,6 @@ void init_kgio_read_write(void)
391
393
 
392
394
  eErrno_EPIPE = rb_const_get(rb_mErrno, rb_intern("EPIPE"));
393
395
  eErrno_ECONNRESET = rb_const_get(rb_mErrno, rb_intern("ECONNRESET"));
396
+ rb_include_module(mPipeMethods, mWaiters);
397
+ rb_include_module(mSocketMethods, mWaiters);
394
398
  }
data/ext/kgio/wait.c CHANGED
@@ -1,117 +1,81 @@
1
1
  #include "kgio.h"
2
2
 
3
- static ID io_wait_rd, io_wait_wr;
3
+ static ID id_wait_rd, id_wait_wr;
4
4
 
5
- void kgio_wait_readable(VALUE io, int fd)
6
- {
7
- if (io_wait_rd) {
8
- (void)rb_funcall(io, io_wait_rd, 0, 0);
9
- } else {
10
- if (!rb_io_wait_readable(fd))
11
- rb_sys_fail("wait readable");
12
- }
13
- }
5
+ /*
6
+ * avoiding rb_thread_select() or similar since rb_io_wait_*able can be
7
+ * made to use poll() later on. It's highly unlikely Ruby will move to
8
+ * use an edge-triggered event notification, so assigning EAGAIN is
9
+ * probably safe...
10
+ */
14
11
 
15
- void kgio_wait_writable(VALUE io, int fd)
16
- {
17
- if (io_wait_wr) {
18
- (void)rb_funcall(io, io_wait_wr, 0, 0);
19
- } else {
20
- if (!rb_io_wait_writable(fd))
21
- rb_sys_fail("wait writable");
22
- }
23
- }
24
12
 
25
13
  /*
26
- * call-seq:
14
+ * Blocks the running Thread indefinitely until +self+ IO object is writable.
15
+ * This method is automatically called by default whenever kgio_read needs
16
+ * to block on input.
27
17
  *
28
- * Kgio.wait_readable = :method_name
29
- * Kgio.wait_readable = nil
30
- *
31
- * Sets a method for kgio_read to call when a read would block.
32
- * This is useful for non-blocking frameworks that use Fibers,
33
- * as the method referred to this may cause the current Fiber
34
- * to yield execution.
35
- *
36
- * A special value of nil will cause Ruby to wait using the
37
- * rb_io_wait_readable() function.
18
+ * Users of alternative threading/fiber libraries are
19
+ * encouraged to override this method in their subclasses or modules to
20
+ * work with their threading/blocking methods.
38
21
  */
39
- static VALUE set_wait_rd(VALUE mod, VALUE sym)
22
+ static VALUE kgio_wait_readable(VALUE self)
40
23
  {
41
- switch (TYPE(sym)) {
42
- case T_SYMBOL:
43
- io_wait_rd = SYM2ID(sym);
44
- return sym;
45
- case T_NIL:
46
- io_wait_rd = 0;
47
- return sym;
48
- }
49
- rb_raise(rb_eTypeError, "must be a symbol or nil");
50
- return sym;
24
+ errno = EAGAIN;
25
+ if (!rb_io_wait_readable(my_fileno(self)))
26
+ rb_sys_fail("kgio_wait_readable");
27
+
28
+ return self;
51
29
  }
52
30
 
53
31
  /*
54
- * call-seq:
55
- *
56
- * Kgio.wait_writable = :method_name
57
- * Kgio.wait_writable = nil
58
- *
59
- * Sets a method for kgio_write to call when a read would block.
60
- * This is useful for non-blocking frameworks that use Fibers,
61
- * as the method referred to this may cause the current Fiber
62
- * to yield execution.
63
- *
64
- * A special value of nil will cause Ruby to wait using the
65
- * rb_io_wait_writable() function.
32
+ * blocks the running Thread indefinitely until +self+ IO object is writable
33
+ * This method is automatically called whenever kgio_write needs to
34
+ * block on output.
35
+ * Users of alternative threading/fiber libraries are
36
+ * encouraged to override this method in their subclasses or modules to
37
+ * work with their threading/blocking methods.
66
38
  */
67
- static VALUE set_wait_wr(VALUE mod, VALUE sym)
39
+ static VALUE kgio_wait_writable(VALUE self)
68
40
  {
69
- switch (TYPE(sym)) {
70
- case T_SYMBOL:
71
- io_wait_wr = SYM2ID(sym);
72
- return sym;
73
- case T_NIL:
74
- io_wait_wr = 0;
75
- return sym;
76
- }
77
- rb_raise(rb_eTypeError, "must be a symbol or nil");
78
- return sym;
41
+ errno = EAGAIN;
42
+ if (!rb_io_wait_writable(my_fileno(self)))
43
+ rb_sys_fail("kgio_wait_writable");
44
+
45
+ return self;
79
46
  }
80
47
 
81
- /*
82
- * call-seq:
83
- *
84
- * Kgio.wait_writable -> Symbol or nil
85
- *
86
- * Returns the symbolic method name of the method assigned to
87
- * call when EAGAIN is occurs on a Kgio::PipeMethods#kgio_write
88
- * or Kgio::SocketMethods#kgio_write call
89
- */
90
- static VALUE wait_wr(VALUE mod)
48
+ VALUE kgio_call_wait_writable(VALUE io)
91
49
  {
92
- return io_wait_wr ? ID2SYM(io_wait_wr) : Qnil;
50
+ return rb_funcall(io, id_wait_wr, 0, 0);
93
51
  }
94
52
 
95
- /*
96
- * call-seq:
97
- *
98
- * Kgio.wait_readable -> Symbol or nil
99
- *
100
- * Returns the symbolic method name of the method assigned to
101
- * call when EAGAIN is occurs on a Kgio::PipeMethods#kgio_read
102
- * or Kgio::SocketMethods#kgio_read call.
103
- */
104
- static VALUE wait_rd(VALUE mod)
53
+ VALUE kgio_call_wait_readable(VALUE io)
105
54
  {
106
- return io_wait_rd ? ID2SYM(io_wait_rd) : Qnil;
55
+ return rb_funcall(io, id_wait_rd, 0, 0);
107
56
  }
108
57
 
109
58
  void init_kgio_wait(void)
110
59
  {
111
60
  VALUE mKgio = rb_define_module("Kgio");
112
61
 
113
- rb_define_singleton_method(mKgio, "wait_readable=", set_wait_rd, 1);
114
- rb_define_singleton_method(mKgio, "wait_writable=", set_wait_wr, 1);
115
- rb_define_singleton_method(mKgio, "wait_readable", wait_rd, 0);
116
- rb_define_singleton_method(mKgio, "wait_writable", wait_wr, 0);
62
+ /*
63
+ * Document-module: Kgio::DefaultWaiters
64
+ *
65
+ * This module contains default kgio_wait_readable and
66
+ * kgio_wait_writable methods that block indefinitely (in a
67
+ * thread-safe manner) until an IO object is read or writable.
68
+ * This module is included in the Kgio::PipeMethods and
69
+ * Kgio::SocketMethods modules used by all bundled IO-derived
70
+ * objects.
71
+ */
72
+ VALUE mWaiters = rb_define_module_under(mKgio, "DefaultWaiters");
73
+
74
+ id_wait_rd = rb_intern("kgio_wait_readable");
75
+ id_wait_wr = rb_intern("kgio_wait_writable");
76
+
77
+ rb_define_method(mWaiters, "kgio_wait_readable",
78
+ kgio_wait_readable, 0);
79
+ rb_define_method(mWaiters, "kgio_wait_writable",
80
+ kgio_wait_writable, 0);
117
81
  }
data/kgio.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.authors = ["kgio hackers"]
12
12
  s.date = Time.now.utc.strftime('%Y-%m-%d')
13
13
  s.description = description
14
- s.email = %q{mongrel-unicorn@rubyforge.org}
14
+ s.email = %q{kgio@bogomips.org}
15
15
 
16
16
  s.extra_rdoc_files = File.readlines('.document').map! do |x|
17
17
  x.chomp!
data/lib/kgio.rb CHANGED
@@ -8,11 +8,11 @@ module Kgio
8
8
  LOCALHOST = '127.0.0.1'
9
9
 
10
10
  # Kgio::PipeMethods#kgio_tryread and Kgio::SocketMethods#kgio_tryread will
11
- # return this constant when waiting for a read is required.
11
+ # return :wait_readable when waiting for a read is required.
12
12
  WaitReadable = :wait_readable
13
13
 
14
- # PipeMethods#kgio_trywrite and SocketMethods#kgio_trywrite will
15
- # return this constant when waiting for a read is required.
14
+ # PipeMethods#kgio_trywrite and SocketMethods#kgio_trywrite will return
15
+ # :wait_writable when waiting for a read is required.
16
16
  WaitWritable = :wait_writable
17
17
  end
18
18
 
@@ -13,9 +13,6 @@ module LibReadWriteTest
13
13
  @rd.close unless @rd.closed?
14
14
  @wr.close unless @wr.closed?
15
15
  end
16
- assert_nothing_raised do
17
- Kgio.wait_readable = Kgio.wait_writable = nil
18
- end
19
16
  end
20
17
 
21
18
  def test_read_zero
@@ -97,9 +94,9 @@ module LibReadWriteTest
97
94
  case rv
98
95
  when String
99
96
  wr = rv
100
- when Kgio::WaitReadable
97
+ when :wait_readable
101
98
  assert false, "should never get here line=#{__LINE__}"
102
- when Kgio::WaitWritable
99
+ when :wait_writable
103
100
  IO.select(nil, [ @wr ])
104
101
  else
105
102
  wr = false
@@ -122,7 +119,7 @@ module LibReadWriteTest
122
119
  end
123
120
 
124
121
  def test_tryread_empty
125
- assert_equal Kgio::WaitReadable, @rd.kgio_tryread(1)
122
+ assert_equal :wait_readable, @rd.kgio_tryread(1)
126
123
  end
127
124
 
128
125
  def test_read_too_much
@@ -159,10 +156,10 @@ module LibReadWriteTest
159
156
 
160
157
  def test_trywrite_return_wait_writable
161
158
  tmp = []
162
- tmp << @wr.kgio_trywrite("HI") until tmp[-1] == Kgio::WaitWritable
163
- assert Kgio::WaitWritable === tmp[-1]
164
- assert(!(Kgio::WaitReadable === tmp[-1]))
165
- assert_equal Kgio::WaitWritable, tmp.pop
159
+ tmp << @wr.kgio_trywrite("HI") until tmp[-1] == :wait_writable
160
+ assert :wait_writable === tmp[-1]
161
+ assert(!(:wait_readable === tmp[-1]))
162
+ assert_equal :wait_writable, tmp.pop
166
163
  assert tmp.size > 0
167
164
  penultimate = tmp.pop
168
165
  assert(penultimate == "I" || penultimate == nil)
@@ -173,7 +170,7 @@ module LibReadWriteTest
173
170
  def test_tryread_extra_buf_eagain_clears_buffer
174
171
  tmp = "hello world"
175
172
  rv = @rd.kgio_tryread(2, tmp)
176
- assert_equal Kgio::WaitReadable, rv
173
+ assert_equal :wait_readable, rv
177
174
  assert_equal "", tmp
178
175
  end
179
176
 
@@ -205,11 +202,10 @@ module LibReadWriteTest
205
202
 
206
203
  def test_monster_write_wait_writable
207
204
  @wr.instance_variable_set :@nr, 0
208
- def @wr.wait_writable
205
+ def @wr.kgio_wait_writable
209
206
  @nr += 1
210
207
  IO.select(nil, [self])
211
208
  end
212
- Kgio.wait_writable = :wait_writable
213
209
  buf = "." * 1024 * 1024 * 10
214
210
  thr = Thread.new { @wr.kgio_write(buf) }
215
211
  readed = @rd.read(buf.size)
@@ -220,7 +216,6 @@ module LibReadWriteTest
220
216
  end
221
217
 
222
218
  def test_wait_readable_ruby_default
223
- assert_nothing_raised { Kgio.wait_readable = nil }
224
219
  elapsed = 0
225
220
  foo = nil
226
221
  t0 = Time.now
@@ -243,7 +238,6 @@ module LibReadWriteTest
243
238
  rescue Errno::EAGAIN
244
239
  break
245
240
  end while true
246
- assert_nothing_raised { Kgio.wait_writable = nil }
247
241
  elapsed = 0
248
242
  foo = nil
249
243
  t0 = Time.now
@@ -261,10 +255,9 @@ module LibReadWriteTest
261
255
  end
262
256
 
263
257
  def test_wait_readable_method
264
- def @rd.moo
258
+ def @rd.kgio_wait_readable
265
259
  defined?(@z) ? raise(RuntimeError, "Hello") : @z = "HI"
266
260
  end
267
- assert_nothing_raised { Kgio.wait_readable = :moo }
268
261
  foo = nil
269
262
  begin
270
263
  foo = @rd.kgio_read(5)
@@ -277,29 +270,26 @@ module LibReadWriteTest
277
270
  end
278
271
 
279
272
  def test_tryread_wait_readable_method
280
- def @rd.moo
273
+ def @rd.kgio_wait_readable
281
274
  raise "Hello"
282
275
  end
283
- assert_nothing_raised { Kgio.wait_readable = :moo }
284
- assert_equal Kgio::WaitReadable, @rd.kgio_tryread(5)
276
+ assert_equal :wait_readable, @rd.kgio_tryread(5)
285
277
  end
286
278
 
287
279
  def test_trywrite_wait_readable_method
288
- def @wr.moo
280
+ def @wr.kgio_wait_writable
289
281
  raise "Hello"
290
282
  end
291
- assert_nothing_raised { Kgio.wait_writable = :moo }
292
283
  tmp = []
293
284
  buf = "." * 1024
294
285
  10000.times { tmp << @wr.kgio_trywrite(buf) }
295
- assert_equal Kgio::WaitWritable, tmp.pop
286
+ assert_equal :wait_writable, tmp.pop
296
287
  end
297
288
 
298
289
  def test_wait_writable_method
299
- def @wr.moo
290
+ def @wr.kgio_wait_writable
300
291
  defined?(@z) ? raise(RuntimeError, "Hello") : @z = "HI"
301
292
  end
302
- assert_nothing_raised { Kgio.wait_writable = :moo }
303
293
  n = []
304
294
  begin
305
295
  loop { n << @wr.kgio_write("HIHIHIHIHIHI") }
@@ -5,10 +5,6 @@ require 'kgio'
5
5
 
6
6
  class TestConnectFDLeak < Test::Unit::TestCase
7
7
 
8
- def teardown
9
- Kgio.wait_readable = Kgio.wait_writable = nil
10
- end
11
-
12
8
  def test_unix_socket
13
9
  nr = 0
14
10
  path = "/non/existent/path"
@@ -0,0 +1,21 @@
1
+ require 'test/unit'
2
+ require 'io/nonblock'
3
+ $-w = true
4
+ require 'kgio'
5
+
6
+ class TestDefaultWait < Test::Unit::TestCase
7
+
8
+ def test_socket_pair
9
+ a, b = Kgio::UNIXSocket.pair
10
+ assert_equal a, a.kgio_wait_writable
11
+ a.syswrite('.')
12
+ assert_equal b, b.kgio_wait_readable
13
+ end
14
+
15
+ def test_pipe
16
+ a, b = Kgio::Pipe.new
17
+ assert_equal b, b.kgio_wait_writable
18
+ b.syswrite('.')
19
+ assert_equal a, a.kgio_wait_readable
20
+ end
21
+ end
@@ -6,7 +6,7 @@ require 'kgio'
6
6
  class TestPipePopen < Test::Unit::TestCase
7
7
  def test_popen
8
8
  io = Kgio::Pipe.popen("sleep 1 && echo HI")
9
- assert_equal Kgio::WaitReadable, io.kgio_tryread(2)
9
+ assert_equal :wait_readable, io.kgio_tryread(2)
10
10
  sleep 1.5
11
11
  assert_equal "HI\n", io.kgio_read(3)
12
12
  assert_nil io.kgio_read(5)
@@ -5,7 +5,7 @@ require 'kgio'
5
5
 
6
6
  class SubSocket < Kgio::Socket
7
7
  attr_accessor :foo
8
- def wait_writable
8
+ def kgio_wait_writable
9
9
  @foo = "waited"
10
10
  end
11
11
  end
@@ -23,7 +23,6 @@ class TestKgioTcpConnect < Test::Unit::TestCase
23
23
  @srv.close unless @srv.closed?
24
24
  Kgio.accept_cloexec = true
25
25
  Kgio.accept_nonblock = false
26
- Kgio.wait_readable = Kgio.wait_writable = nil
27
26
  end
28
27
 
29
28
  def test_new
@@ -56,7 +55,6 @@ class TestKgioTcpConnect < Test::Unit::TestCase
56
55
  end
57
56
 
58
57
  def test_socket_start
59
- Kgio::wait_writable = :wait_writable
60
58
  sock = SubSocket.start(@addr)
61
59
  assert_nil sock.foo
62
60
  ready = IO.select(nil, [ sock ])
@@ -65,7 +63,6 @@ class TestKgioTcpConnect < Test::Unit::TestCase
65
63
  end
66
64
 
67
65
  def test_wait_writable_set
68
- Kgio::wait_writable = :wait_writable
69
66
  sock = SubSocket.new(@addr)
70
67
  assert_equal "waited", sock.foo
71
68
  assert_equal nil, sock.kgio_write("HELLO")
@@ -6,7 +6,7 @@ require 'tempfile'
6
6
 
7
7
  class SubSocket < Kgio::Socket
8
8
  attr_accessor :foo
9
- def wait_writable
9
+ def kgio_wait_writable
10
10
  @foo = "waited"
11
11
  end
12
12
  end
@@ -57,7 +57,6 @@ class TestKgioUnixConnect < Test::Unit::TestCase
57
57
  end
58
58
 
59
59
  def test_socket_start
60
- Kgio::wait_writable = :wait_writable
61
60
  sock = SubSocket.start(@addr)
62
61
  assert_nil sock.foo
63
62
  ready = IO.select(nil, [ sock ])
@@ -66,7 +65,6 @@ class TestKgioUnixConnect < Test::Unit::TestCase
66
65
  end
67
66
 
68
67
  def test_wait_writable_set
69
- Kgio::wait_writable = :wait_writable
70
68
  sock = SubSocket.new(@addr)
71
69
  assert_kind_of Kgio::Socket, sock
72
70
  assert_instance_of SubSocket, sock
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kgio
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: -766259887
5
+ prerelease: true
6
6
  segments:
7
- - 1
8
- - 3
9
- - 1
10
- version: 1.3.1
7
+ - 2
8
+ - 0
9
+ - 0pre1
10
+ version: 2.0.0pre1
11
11
  platform: ruby
12
12
  authors:
13
13
  - kgio hackers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-08 00:00:00 +00:00
18
+ date: 2010-11-18 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -24,7 +24,7 @@ description: |-
24
24
  exceptions on EAGAIN and EINPROGRESS. It is intended for use with the
25
25
  Unicorn and Rainbows! Rack servers, but may be used by other
26
26
  applications.
27
- email: mongrel-unicorn@rubyforge.org
27
+ email: kgio@bogomips.org
28
28
  executables: []
29
29
 
30
30
  extensions:
@@ -78,6 +78,7 @@ files:
78
78
  - test/lib_server_accept.rb
79
79
  - test/test_accept_class.rb
80
80
  - test/test_connect_fd_leak.rb
81
+ - test/test_default_wait.rb
81
82
  - test/test_pipe_popen.rb
82
83
  - test/test_pipe_read_write.rb
83
84
  - test/test_socketpair_read_write.rb
@@ -112,12 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
113
  required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  none: false
114
115
  requirements:
115
- - - ">="
116
+ - - ">"
116
117
  - !ruby/object:Gem::Version
117
- hash: 3
118
+ hash: 25
118
119
  segments:
119
- - 0
120
- version: "0"
120
+ - 1
121
+ - 3
122
+ - 1
123
+ version: 1.3.1
121
124
  requirements: []
122
125
 
123
126
  rubyforge_project: rainbows
@@ -126,6 +129,7 @@ signing_key:
126
129
  specification_version: 3
127
130
  summary: kinder, gentler I/O for Ruby
128
131
  test_files:
132
+ - test/test_default_wait.rb
129
133
  - test/test_unix_connect.rb
130
134
  - test/test_pipe_read_write.rb
131
135
  - test/test_unix_server.rb