@@ -483,7 +483,7 @@ apiSend (ourEndPoint, theirEndPoint) connId connAlive payload =
483 -- instance if the connection is closed) with the outer exception (which is
483 -- instance if the connection is closed) with the outer exception (which is
484 -- returned by 'try' when an exception is thrown by 'sendOn', and handled
484 -- returned by 'try' when an exception is thrown by 'sendOn', and handled
485 -- by 'withRemoteState')
485 -- by 'withRemoteState')
486− liftM join . try . mapIOException sendFailed $
486+ liftM join . try . mapIOException sendFailed $
487 withRemoteState (ourEndPoint, theirEndPoint) RemoteStatePatternMatch
487 withRemoteState (ourEndPoint, theirEndPoint) RemoteStatePatternMatch
488 { caseInvalid = \_ ->
488 { caseInvalid = \_ ->
489 relyViolation (ourEndPoint, theirEndPoint) "apiSend"
489 relyViolation (ourEndPoint, theirEndPoint) "apiSend"
@@ -679,7 +679,7 @@ requestConnectionTo ourEndPoint theirAddress = go
679 findRemoteEndPoint ourEndPoint theirAddress
679 findRemoteEndPoint ourEndPoint theirAddress
681 -- If it was new, start listening for incoming messages, too
681 -- If it was new, start listening for incoming messages, too
682− when isNew . void . forkEndPointThread ourEndPoint $
682+ when isNew . void . forkEndPointThread ourEndPoint $
683 setupRemoteEndPoint (ourEndPoint, theirEndPoint)
683 setupRemoteEndPoint (ourEndPoint, theirEndPoint)
685 let theirState = remoteState theirEndPoint
685 let theirState = remoteState theirEndPoint
@@ -703,15 +703,15 @@ requestConnectionTo ourEndPoint theirAddress = go
703 -- endpoint state, and might have changed in the meantime, these changes
703 -- endpoint state, and might have changed in the meantime, these changes
704 -- won't matter.
704 -- won't matter.
705 case endPointStateSnapshot of
705 case endPointStateSnapshot of
706− RemoteEndPointInvalid err ->
706+ RemoteEndPointInvalid err ->
707 throwIO err
707 throwIO err
709− RemoteEndPointClosing resolved _ ->
709+ RemoteEndPointClosing resolved _ ->
710 -- If the remote endpoint is closing, then we need to block until
710 -- If the remote endpoint is closing, then we need to block until
711 -- this is resolved and we then try again
711 -- this is resolved and we then try again
712 readMVar resolved >> go
712 readMVar resolved >> go
714− RemoteEndPointClosed ->
714+ RemoteEndPointClosed ->
715 -- RemoteEndPointClosed indicates that a concurrent thread was in the
715 -- RemoteEndPointClosed indicates that a concurrent thread was in the
716 -- process of closing the TCP connection to the remote endpoint when
716 -- process of closing the TCP connection to the remote endpoint when
717 -- we obtained a reference to it. By INV-CLOSE we can assume that the
717 -- we obtained a reference to it. By INV-CLOSE we can assume that the
@@ -728,9 +728,9 @@ requestConnectionTo ourEndPoint theirAddress = go
728 reply <- mapIOException connectFailed $
728 reply <- mapIOException connectFailed $
729 doRemoteRequest (ourEndPoint, theirEndPoint) RequestConnectionId
729 doRemoteRequest (ourEndPoint, theirEndPoint) RequestConnectionId
730 case decodeInt32 . BS.concat $ reply of
730 case decodeInt32 . BS.concat $ reply of
731− Nothing ->
731+ Nothing ->
732 throwIO (connectFailed $ userError "Invalid integer")
732 throwIO (connectFailed $ userError "Invalid integer")
733− Just cid ->
733+ Just cid ->
734 return (theirEndPoint, cid)
734 return (theirEndPoint, cid)
736 connectFailed = TransportError ConnectFailed . show
736 connectFailed = TransportError ConnectFailed . show
@@ -772,15 +772,14 @@ findRemoteEndPoint ourEndPoint theirAddress =
772setupRemoteEndPoint :: EndPointPair -> IO ()
772setupRemoteEndPoint :: EndPointPair -> IO ()
773setupRemoteEndPoint (ourEndPoint, theirEndPoint) = do
773setupRemoteEndPoint (ourEndPoint, theirEndPoint) = do
774 didAccept <- bracketOnError (socketToEndPoint ourAddress theirAddress)
774 didAccept <- bracketOnError (socketToEndPoint ourAddress theirAddress)
775− onError $ \result ->
775+ onError $ \result ->
776 case result of
776 case result of
777 Right (sock, ConnectionRequestAccepted) -> do
777 Right (sock, ConnectionRequestAccepted) -> do
778 let vst = ValidRemoteEndPointState
778 let vst = ValidRemoteEndPointState
779 { remoteSocket = sock
779 { remoteSocket = sock
780 , _remoteOutgoing = 0
780 , _remoteOutgoing = 0
781 , _remoteIncoming = IntSet.empty
781 , _remoteIncoming = IntSet.empty
782− , sendOn = (`onException` tryCloseSocket sock)
783− . sendMany sock
782+ , sendOn = sendMany sock
785 putMVar theirState (RemoteEndPointValid vst)
784 putMVar theirState (RemoteEndPointValid vst)
786 return True
785 return True
@@ -871,7 +870,7 @@ socketToEndPoint (EndPointAddress ourAddress) theirAddress = try $ do
872-- If the local endpoint is closed, do nothing
871-- If the local endpoint is closed, do nothing
873removeRemoteEndPoint :: EndPointPair -> IO ()
872removeRemoteEndPoint :: EndPointPair -> IO ()
874−removeRemoteEndPoint (ourEndPoint, theirEndPoint) =
873+removeRemoteEndPoint (ourEndPoint, theirEndPoint) =
875 modifyMVar_ ourState $ \st -> case st of
874 modifyMVar_ ourState $ \st -> case st of
876 LocalEndPointValid vst ->
875 LocalEndPointValid vst ->
877 case vst ^. localConnectionTo theirAddress of
876 case vst ^. localConnectionTo theirAddress of
@@ -956,7 +955,7 @@ doRemoteRequest (ourEndPoint, theirEndPoint) header = do
957-- | Send a CloseSocket request if the remote endpoint is unused
956-- | Send a CloseSocket request if the remote endpoint is unused
958closeIfUnused :: EndPointPair -> IO ()
957closeIfUnused :: EndPointPair -> IO ()
959−closeIfUnused (ourEndPoint, theirEndPoint) =
958+closeIfUnused (ourEndPoint, theirEndPoint) =
960 modifyRemoteState_ (ourEndPoint, theirEndPoint) remoteStateIdentity
959 modifyRemoteState_ (ourEndPoint, theirEndPoint) remoteStateIdentity
961 { caseValid = \vst ->
960 { caseValid = \vst ->
962 if vst ^. remoteOutgoing == 0 && IntSet.null (vst ^. remoteIncoming)
961 if vst ^. remoteOutgoing == 0 && IntSet.null (vst ^. remoteIncoming)