Exemple #1
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose()
        {
            if (_stopped)
            {
                return;
            }
            _stopped = true;

            try {
                // get a collection of the current connections
                var connections = new ArrayRig <UdpConnection>();
                foreach (var entry in _connections.TakeItem())
                {
                    connections.Add(entry.Value);
                }
                _connections.Release();

                // dispose of each connection
                foreach (var connection in connections)
                {
                    connection.Dispose();
                }

                // dispose of the listenning socket
                AsyncSocket.Dispose();
                _socket.Dispose();
            } catch (Exception ex) {
                Log.Error("Exception disposing of UDP server connections.", ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Close this connection and remove it from the client connection pool.
        /// </summary>
        public void Dispose()
        {
            _lock.Take();
            if (_disposed)
            {
                _lock.Release();
                return;
            }
            _disposed = true;

            if (_timeoutTimer != null)
            {
                _timeoutTimer.Run = false;
                _timeoutTimer     = null;
            }

            Log.Info("Disposing of connection '" + this + "'.");

            // should the underlying socket be disposed?
            if (Server.AsyncSocket.Socket != AsyncSocket.Socket)
            {
                // yes, dispose
                AsyncSocket.Socket.Dispose();
            }

            // dispose of the async socket
            AsyncSocket.Dispose();

            // remove the client from the server collection
            Server.RemoveConnection(this);

            _message.Dispose();

            _lock.Release();
        }