@@ -17,7 +17,9 @@ import Foreign.C.Types
1717import Foreign.ForeignPtr (withForeignPtr)
1818import Foreign.Ptr (Ptr, castPtr, plusPtr)
1919import GHC.Conc (threadWaitRead)
20+import qualified GHC.IO.Exception as E
2021import Network.Socket (Socket)
22+import qualified System.IO.Error as E
2123#if MIN_VERSION_network(3,1,0)
2224import Network.Socket (withFdSocket)
2325#else
@@ -95,7 +97,7 @@ spell init0 siz0 recv recvBuf
9597 loop bss' siz'
9698
9799receive :: Socket -> BufferPool -> Recv
98−receive sock pool = withBufferPool pool $ \ (ptr, size) -> do
100+receive sock pool = E.handle handler $ withBufferPool pool $ \ (ptr, size) -> do
99101#if MIN_VERSION_network(3,1,0)
100102 withFdSocket sock $ \fd -> do
101103#elif MIN_VERSION_network(3,0,0)
@@ -105,6 +107,11 @@ receive sock pool = withBufferPool pool $ \ (ptr, size) -> do
105107#endif
106108 let size' = fromIntegral size
107109 fromIntegral <$> receiveloop fd ptr size'
110+ where
111+ handler :: E.IOException -> IO ByteString
112+ handler e
113+ | E.ioeGetErrorType e == E.InvalidArgument = return ""
114+ | otherwise = E.throwIO e
108115
109116receiveBuf :: Socket -> RecvBuf
110117receiveBuf sock buf0 siz0 = do