Re: Strange HTTP module behavior [PATCH]

On Fri, Feb 18, 2005 at 11:36:57PM +0100, Bjorn Bringert wrote:
John Goerzen wrote:
It turns out that Network.Socket.recv raises an EOF error when it gets back 0 bytes of data. HTTP is expecting it to return an empty list for some reason.
The below patch fixed it for me. [...]
Hmm, strange. Is that recv behavior a bug or a feature?
I don't know, but it's explicitly there whatever it is. From ghc 6.2.2: let len' = fromIntegral len if len' == 0 then ioError (mkEOFError "Network.Socket.recv") else peekCStringLen (ptr,len') It appears this change was committed to fptools in version 1.26 of Socket.hsc on July 15, 2002. http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/libraries/network/Network/... Which arguably is not what one would expect recv to do, and in any case is undocumented at http://www.haskell.org/ghc/docs/latest/html/libraries/network/Network.Socket... Still, 2002 was awhile back, so I'm still surprised nobody else noticed. -- John

John Goerzen writes:
Which arguably is not what one would expect recv to do, and in any case is undocumented at http://www.haskell.org/ghc/docs/latest/html/libraries/network/Network.Socket...
Someone correct me if I am wrong, but I think that _all_ I/O functions may throw an EOF exception -- not just recv. I have found the following wrapper to be the simplest solution to dealing with that: -- |Return 'Nothing' if the given computation throws an -- 'isEOFError' exception. handleEOF :: IO a -> IO (Maybe a) handleEOF f = catchJust ioErrors (fmap Just f) (\e -> if isEOFError e then return Nothing else ioError e) Peter

Hmmm... FWIW, I've been using a lightly modified version of Bjorn's version of HTTP in a modified HaXml parser, and it worked fine for accessing external entities. But that almost certainly did not involve receiving zero bytes. #g -- At 16:58 18/02/05 -0600, John Goerzen wrote:
On Fri, Feb 18, 2005 at 11:36:57PM +0100, Bjorn Bringert wrote:
John Goerzen wrote:
It turns out that Network.Socket.recv raises an EOF error when it gets back 0 bytes of data. HTTP is expecting it to return an empty list for some reason.
The below patch fixed it for me. [...]
Hmm, strange. Is that recv behavior a bug or a feature?
I don't know, but it's explicitly there whatever it is. From ghc 6.2.2:
let len' = fromIntegral len if len' == 0 then ioError (mkEOFError "Network.Socket.recv") else peekCStringLen (ptr,len')
It appears this change was committed to fptools in version 1.26 of Socket.hsc on July 15, 2002.
http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/libraries/network/Network/...
Which arguably is not what one would expect recv to do, and in any case is undocumented at http://www.haskell.org/ghc/docs/latest/html/libraries/network/Network.Socket...
Still, 2002 was awhile back, so I'm still surprised nobody else noticed.
-- John _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
------------ Graham Klyne For email: http://www.ninebynine.org/#Contact
participants (3)
-
Graham Klyne
-
John Goerzen
-
Peter Simons