From: "Christoffer Lernö" Date: 2007-10-14T16:13:43+09:00 Subject: Re: write_nonblock is blocking? On 14 Oct 2007, at 01:23, Eric Hodel wrote: > On Oct 13, 2007, at 14:55 , Christoffer Lernö wrote: >> Anyone know what's up with TCPSocket#write_noblock actually >> blocking when sending a packet that exceeds the buffer size of the >> socket in 1.8.6 on Mac. >> >> The behaviour seems slightly counter-productive. > > How long does it block? I see ruby occasionally being delayed 10ms > when using write_nonblock, but not repeatably for the same packet > sizes. Probably my benchmark script is wrong. > > Could you supply a benchmark script that illustrates your problem? > > #write_nonblock first does rb_io_check_closed() which might call > down to fseek(3) then write(2) before calling rb_io_set_nonblock > (). I'm not even close to being a sockets expert though, I just > read the man pages. Thanks. Know it "should work" made me try to analyze the situation. Here is an example code: require 'socket' a = TCPServer.new(5000) socket = TCPSocket.new("localhost", 5000) # Using a.accept will give a socket that does not exhibit problems, # Only TCPServer#accept_nonblock seems to create this # odd situation. other = a.accept_nonblock puts "Start Write" # Lower values, say "X" * 2000, writes all in one sweep and does # not cause it block other.write_nonblock("X" * 300000) puts "End Write" It looks like write_nonblock together with accept_nonblock causes some issues. Now I could be using these wrong as both are new (in 1.8.6?) /Christoffer