[Haskell-cafe] non-blocking recv from UDP socket

Johan Tibell johan.tibell at gmail.com
Thu Aug 26 07:01:08 EDT 2010


Hi Thu,

On Thu, Aug 26, 2010 at 11:13 AM, Vo Minh Thu <noteed at gmail.com> wrote:

> Is is possible to get Network.Socket.ByteString.recv to be
> non-blocking (i.e. return directly even if no data is available) ?
>

Unfortunately not.


> I have tried ti use
>
>  setSocketOption sock NoDelay 1
>
> but then I get the following error:
>
>  setSocketOption: unsupported operation (Protocol not available)
>

Sockets are already set to be non-blocking and the blocking semantics are
implemented on top of non-blocking sockets using e.g. the select system
call. It's not the recv syscall that blocks but the I/O manager who blocks
you're thread because recv returned WOULD_BLOCK. The I/O manager calls
threadWaitRead upon receiving this error. threadWaitRead puts the thread to
sleep until the socket is readable (as indicated by select).

We could perhaps implement a truly non-blocking API.

Cheers,
Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100826/27f2c4cc/attachment.html


More information about the Haskell-Cafe mailing list