> -----Original Message-----
> From: Nathaniel Talbott [mailto:nathaniel / talbott.ws] 
> Sent: Friday, December 05, 2003 3:43 PM
> To: ruby-core / ruby-lang.org
> Subject: Errno::EINPROGRESS in WEBrick
> 
> 
> A partial backtrace:
> 
>    [2003-12-04 10:35:18] ERROR Errno::EINPROGRESS: Operation now in 
> progress
>            /usr/lib/ruby/1.8/webrick/httpresponse.rb:301:in `write'
>            /usr/lib/ruby/1.8/webrick/httpresponse.rb:301:in `<<'
>            /usr/lib/ruby/1.8/webrick/httpresponse.rb:301:in 
> `_write_data'
>            /usr/lib/ruby/1.8/webrick/httpresponse.rb:273:in 
> `send_body_string'
>            /usr/lib/ruby/1.8/webrick/httpresponse.rb:167:in 
> `send_body'
> 
> My question is, should this simply be caught by 
> WEBrick::HTTPResponse#send_response (like Errno::EPIPE, 
> Errno::ECONNRESET, Errno::ENOTCONN), or is it indicative of a more 
> serious problem that needs to be resolved? I don't have a good enough 
> understanding of the cause of EINPROGRESS to know the answer.
> 
> 
> Nathaniel
> 
> <:((><

Assuming things are consistent with regards to sockets between Perl and
Ruby, a non-blocking connect doesn't (usually) return successfully right
away.  It will usually return EINPROGRESS which indicates that the
non-blocking connect is in progress and should be checked periodically
for completion (to paraphrase Lincoln Stein).

The approach Lincoln Stein uses is this:

1) connect
2) check error, ignore EINPROGRESS
3) select on the socket
4) wait until the socket is writable (or timeout)
5) return to blocking mode if desired

Hope that helps.

Regards,

Dan

PS - See "Network Programming with Perl", p.396 for an easily
translatable example if you happen to have the book.