Problem with Non Blocking Socket Connections

Hello,

I am trying to create a socket that is set to O_NONBLOCK before initiating
the connection. This is what I have tried:

socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
socket.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
socket.connect(sockaddr_server)

When sockaddr_server is accessable, connections are established even though
an Errno::EINPROGRESS exception is supposed to be raised.
When the network is down, the connect call hangs.

I have tried the same code with Ruby versions 1.6.8, 1.7 and 1.8 on
Debian (Unstable).

Thank you,
Masuo

socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
socket.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
socket.connect(sockaddr_server)

This is what do internally Socket#connect, i.e. the socket is put in
non-blocking mode and ruby manage EAGAIN, EINPROGRESS, ...

Guy Decoux