[Haskell-cafe] Re: Coming up with a better API for Network.Socket.recv

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Thu Feb 26 23:48:09 EST 2009


On 2009 Feb 26, at 23:41, Achim Schneider wrote:
> "Brandon S. Allbery KF8NH" <allbery at ece.cmu.edu> wrote:
>> On 2009 Feb 26, at 16:45, Johan Tibell wrote:
>>> definition of `recv` would look like. My current thinking is that it
>>> would mimic what C/Python/Java does and return a zero length
>>> ByteString when EOF is reached.
>>
>> Ew.  Isn't this what Maybe is for?
>>
>> Anyway, the reason recv doesn't return 0 is that if you have a
>> datagram socket, a zero-length recv is valid and doesn't mean EOF.
>>
> My man page says a retval of 0 means that "the peer has performed an
> orderly shutdown", which, in the UDP case, means that it has send a
> complete datagram... no mention of EOF. A true EOF in the sense of "no
> more data will be received" would mean unbinding the socket.

Right.  Just have to realize that a zero-length datagram packet is  
possible and even meaningful, so 0 isn't available as an EOF flag.

Anyway, the POSIX spec indicates the EOF condition as return -1 with  
errno == ECONNRESET; this should not be taken as anything but the  
limited expressiveness of a C-based API.  We should map this return to  
Nothing.

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090226/abefa3de/PGP.bin


More information about the Haskell-Cafe mailing list