예제 #1
0
        void ICommunicationOwner.OnTunnelingClosing(CommunicationSubType communicationSubType, Exception exception)
        {
            switch (communicationSubType)
            {
            case CommunicationSubType.Session:
                // log
                if (exception != null)
                {
                    LogError($"Error: {exception.Message}");
                }
                LogVerbose("Closing tunneling mode.");
                break;

            case CommunicationSubType.UpStream:
            case CommunicationSubType.DownStream:
                string direction = communicationSubType.ToString();
                if (exception != null)
                {
                    // terminate the communication
                    StopCommunication();

                    // decide error severity
                    Tuple <TraceEventType, string> logContent = GetLogContent(exception);

                    // log
                    Log(logContent.Item1, $"Error in {direction} tunneling: {logContent.Item2}");
                }
                else
                {
                    // shutdown the communication of another direction
                    bool downStream = (communicationSubType == CommunicationSubType.DownStream);
                    lock (this.instanceLocker) {
                        if (this.server.IsConnecting)
                        {
                            Socket socket = this.server.Socket;
                            socket.Shutdown(downStream ? SocketShutdown.Receive : SocketShutdown.Send);
                        }
                        if (this.client != null)
                        {
                            Socket socket = this.client.Client;
                            socket.Shutdown(downStream ? SocketShutdown.Send : SocketShutdown.Receive);
                        }
                    }
                }
                LogVerbose($"Closing {communicationSubType.ToString()} tunneling.");
                break;
            }
        }
예제 #2
0
        void ICommunicationOwner.OnTunnelingStarted(CommunicationSubType communicationSubType)
        {
            // log
            switch (communicationSubType)
            {
            case CommunicationSubType.Session:
                LogVerbose("Started tunneling mode.");
                break;

            case CommunicationSubType.UpStream:
            case CommunicationSubType.DownStream:
                LogVerbose($"Started {communicationSubType.ToString()} tunneling.");
                break;
            }

            return;
        }