Exemplo n.º 1
0
 private void OnRequest(object sender, FactoryRequestEventArgs e)
 {
     RequestReceived(this, e);
 }
Exemplo n.º 2
0
 private void OnRequest(object sender, FactoryRequestEventArgs e)
 {
   RequestReceived(this, e);
 }
Exemplo n.º 3
0
    /// <summary>
    /// 消息解析器解析出一个请求消息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void OnRequest(object sender, FactoryRequestEventArgs e)
    {
      _context = this;

      // 根据请求消息内容生成响应消息
      Response = HttpFactory.Current.Get<IResponse>(this, e.Request);
      Logger.Debug("Received '" + e.Request.Method + " " + e.Request.Uri.PathAndQuery + "' from " + Socket.RemoteEndPoint);

      // 如果请求连接中设置了保活
      if (e.Request.Connection != null && e.Request.Connection.Type == ConnectionType.KeepAlive)
      {
        Response.Add(new StringHeader("Keep-Alive", "timeout=5, max=100"));

        // 刷新计时器
        if (_keepAlive != null)
          _keepAlive.Change(_keepAliveTimeout, _keepAliveTimeout);
      }

      // 记录请求消息
      Request = e.Request;

      // 通知处理请求
      CurrentRequestReceived(this, new RequestEventArgs(this, e.Request, Response));
      RequestReceived(this, new RequestEventArgs(this, e.Request, Response));

      // 如果请求连接中设置了保活,记录请求处理的超时时间
      if (Response.Connection.Type == ConnectionType.KeepAlive)
      {
        if (_keepAlive == null)
          _keepAlive = new Timer(OnKeepAliveTimeout, null, _keepAliveTimeout, _keepAliveTimeout);
      }

      // 通知请求处理完毕
      RequestCompleted(this, new RequestEventArgs(this, e.Request, Response));
      CurrentRequestCompleted(this, new RequestEventArgs(this, e.Request, Response));
    }