From: Bill Kelly Date: 2003-05-16T21:33:27+09:00 Subject: Re: TCP Sockets Hi, From: "Dominik Werder" > > my problem is not the http protocol itself (not at this time :) but the IO- > blocking. > If I try to read all the lines the server must have send to me, but the > data is not yet available to the socket, the process blocks. > I wondered if it's possible to solve this without threads, for example with > the knowledge about the amount of bytes that can be read without blocking.. 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.) HTH, Bill