[Haskell-cafe] controlling timeout for Network.Socket.connect - how?

Manlio Perillo manlio_perillo at libero.it
Sat Feb 28 15:23:58 EST 2009

Belka ha scritto:
> Thanks, Manlio!
>> What system?
> ArchLinux (2.6.27)
>> Is the timeout the same with a plain C program?
> Didn't try yet... ^__^
>>> I know that controlling timeout is somehow connected to select(2) 
>> Yes.
>> The only working method is to set the socket to non blocking mode, and 
>> use select (or poll/epoll/kqueue).
> Thanks, now I'm confident, that am on the right way! ^__^
> I wonder, if *select* really blocks the whole process... or blocks just the
> "green" thread, that called it?.. 

select blocks the whole process.
But you should really use Control.Concurrent.threadWaitRead.

Note that:
1) when connection completes successfully, the socket descriptor becomes
2) in case of errors, the socket descriptor becomes both writable and

As pointed in "UNIX Network Programming" (third edition):
nonblocking connects are one of the most nonportable areas of network 

You may check the Twisted framework (if you know Python) to see a sample 

Manlio Perillo
> It doesn't depend from being safe/unsafe FFI-ed, does it?
> Belka

More information about the Haskell-Cafe mailing list