@@ -19,8 +19,8 @@
1919module Streamly.Internal.Network.Socket
2020 (
2121 -- * Use a socket
22− withSocketM
23− , withSocket
22+ useSocketM
23+ , useSocket
2424
2525 -- * Read from connection
2626 , read
@@ -92,35 +92,25 @@ import qualified Streamly.Internal.Memory.Array.Types as A
9292import qualified Streamly.Prelude as S
9393import qualified Streamly.Streams.StreamD.Type as D
9494
95−-- | @'withSocketM' socket act@ runs the monadic computation @act@ passing the
96−-- socket handle to it. The handle will be closed on exit from 'withSocketM',
95+-- | @'useSocketM' socket act@ runs the monadic computation @act@ passing the
96+-- socket handle to it. The handle will be closed on exit from 'useSocketM',
9797-- whether by normal termination or by raising an exception. If closing the
9898-- handle raises an exception, then this exception will be raised by
99−-- 'withSocketM' rather than any exception raised by 'act'.
99+-- 'useSocketM' rather than any exception raised by 'act'.
100100--
101101-- @since 0.7.0
102−{-# INLINE withSocketM #-}
103−withSocketM :: (MonadMask m, MonadIO m) => Socket -> (Socket -> m ()) -> m ()
104−withSocketM sk f = do
105−-- f sk `onException` liftIO (Net.close sk)
106−-- liftIO (Net.close sk)
107− finally (liftIO (Net.close sk)) (f sk)
108−
109−-- XXX bracket performs 2x better than 'finally'. That's perhaps because of
110−-- better fusion of "A.flattenArrays . readArrays"?
111−--
112−-- withSocketS :: (IsStream t, MonadCatch m, MonadIO m) => Socket -> t m Word8
113−-- withSocketS sk = A.flattenArrays $
114−-- S.finally (liftIO (Net.close sk)) (readArrays sk)
102+{-# INLINE useSocketM #-}
103+useSocketM :: (MonadMask m, MonadIO m) => Socket -> (Socket -> m ()) -> m ()
104+useSocketM sk f = finally (liftIO (Net.close sk)) (f sk)
115105
116−-- | Like 'withSocketM' but runs a streaming computation instead of a monadic
106+-- | Like 'useSocketM' but runs a streaming computation instead of a monadic
117107-- computation.
118108--
119109-- @since 0.7.0
120−{-# INLINE withSocket #-}
121−withSocket :: (IsStream t, MonadCatch m, MonadIO m)
110+{-# INLINE useSocket #-}
111+useSocket :: (IsStream t, MonadCatch m, MonadIO m)
122112 => Socket -> (Socket -> t m a) -> t m a
123−withSocket sk = S.bracket (return sk) (liftIO . Net.close)
113+useSocket sk = S.bracket (return sk) (liftIO . Net.close)
124114
125115-------------------------------------------------------------------------------
126116-- Array IO (Input)