@@ -57,7 +57,7 @@ module Streamly.Internal.Network.Socket
59import Control.Concurrent (threadWaitWrite, rtsSupportsBoundThreads)
59import Control.Concurrent (threadWaitWrite, rtsSupportsBoundThreads)
60−import Control.Monad.Catch (MonadCatch, onException)
60+import Control.Monad.Catch (MonadCatch, finally, MonadMask)
61import Control.Monad.IO.Class (MonadIO(..))
61import Control.Monad.IO.Class (MonadIO(..))
62import Control.Monad (when)
62import Control.Monad (when)
63import Data.Word (Word8)
63import Data.Word (Word8)
@@ -100,10 +100,11 @@ import qualified Streamly.Streams.StreamD.Type as D
101-- @since 0.7.0
101-- @since 0.7.0
102{-# INLINE withSocketM #-}
102{-# INLINE withSocketM #-}
103−withSocketM :: (MonadCatch m, MonadIO m) => Socket -> (Socket -> m ()) -> m ()
103+withSocketM :: (MonadMask m, MonadIO m) => Socket -> (Socket -> m ()) -> m ()
104withSocketM sk f = do
104withSocketM sk f = do
105− f sk `onException` liftIO (Net.close sk)
105+-- f sk `onException` liftIO (Net.close sk)
106− liftIO (Net.close sk)
106+-- liftIO (Net.close sk)
107+ finally (liftIO (Net.close sk)) (f sk)
108-- XXX bracket performs 2x better than 'finally'. That's perhaps because of
109-- XXX bracket performs 2x better than 'finally'. That's perhaps because of
109-- better fusion of "A.flattenArrays . readArrays"?
110-- better fusion of "A.flattenArrays . readArrays"?