public void Close()
 {
     _shutdown = true;
     if (socket != null)
     {
         if (_idleTimer != null)
         {
             _idleTimer.Dispose();
             _idleTimer = null;
         }
         try
         {
             socket.Disconnect(false);
             socket.Close();
             socket = null;
         }
         catch (Exception e) { }
         try
         {
             _inputStream.Dispose();
             _inputStream = null;
         }
         catch (Exception e)
         {
             Logger.Error(e.Message);
         }
     }
     _buffer = null;
     _parser.RequestLineRecieved = null;
     _parser.Clear();
     if (!_disposed)
         _listener.ClearConnection(this);
 }
 internal void Start(Socket s, PortListener listener, X509Certificate cert,long id)
 {
     _idleTimer = new Timer(new TimerCallback(_IdleTimeout), null, _CONNECTION_IDLE_TIMEOUT, Timeout.Infinite);
     _rand = new MT19937(id);
     _buffer = new byte[_BUFFER_SIZE];
     _requests = new List<HttpRequest>();
     _parser.RequestLineRecieved = _RequestLineRecieved;
     _shutdown = false;
     _id = id;
     socket = s;
     _listener = listener;
     _cert = cert;
     _currentConnection = this;
     if (_listener.UseSSL)
     {
         _inputStream = new WrappedStream(new SslStream(new NetworkStream(socket), true));
         _inputStream.AuthenticateAsServer(_cert);
     }
     else
         _inputStream = new WrappedStream(new NetworkStream(socket));
     _inputStream.BeginRead(_buffer, 0, _buffer.Length, new AsyncCallback(OnReceive), null);
 }