From: Brian Candler Date: 2003-05-16T19:33:46+09:00 Subject: Re: TCP Sockets On Fri, May 16, 2003 at 07:20:30PM +0900, Dominik Werder wrote: > 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.. Maybe, but threads are really the "ruby way" to solve this problem. In other words: if you care that the process blocks with a half-received HTTP request, because you want to be doing something else at the same time, then the 'something else' can be done in another thread. Threads in Ruby are really just a convenient abstraction over select(). If a thread is about to do an operation which would block, it adds its fd to those waiting for data, and hands over control to another thread. When its fd becomes ready again, at a convenient time it will get control handed back to it. Regards, Brian.