[Haskell-cafe] Data.Binary hanging when used with socket - feature?

Paul Brenman paul.brenman at gmail.com
Sun Jun 17 19:40:13 CEST 2012


I'm using the 0.5.1.0 binary package (i.e. Data.Binary/Data.Binary.Get) to
encode/decode a lazy bytestring. Unfortunately, decode/get are hanging,
possibly due to the underlying chunking logic in Data.Binary.Get.

The lazy bytestring is being populated from a socket (via "socketTohandle
sock ReadWriteMode . hGetContents"). Periodically, encoded data structures
are received from the socket. When the encoded data structure happens to
end exactly on a chunk boundary, and in my specific case the final encoded
item is an Int(64), the Data.Binary.Get.getBytes function wants to force
the next chunk to be read into the lazy bytestring before returning the
decoded item (see comment in file at line 333 that reads "forces the next
chunk before this one is returned"). Unfortunately, since the socket is not
yet ready to send anything the call to decode/get hangs. The assumption
seems to be that the lazy bytestring isn't populated from a source that can
potentially block.

Is this reading correct?

If so, are there any workarounds?

Appreciate any advice - production code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120617/d3941ad7/attachment.htm>


More information about the Haskell-Cafe mailing list