Пример #1
0
 protected override void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             protocol?.Dispose();
         }
         base.Dispose(disposing);
     }
     //dispose unmanaged resources
     disposed = true;
 }
Пример #2
0
        /// <summary>
        /// Dispose resources. Override this method in derived classes. Unmanaged resources should always be released
        /// when this method is called. Managed resources may only be disposed of if disposeManagedResources is true.
        /// </summary>
        /// <param name="disposeManagedResources">A value which indicates whether managed resources may be disposed of.</param>
        protected override void DisposeResources(bool disposeManagedResources)
        {
            // we do not hold unmanaged resources
            if (!disposeManagedResources)
            {
                return;
            }

            // dispose resources
            state.Dispose();
            log.Dispose();
            protocol.Dispose();
        }
Пример #3
0
        private void CloseClientSocket(Socket socket, SocketAsyncEventArgs args)
        {
            // Do a shutdown before you close the socket
            try
            {
                socket.Shutdown(SocketShutdown.Both);
                _protocol.Dispose(args);
            }
            catch (Exception)
            {
                // ignored
            }

            // This method closes the socket and releases all resources, both managed and unmanaged.
            socket.Close();

            _monitor.CloseClient();
        }
Пример #4
0
        public virtual void Dispose()
        {
            if (!disposed)
            {
                disposing = true;
                Disconnect("Dispose");

                allDone.Close();
                buffer        = null;
                localAddress  = null;
                remoteAddress = null;

                ProtocolChange -= OnProtocolChanged;
                // ConnectionStatusChange need to be removed after calling Disconnect as Disconnect fires ConnectionStatusChange;
                ConnectionStatusChange -= OnConnectionStatusChanged;
#if !COMPACT_FRAMEWORK
                SecureUpdate -= OnSecureUpdate;
#endif
                if (socket != null)
                {
                    socket.Close();
                    socket = null;
                }
                if (protocol != null)
                {
                    protocol.Dispose();
                    protocol = null;
                }
#if !COMPACT_FRAMEWORK
                if (secStream != null)
                {
                    secStream.Dispose();
                    secStream = null;
                }
#endif
                GC.SuppressFinalize(this);
                disposed  = true;
                disposing = false;
            }
        }
Пример #5
0
        internal static void ProcessQueue()
        {
            ProtocolEventInfo protocolEvent;

            while (protocolEvents.TryDequeue(out protocolEvent))
            {
                if (HTTPManager.Logger.Level == Loglevels.All)
                {
                    HTTPManager.Logger.Information("ProtocolEventHelper", "Processing protocol event: " + protocolEvent.ToString());
                }

                if (OnEvent != null)
                {
                    try
                    {
                        OnEvent(protocolEvent);
                    }
                    catch (Exception ex)
                    {
                        HTTPManager.Logger.Exception("ProtocolEventHelper", "ProcessQueue", ex);
                    }
                }

                IProtocol protocol = protocolEvent.Source;

                protocol.HandleEvents();

                if (protocol.IsClosed)
                {
                    ActiveProtocols.Remove(protocol);

                    HostManager.GetHost(protocol.ConnectionKey.Host)
                    .GetHostDefinition(protocol.ConnectionKey.Connection)
                    .DecreaseActiveConnectionCount();

                    protocol.Dispose();
                }
            }
        }