From: nobu.nokada@... Date: 2003-03-02T18:27:42+09:00 Subject: Re: Unable to do non-blocking read on socket --Multipart_Sun_Mar__2_18:27:38_2003-1 Content-Type: text/plain; charset=US-ASCII Hi, At Fri, 28 Feb 2003 01:12:07 +0900, Seth Kurtzberg wrote: > This is with 1.8 CVS head on linux kernel 2.4.20. EAGAIN/EWOULDBLOCK should be handled in 1.8, IO#read with no arguments for non-blocking IO doesn't wait unreceived data. $ ruby server.rb foo & [1] 13697 $ ruby client.rb foo "" $ ruby client.rb foo 3 "hello," $ ruby client.rb foo 5 "hello, world" --Multipart_Sun_Mar__2_18:27:38_2003-1 Content-Type: text/x-ruby; charset=US-ASCII Content-Disposition: attachment; filename="server.rb" Content-Transfer-Encoding: 7bit #! /usr/bin/ruby require 'socket' PATH = ARGV.shift s = UNIXServer.open(PATH) begin loop do Thread.new(s.accept) do |t| sleep 1 t.write "hello," sleep 2 t.write " world" end end ensure s.close File.unlink(PATH) end --Multipart_Sun_Mar__2_18:27:38_2003-1 Content-Type: text/x-ruby; charset=US-ASCII Content-Disposition: attachment; filename="client.rb" Content-Transfer-Encoding: 7bit #! /usr/bin/ruby require 'socket' require 'io/nonblock' PATH = ARGV.shift WAIT = ARGV.shift.to_i s = UNIXSocket.new(PATH) p s.nonblock {sleep WAIT; s.read} --Multipart_Sun_Mar__2_18:27:38_2003-1 Content-Type: text/x-ruby; charset=US-ASCII Content-Disposition: attachment; filename="io/nonblock.rb" Content-Transfer-Encoding: 7bit require "fcntl" class IO def nonblock? (fcntl(Fcntl::F_GETFL) & File::NONBLOCK) != 0 end def nonblock=(nb) f = fcntl(Fcntl::F_GETFL) if nb f |= File::NONBLOCK else f &= ~File::NONBLOCK end fcntl(Fcntl::F_SETFL, f) end def nonblock(nb = true) nb, self.nonblock = nonblock?, nb yield ensure self.nonblock = nb end end --Multipart_Sun_Mar__2_18:27:38_2003-1 Content-Type: text/plain; charset=US-ASCII -- Nobu Nakada --Multipart_Sun_Mar__2_18:27:38_2003-1--