Beispiel #1
0
 /// <summary>
 /// Handles a case where the remote <see cref="Connection"/> caused a closure for the given <see cref="CloseReason"/>.
 /// </summary>
 /// <param name="closeReason">The reason for the <see cref="Connection"/> closing.</param>
 internal void ExternalClose(CloseReason closeReason)
 {
     writeStreamThread.AbortSave();
     readStreamThread.AbortSave();
     connectionClosed?.Invoke(closeReason, this);
     invokePacketThread.AbortSave();
     CloseSocket();
 }
 /// <summary>
 /// Closes this connection, but still sends the data on the stream to the bound endpoint.
 /// </summary>
 /// <param name="closeReason">The close reason.</param>
 /// <param name="callCloseEvent">If the instance should call the connectionLost event.</param>
 public void Close(CloseReason closeReason, bool callCloseEvent = false)
 {
     try
     {
         Send(new CloseRequest(closeReason));
         if (callCloseEvent)
         {
             connectionClosed?.Invoke(closeReason, this);
         }
         WriteSubWork(); //Force to write the remaining packets.
     }
     catch { }
     finally
     {
         readStreamThread.AbortSave();
         writeStreamThread.AbortSave();
         invokePacketThread.AbortSave();
         CloseSocket();
     }
 }