[Haskell-cafe] non-blocking recv from UDP socket
johan.tibell at gmail.com
Thu Aug 26 07:01:08 EDT 2010
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) ?
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe