From 6876f79b3403eb2cdb1336241d177ac076c91d63 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 22 Sep 2013 03:43:14 +0000 Subject: [DOC] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/io.c b/io.c index e23ba16ca0..29b25d74f1 100644 --- a/io.c +++ b/io.c @@ -8493,7 +8493,7 @@ rb_io_advise(int argc, VALUE *argv, VALUE io) * It is not happen for IO-like objects such as OpenSSL::SSL::SSLSocket. * * The best way to use IO.select is invoking it - * after nonblocking methods such as read_nonblock. + * after nonblocking methods such as read_nonblock, write_nonblock, etc. * The methods raises an exception which is extended by * IO::WaitReadable or IO::WaitWritable. * The modules notify how the caller should wait with IO.select. @@ -8555,6 +8555,26 @@ rb_io_advise(int argc, VALUE *argv, VALUE io) * Invoking IO.select before IO#readpartial works well in usual. * However it is not the best way to use IO.select. * + * The writability notified by select(2) doesn't show + * how many bytes writable. + * IO#write method blocks until given whole string is written. + * So, IO#write(two or more bytes) can block after writability is notified by IO.select. + * IO#write_nonblock is required to avoid the blocking. + * + * Blocking write (write) can be emulated using + * write_nonblock and IO.select as follows: + * IO::WaitReadable should also be rescued for SSL renegotiation in OpenSSL::SSL::SSLSocket. + * + * begin + * result = io_like.write_nonblock(string) + * rescue IO::WaitReadable + * IO.select([io_like]) + * retry + * rescue IO::WaitWritable + * IO.select(nil, [io_like]) + * retry + * end + * * === Parameters * read_array:: an array of IO objects that wait until ready for read * write_array:: an array of IO objects that wait until ready for write -- cgit v1.2.3