Fix for the Webrick "Errno::EINVAL: Invalid argument" error

It turns out that the problem is with the following HTTPServer#run code:

          while timeout > 0
            break if IO.select([sock], nil, nil, 0.5)
            timeout = 0 if @status != :Running
            timeout -= 0.5
          end
          raise HTTPStatus::EOFError if timeout <= 0
          req.parse(sock)

where parse(sock) throws StandardError exception.
It happens because IO.select returns [[sock], [], []] while client has
closed its side of the connection. The fix can be as simple as adding
test for the sock.eof to the raise statement:

          raise HTTPStatus::EOFError if timeout <= 0 || sock.eof?

Or may be it should be:

          break if timeout <= 0 || sock.eof?

Regards,
Yura.

Hi,

In message <20050511235118.AF182355B2@beryllium.ruby-lang.org>,

···

`"Yura Kloubakov" <ykloubakov@ftxs.fujitsu.com>' wrote:

It happens because IO.select returns [[sock], , ] while client has
closed its side of the connection. The fix can be as simple as adding
test for the sock.eof to the raise statement:

          raise HTTPStatus::EOFError if timeout <= 0 || sock.eof?

Thanks. Should I apply it to Ruby 1.9 too?

--
gotoyuzo