Example #1
0
        /// <summary>
        /// Dispose client manager and connection objects
        /// </summary>
        internal void Dispose(bool disposingIntentionally)
        {
            if (_disposed)
            {
                return;
            }
            lock (_disposeSync)
            {
                _disposed = true;

                if (_sendAsyncArgs != null)
                {
                    _sendAsyncArgs.Dispose();
                    _sendAsyncArgs = null;
                }

                if (_receiveAsyncArgs != null)
                {
                    _receiveAsyncArgs.Dispose();
                    _receiveAsyncArgs = null;
                }

                if (_enumerationPointers != null && !_cacheStopped)
                {
                    foreach (string key in _enumerationPointers.Keys)
                    {
                        _cmdExecuter.DisposeEnumerator(_enumerationPointers[key]);
                    }
                    _enumerationPointers = null;
                }

                if (_clientSocket != null)
                {
#if !NET20
                    if (_clientSocket.Connected)
                    {
                        try
                        {
                            _clientSocket.Dispose();
                        }
                        catch (SocketException e) { }
                        catch (ObjectDisposedException e) { }
                    }
#endif
                    try
                    {
                        if (_clientSocket != null)
                        {
                            _clientSocket.Close();
                        }
                    }
                    catch (Exception) { }
                    GC.SuppressFinalize(_clientSocket);
                    _clientSocket = null;
                }
                Buffer = null;
                BufferPool.CheckinBuffer(PinnedBuffer);
                BufferPool.CheckinBuffer(sendBuffer);

                PinnedBuffer = null;
                sendBuffer   = null;

                ConnectionManager.EventsAndCallbackQueue.UnRegisterSlaveQueue(_slaveId);

                if (_cmdExecuter != null)
                {
                    if (!_cacheStopped && _raiseClientDisconnectedEvent)
                    {
                        try
                        {
                            _cmdExecuter.OnClientDisconnected(ClientID, UniqueCacheID);
                        }
                        catch (Exception e)
                        {
                            if (SocketServer.Logger.IsErrorLogsEnabled)
                            {
                                SocketServer.Logger.NCacheLog.Error("ClientManager.Dispose", e.ToString());
                            }
                        }
                    }
                    if (_cmdExecuter != null)
                    {
                        _cmdExecuter.Dispose();
                        _cmdExecuter = null;
                    }
                }
                if (!disposingIntentionally)
                {
                    _clientDisposed(this.ClientID);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Dispose client manager and connection objects
        /// </summary>
        internal void Dispose(bool disposingIntentionally)
        {
            lock (_disposeSync)
            {
                _disposed = true;

                if (_enumerationPointers != null && !_cacheStopped)
                {
                    foreach (string key in _enumerationPointers.Keys)
                    {
                        _cmdExecuter.DisposeEnumerator(_enumerationPointers[key]);
                    }
                    _enumerationPointers = null;
                }


                if (_clientSocket != null)
                {
                    if (_clientSocket.Connected)
                    {
                        try
                        {
                            _clientSocket.Shutdown(SocketShutdown.Both);
                        }
                        catch (SocketException e) { /* log.Append(e.Message); */ }
                        catch (ObjectDisposedException e) { /*log.Append(e.Message);*/ }
                    }
                    if (_clientSocket != null)
                    {
                        _clientSocket.Close();
                    }
                    _clientSocket = null;
                }
                Buffer = null;
                BufferPool.CheckinBuffer(PinnedBuffer);
                BufferPool.CheckinBuffer(sendBuffer);
                PinnedBuffer = null;
                sendBuffer   = null;


                try
                {
                    lock (this)
                    {
                        while (this.PendingSendOperationQueue.Count > 0)
                        {
                            object      operation = PendingSendOperationQueue.remove();
                            SendContext opContext = (SendContext)operation;

                            if (opContext != null)
                            {
                                if (SocketServer.IsServerCounterEnabled)
                                {
                                    _connectionManager.PerfStatsColl.DecrementResponsesQueueCountStats();
                                }
                                if (SocketServer.IsServerCounterEnabled)
                                {
                                    _connectionManager.PerfStatsColl.DecrementResponsesQueueSizeStats(opContext.expectedSize);
                                }
                            }
                        }
                    }
                }
                catch (Exception e) { }

                ConnectionManager.EventsAndCallbackQueue.UnRegisterSlaveQueue(_slaveId);
                if (SocketServer.IsServerCounterEnabled)
                {
                    _connectionManager.PerfStatsColl.SetEventQueueCountStats(ConnectionManager.EventsAndCallbackQueue.Count);
                }

                if (_cmdExecuter != null)
                {
                    if (!_cacheStopped && _raiseClientDisconnectedEvent)
                    {
                        try
                        {
                            _cmdExecuter.OnClientDisconnected(ClientID, UniqueCacheID);
                        }
                        catch (Exception e)
                        {
                            if (SocketServer.Logger.IsErrorLogsEnabled)
                            {
                                SocketServer.Logger.NCacheLog.Error("ClientManager.Dispose", e.ToString());
                            }
                        }
                    }
                    if (_cmdExecuter != null)
                    {
                        _cmdExecuter.Dispose();
                        _cmdExecuter = null;
                    }
                }
                if (!disposingIntentionally)
                {
                    _clientDisposed(this.ClientID);
                }
            }
        }