From: Dominik Werder Date: 2003-05-16T22:30:34+09:00 Subject: Re: TCP Sockets Thanks for posting, I guess this should be working for me. I'm only very confused why something like this is so hard to do. But it's probably because everybody uses threads.. bye! Dominik > Sorry if this has already been covered, but, I've used select() > successfully to test whether data is available at a socket. > (I wrote a non-blocking multi-client server without threads this > way before learning how well and easily Ruby threads handle > socket I/O.) > > Was select() not appropriate to your situation? > > For what it's worth, here's a code example that's working for me > from my non-threaded app: > > # read any available chars and append them to our local buffer > def terminal_buffered_read > begin if Kernel.select([self], nil, nil, 0) > dat = self.recv(65536) > if !dat || dat.empty? > @term_eof = true > else > @term_read_buf << dat > end > end > rescue IOError, SystemCallError > @term_eof = true > end > end > > (The above was part of a module whose methods were added to a > socket IO object via Object#extend.)