From: Tanaka Akira Date: 2005-01-26T00:27:44+09:00 Subject: Re: In need of Win32 fcntl (non-blocking) In article <41F65F1B.80706@palli.nl>, Ivo Palli writes: > Instead I want to use a select, which is thankfully support in Ruby. > However a read to a socket which has data open always seems to block, > unless I specifically read what is available. Since I cannot know how > much data is waiting for me, I really need to do a non-blocking read. In > Linux it works, in Windows the fcntl call is not supported. :( As far as > I searched and tried, there is no other way to read data without blocking. sysread might be usable because sysread doesn't block when some data available. If sysread is usable, you don't need non-blocking read. require "socket" gs = TCPserver.open(0) addr = gs.addr addr.shift printf("server is on %s\n", addr.join(":")) socks = [gs] loop do nsock = select(socks); next if nsock == nil for s in nsock[0] if s == gs ns = s.accept socks.push(ns) print(s, " is accepted\n") else begin print "[" + s.sysread(4096) + "]\n" rescue EOFError print(s, " is gone\n") s.close socks.delete(s) end end end end -- Tanaka Akira