@@ -449,6 +449,8 @@ data ControlHeader =
449
449
| CloseConnection
450
450
-- | Request to close the connection (see module description)
451
451
| CloseSocket
452
+ -- | Sent by an endpoint when it is closed.
453
+ | CloseEndPoint
452
454
-- | Message sent to probe a socket
453
455
| ProbeSocket
454
456
-- | Acknowledgement of the ProbeSocket message
@@ -747,9 +749,7 @@ apiCloseEndPoint transport evs ourEndPoint =
747
749
return closed
748
750
RemoteEndPointValid vst -> do
749
751
sched theirEndPoint $ do
750
- void $ tryIO $ sendOn vst [ encodeInt32 CloseSocket
751
- , encodeInt32 (vst ^. remoteMaxIncoming)
752
- ]
752
+ void $ tryIO $ sendOn vst [ encodeInt32 CloseEndPoint ]
753
753
-- Release probing resources if probing.
754
754
forM_ (remoteProbing vst) id
755
755
tryCloseSocket (remoteSocket vst)
@@ -929,6 +929,29 @@ handleIncomingMessages (ourEndPoint, theirEndPoint) = do
929
929
Just CloseSocket -> do
930
930
didClose <- recvInt32 sock >>= closeSocket sock
931
931
unless didClose $ go sock
932
+ Just CloseEndPoint -> do
933
+ let closeRemoteEndPoint vst = do
934
+ forM_ (remoteProbing vst) id
935
+ -- close incoming connections
936
+ forM_ (Set. elems $ vst ^. remoteIncoming) $
937
+ writeChan ourChannel . ConnectionClosed . connId
938
+ -- report the endpoint as gone if we have any outgoing
939
+ -- connections
940
+ when (vst ^. remoteOutgoing > 0 ) $ do
941
+ let code = EventConnectionLost (remoteAddress theirEndPoint)
942
+ writeChan ourChannel . ErrorEvent $
943
+ TransportError code " The remote endpoint was closed."
944
+ removeRemoteEndPoint (ourEndPoint, theirEndPoint)
945
+ modifyMVar_ theirState $ \ s -> case s of
946
+ RemoteEndPointValid vst -> do
947
+ closeRemoteEndPoint vst
948
+ return RemoteEndPointClosed
949
+ RemoteEndPointClosing resolved vst -> do
950
+ closeRemoteEndPoint vst
951
+ putMVar resolved ()
952
+ return RemoteEndPointClosed
953
+ _ -> return s
954
+ tryCloseSocket sock
932
955
Just ProbeSocket -> do
933
956
forkIO $ sendMany sock [encodeInt32 ProbeSocketAck ]
934
957
go sock
0 commit comments