@@ -19,8 +19,8 @@
19module Streamly.Internal.Network.Socket
19module Streamly.Internal.Network.Socket
21 -- * Use a socket
21 -- * Use a socket
22− withSocketM
22+ useSocketM
23− , withSocket
23+ , useSocket
25 -- * Read from connection
25 -- * Read from connection
@@ -92,35 +92,25 @@ import qualified Streamly.Internal.Memory.Array.Types as A
92import qualified Streamly.Prelude as S
92import qualified Streamly.Prelude as S
93import qualified Streamly.Streams.StreamD.Type as D
93import qualified Streamly.Streams.StreamD.Type as D
95−-- | @'withSocketM' socket act@ runs the monadic computation @act@ passing the
95+-- | @'useSocketM' socket act@ runs the monadic computation @act@ passing the
96−-- socket handle to it. The handle will be closed on exit from 'withSocketM',
96+-- socket handle to it. The handle will be closed on exit from 'useSocketM',
97-- whether by normal termination or by raising an exception. If closing the
97-- whether by normal termination or by raising an exception. If closing the
98-- handle raises an exception, then this exception will be raised by
98-- 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'.
101-- @since 0.7.0
101-- @since 0.7.0
102−{-# INLINE withSocketM #-}
102+{-# INLINE useSocketM #-}
103−withSocketM :: (MonadMask m, MonadIO m) => Socket -> (Socket -> m ()) -> m ()
103+useSocketM :: (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)
104+useSocketM sk f = finally (liftIO (Net.close sk)) (f sk)
109−-- XXX bracket performs 2x better than 'finally'. That's perhaps because of
110−-- better fusion of "A.flattenArrays . readArrays"?
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)
116−-- | Like 'withSocketM' but runs a streaming computation instead of a monadic
106+-- | Like 'useSocketM' but runs a streaming computation instead of a monadic
117-- computation.
107-- computation.
119-- @since 0.7.0
109-- @since 0.7.0
120−{-# INLINE withSocket #-}
110+{-# INLINE useSocket #-}
121−withSocket :: (IsStream t, MonadCatch m, MonadIO m)
111+useSocket :: (IsStream t, MonadCatch m, MonadIO m)
122 => Socket -> (Socket -> t m a) -> t m a
112 => 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)
125-------------------------------------------------------------------------------
115-------------------------------------------------------------------------------
126-- Array IO (Input)
116-- Array IO (Input)