Disconnect() public method

Disconnect from client
public Disconnect ( SocketError error ) : void
error SocketError error to report in the event.
return void
コード例 #1
0
 public static void ProcessShutDown()
 {
     try
     {
         SocketError disconnectError = SocketError.HostDown;
         for (int i = 0; i < m_contexts.Count; i++)
         {
             HttpClientContext context = null;
             if (m_contexts.TryDequeue(out context))
             {
                 try
                 {
                     context.Disconnect(disconnectError);
                 }
                 catch { }
             }
         }
         m_processWaitEven.Dispose();
         m_processWaitEven = null;
     }
     catch
     {
         // We can't let this crash.
     }
 }
コード例 #2
0
        /// <summary>
        /// Send headers and body to the browser.
        /// </summary>
        /// <exception cref="InvalidOperationException">If content have already been sent.</exception>
        public void Send()
        {
            if (!_headersSent)
            {
                SendHeaders();
            }
            if (_sent)
            {
                throw new InvalidOperationException("Everyting have already been sent.");
            }
            if (Body.Length == 0)
            {
                if (Connection == ConnectionType.Close)
                {
                    _context.Disconnect(SocketError.Success);
                }
                return;
            }

            Body.Flush();
            Body.Seek(0, SeekOrigin.Begin);
            byte[] buffer    = new byte[4196];
            int    bytesRead = Body.Read(buffer, 0, 4196);

            while (bytesRead > 0)
            {
                _context.Send(buffer, 0, bytesRead);
                bytesRead = Body.Read(buffer, 0, 4196);
            }

            if (Connection == ConnectionType.Close)
            {
                _context.Disconnect(SocketError.Success);
            }

            _sent = true;
        }