module Control.Proxy.Network.Internal (
Timeout(..)
, recv
, send
) where
import qualified Data.ByteString as B
import qualified Control.Exception as E
import Data.Typeable (Typeable)
import qualified GHC.IO.Exception as Eg
import qualified Network.Socket as NS
import qualified Network.Socket.ByteString
data Timeout
= Timeout String
deriving (Eq, Show, Typeable)
instance E.Exception Timeout where
recv :: NS.Socket -> Int -> IO (Maybe B.ByteString)
recv sock nbytes =
E.handle (\Eg.IOError{Eg.ioe_type=Eg.ResourceVanished} -> return Nothing)
(do bs <- Network.Socket.ByteString.recv sock nbytes
if B.null bs then return Nothing
else return (Just bs))
send :: NS.Socket -> B.ByteString -> IO ()
send = Network.Socket.ByteString.sendAll