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

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Sat Feb 28 15:55:29 EST 2009


On 2009 Feb 27, at 4:25, Colin Paul Adams wrote:
>> 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.
>
> Johan> I'm not sure I agree. I think using exceptions in this case  
> is fine as
> Johan> loosing the connection is indeed an exceptional condition and  
> the best
> Johan> thing a program can do in this case is probably to abort  
> processing of
> Johan> the disconnected client.
>
> I guess this depends upon how exceptional you want an exception to be.
>
> To my mind, a lost connection is a fairly normal condition (FAR to
> normal for my teleworking situation :-( ). That is, I would expect
> the exception to occur rather than not, during one run of a
> program. On that basis, I would suggest Nothing is better than an
> exception.

Actually, thinking about this, ECONNRESET can be a normal end-of- 
connection for TCP, but for UDP should never happen (on recv(); on  
send() it is surely an exception).  But at the same time, if you're  
using recv() with TCP you are probably not working with a higher level  
protocol that simply shuts down the connection when it's done:  it's  
more of a stream-oriented behavior, and the stream-oriented read()  
handles it as such.

That said I have heard of cases where recv() is used for stream  
protocols for efficiency reasons.  I don't know if the efficiency  
argument relates to anything newer than a PDP11 or VAX 750, though....

-- 
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/20090228/da5de864/PGP.bin


More information about the Haskell-Cafe mailing list