From: Francis Cianfrocca Date: 2006-05-09T09:45:33+09:00 Subject: Re: Considering Ruby For a Networking Application ------=_Part_46583_11883964.1147135530003 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline From what you said, this code doesn't do what you think it should do: # hmm, io/nonblock refuses to work on windows because # of missing GETFL :( Just fake it... if RUBY_PLATFORM =3D~ /mswin32/ class IO def nonblock=3D(nb) fcntl(Fcntl::F_SETFL, nb ? Fcntl::O_NONBLOCK : 0) end end end That's because on Windows, this isn't the way to set sockets nonblocking. Microsoft reinvented a lot of wheels in Windows, and this is one of 'em. Tr= y this C code instead (I'll leave it to you to turn it into Ruby): unsigned long one =3D 1; ioctlsocket (the_socket_descriptor, FIONBIO, &one); This will return non-zero in case of error (I've never seen it return an error). Best -francis On 5/8/06, Bill Kelly wrote: > > From: "James Edward Gray II" > > > > On May 8, 2006, at 12:12 PM, Francis Cianfrocca wrote: > > > >> If your performance and scalability requirements are low, then the > >> easiest thing is > >> probably to use blocking i/o with a thread per socket. If you use > >> blocking > >> i/o, you're better off multiplexing the i/o with a select loop. > > > > But then a large write could still block the entire process, since > > Ruby's threads aren't native. Right? > > Judging from the results of my test program on Linux and > Windows, it appears nonblocking writes are supported in > 1.8.4. > > ruby 1.8.4 (2005-12-24) [i686-linux] > ruby 1.8.4 (2005-12-24) [i386-mswin32] > > Interestingly, while the Linux version behaved as expected, > displaying blocking characteristics until I explicitly set > nonblock=3Dtrue, the windows version appears to sport some > sort of always-on nonblocking buffered implementation behind > the scenes now. > > On Windows, even if I never set nonblock=3Dtrue, I could syswrite > 40 megs to the socket and #syswrite would return immediately! > (Subsequent syswrites would then appear to block until the > data from the previous huge syswrite was consumed; but just the > ruby thread performing the syswrite was blocked, never the whole > process. So anyway there's some kind of dynamic buffering going > on behind the scenes in the windows implementation--but in any > case, it never blocked the whole process. Excellent.) > > In my test program (attached) I'm catching just about every > exception under the sun, including EAGAIN, which I saw being > done in lib/openssl/buffering.rb. However, the only > exception I actually saw raised was EOFError. (I never tried > to force an EPIPE condition on the write.) > > Anyway, for what it's worth, it appears ruby 1.8.4 now > definitely supports nonblocking socket I/O on both Linux > and Windows!! Yay! > > I'll still be looking at EventMachine though. :) > > > Regards, > > Bill > > > > ------=_Part_46583_11883964.1147135530003--