ÿØÿà JFIF ÿÛ „ ( %!1!%*+...983,7(-.-
U:RDoc::AnyMethod[iI"select:ETI"Kernel#select;TF:privateo:RDoc::Markup::Document:@parts[-o:RDoc::Markup::Paragraph; [I""Calls select(2) system call. ;TI"HIt monitors given arrays of IO objects, waits until one or more of ;TI"GIO objects are ready for reading, are ready for writing, and have ;TI"Ipending exceptions respectively, and returns an array that contains ;TI"Carrays of those IO objects. It will return +nil+ if optional ;TI"@timeout value is given and no IO object is ready in ;TI"timeout seconds.;To:RDoc::Markup::BlankLine o;
; [ I"GIO.select peeks the buffer of IO objects for testing readability. ;TI"CIf the IO buffer is not empty, IO.select immediately notifies ;TI"Ireadability. This "peek" only happens for IO objects. It does not ;TI"@happen for IO-like objects such as OpenSSL::SSL::SSLSocket.;T@o;
; [I"DThe best way to use IO.select is invoking it after nonblocking ;TI"Hmethods such as #read_nonblock, #write_nonblock, etc. The methods ;TI"Araise an exception which is extended by IO::WaitReadable or ;TI"FIO::WaitWritable. The modules notify how the caller should wait ;TI"Gwith IO.select. If IO::WaitReadable is raised, the caller should ;TI"Iwait for reading. If IO::WaitWritable is raised, the caller should ;TI"wait for writing.;T@o;
; [I"IO#write(two or more bytes) can block after ;TI"Jwritability is notified by IO.select. IO#write_nonblock is required ;TI"to avoid the blocking.;T@o;
; [I"GBlocking write (#write) can be emulated using #write_nonblock and ;TI"GIO.select as follows: IO::WaitReadable should also be rescued for ;TI"2SSL renegotiation in OpenSSL::SSL::SSLSocket.;T@o;; [I"while 0 < string.bytesize
;TI"
begin
;TI"2 written = io_like.write_nonblock(string)
;TI" rescue IO::WaitReadable
;TI" IO.select([io_like])
;TI" retry
;TI" rescue IO::WaitWritable
;TI"# IO.select(nil, [io_like])
;TI" retry
;TI" end
;TI". string = string.byteslice(written..-1)
;TI" end
;T;
0S:RDoc::Markup::Heading:
leveli: textI"Parameters;To:RDoc::Markup::List:
@type: NOTE:@items[ o:RDoc::Markup::ListItem:@label[I"read_array;T; [o;
; [I":an array of IO objects that wait until ready for read;To;;[I"write_array;T; [o;
; [I";an array of IO objects that wait until ready for write;To;;[I"error_array;T; [o;
; [I"4an array of IO objects that wait for exceptions;To;;[I"timeout;T; [o;
; [I"a numeric value in second;T@S;;i;I"Example;T@o;; [I"rp, wp = IO.pipe
;TI"mesg = "ping "
;TI"100.times {
;TI"H # IO.select follows IO#read. Not the best way to use IO.select.
;TI"' rs, ws, = IO.select([rp], [wp])
;TI" if r = rs[0]
;TI" ret = r.read(5)
;TI" print ret
;TI" case ret
;TI" when /ping/
;TI" mesg = "pong\n"
;TI" when /pong/
;TI" mesg = "ping "
;TI"
end
;TI" end
;TI" if w = ws[0]
;TI" w.write(mesg)
;TI" end
;TI"}
;T;
0o;
; [I"produces:;T@o;; [
I"ping pong
;TI"ping pong
;TI"ping pong
;TI"(snipped)
;TI" ping;T;
0:
@fileI" io.c;T:0@omit_headings_from_table_of_contents_below0I"WIO.select(read_array [, write_array [, error_array [, timeout]]]) -> array or nil
;T0[ I"$(p1, p2 = v2, p3 = v3, p4 = v4);T@¼FI"Kernel;TcRDoc::NormalModule00