Ejemplo n.º 1
0
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    Disconnected.Raise(this);

                    // Dispose managed resources.
                    lock (sync)
                    {
                        isSending = false;
                        sendQueue.Clear();
                    }

                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                    stream.Close();
                    Received     = null;
                    Disconnected = null;
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If disposing is false,
                // only the following code is executed.

                disposed = true;
            }
        }
Ejemplo n.º 2
0
        public void Disconnect()
        {
            if (IsDisposed)
            {
                return;
            }
            IsDisposed = true;

            if (_socket == null)
            {
                return;
            }
            Flush();

            try
            {
                _socket.Shutdown(SocketShutdown.Both);
            }
            catch
            {
            }

            _socket.Close();

            if (_recvBuffer != null)
            {
                lock (_pool)
                {
                    _pool.AddFreeSegment(_recvBuffer);
                }
            }

            if (_incompletePacketBuffer != null)
            {
                lock (_pool)
                {
                    _pool.AddFreeSegment(_incompletePacketBuffer);
                }
            }

            _incompletePacketBuffer = null;
            _incompletePacketLength = 0;
            _recvBuffer             = null;
            _isCompressionEnabled   = false;
            _socket        = null;
            _recvEventArgs = null;
            _sendEventArgs = null;

            lock (_sendQueue)
            {
                if (!_sendQueue.IsEmpty)
                {
                    _sendQueue.Clear();
                }
            }

            _circularBuffer = null;
            Disconnected.Raise();
        }
Ejemplo n.º 3
0
 private void ReceiveAsync(ReceiveState state)
 {
     //var socket = state.Socket;
     if (socket == null || !socket.Connected)
     {
         Disconnected.Raise(this);
         return;
     }
     stream.BeginRead(state.Buffer, 0, state.Buffer.Length, OnReceiveAsync, state);
 }
Ejemplo n.º 4
0
        private void Disconnect(SocketError error)
        {
            _logFile?.Write($"disconnection  -  socket_error: {error}");

            if (IsDisposed)
            {
                return;
            }

            Status     = ClientSocketStatus.Disconnected;
            IsDisposed = true;

            if (_tcpClient == null)
            {
                return;
            }

            try
            {
                _tcpClient.Close();
            }
            catch
            {
            }

            try
            {
                _netStream?.Dispose();
            }
            catch
            {
            }

            Log.Trace($"Disconnected [{(_is_login_socket ? "login socket" : "game socket")}]");

            _incompletePacketBuffer = null;
            _incompletePacketLength = 0;
            _recvBuffer             = null;
            _isCompressionEnabled   = false;
            _tcpClient      = null;
            _netStream      = null;
            _circularBuffer = null;
            _localIP        = null;
            _sendingBuffer  = null;
            _sendingCount   = 0;

            if (error != 0)
            {
                Disconnected.Raise(error);
            }

            Statistics.Reset();
        }
Ejemplo n.º 5
0
        private void Disconnect(SocketError error)
        {
            if (IsDisposed)
            {
                return;
            }

            IsDisposed = true;

            if (_socket == null)
            {
                return;
            }

            try
            {
                _socket.Shutdown(SocketShutdown.Both);
            }
            catch
            {
            }

            try
            {
                _socket.Close();
            }
            catch
            {
            }

            Log.Trace($"Disconnected [{(_is_login_socket ? "login socket" : "game socket")}]");

            _incompletePacketBuffer = null;
            _incompletePacketLength = 0;
            _recvBuffer             = null;
            _isCompressionEnabled   = false;
            _socket         = null;
            _circularBuffer = null;

            if (error != 0)
            {
                Disconnected.Raise(error);
            }

            Statistics.Reset();
        }
Ejemplo n.º 6
0
        private void Disconnect(SocketError error)
        {
            if (IsDisposed)
            {
                return;
            }

            IsDisposed = true;

            if (_socket == null)
            {
                return;
            }

            Flush();

            try
            {
                _socket.Shutdown(SocketShutdown.Both);
            }
            catch
            {
            }

            _socket.Close();

            _incompletePacketBuffer = null;
            _incompletePacketLength = 0;
            _recvBuffer             = null;
            _isCompressionEnabled   = false;
            _socket        = null;
            _recvEventArgs = null;
            _sendEventArgs = null;

            lock (_sendQueue)
            {
                if (!_sendQueue.IsEmpty)
                {
                    _sendQueue.Clear();
                }
            }

            _circularBuffer = null;
            Disconnected.Raise(error);
            Statistics.Reset();
        }
Ejemplo n.º 7
0
        private void Disconnect(SocketError error)
        {
            if (IsDisposed)
            {
                return;
            }

            IsDisposed = true;

            if (_socket == null)
            {
                return;
            }

            try
            {
                _socket.Shutdown(SocketShutdown.Both);
            }
            catch
            {
            }

            try
            {
                _socket.Close();
            }
            catch
            {
            }

            _incompletePacketBuffer = null;
            _incompletePacketLength = 0;
            _recvBuffer             = null;
            _isCompressionEnabled   = false;
            _socket         = null;
            _recvEventArgs  = null;
            _circularBuffer = null;

            if (error != 0)
            {
                Disconnected.Raise(error);
            }

            Statistics.Reset();
        }
Ejemplo n.º 8
0
        private void NetPluginDisconnectedEvent(object sender, ISledTarget target)
        {
            try
            {
                m_recvBuf.Reset();

                SetEndianness(Endian.Unknown);

                IsConnected              = false;
                IsDebugging              = false;
                IsConnecting             = false;
                m_bAuthenticated         = false;
                IsUpdateInProgress       = false;
                CurrentlyHitBp           = null;
                IsCurrentlyHitBpActualBp = false;

                Disconnected.Raise(this, new SledDebugServiceEventArgs(target));

                // Update status text
                m_connectStatus.Text = Localization.SledDisconnected;

                if (target != null)
                {
                    SledOutDevice.OutLine(
                        SledMessageType.Info,
                        SledUtil.TransSub(Localization.SledTargetDisconnectedFrom, target));
                }

                m_curTarget = null;

                // Unsubscribe from events & release resources
                m_netPlugin.ConnectedEvent          -= NetPluginConnectedEvent;
                m_netPlugin.DisconnectedEvent       -= NetPluginDisconnectedEvent;
                m_netPlugin.DataReadyEvent          -= NetPluginDataReadyEvent;
                m_netPlugin.UnHandledExceptionEvent -= NetPluginUnHandledExceptionEvent;
                m_netPlugin.Dispose();
                m_netPlugin = null;
            }
            finally
            {
                Thaw();
            }
        }
Ejemplo n.º 9
0
 public static void InvokeDisconnected()
 {
     NetworkManager.SocketClient.Status = ConnectionStatus.Offline;
     Disconnected.Raise();
 }