WebServer icon indicating copy to clipboard operation
WebServer copied to clipboard

handleConn 为何要去掉EPOLLIN ???

Open adlternative opened this issue 3 years ago • 2 comments

void HttpData::handleConn() {
  seperateTimer();
  __uint32_t &events_ = channel_->getEvents();

  if (!error_ && connectionState_ == H_CONNECTED) {
    if (events_ != 0) {
      int timeout = DEFAULT_EXPIRED_TIME;
      if (keepAlive_) timeout = DEFAULT_KEEP_ALIVE_TIME;
      if ((events_ & EPOLLIN) && (events_ & EPOLLOUT)) {
        events_ = __uint32_t(0);
        events_ |= EPOLLOUT;
      }
      // events_ |= (EPOLLET | EPOLLONESHOT);
      events_ |= EPOLLET;
      loop_->updatePoller(channel_, timeout);

    } else if (keepAlive_) {
      events_ |= (EPOLLIN | EPOLLET);
      // events_ |= (EPOLLIN | EPOLLET | EPOLLONESHOT);
      int timeout = DEFAULT_KEEP_ALIVE_TIME;
      loop_->updatePoller(channel_, timeout);
    } else {
      // cout << "close normally" << endl;
      // loop_->shutdown(channel_);
      // loop_->runInLoop(bind(&HttpData::handleClose, shared_from_this()));
      events_ |= (EPOLLIN | EPOLLET);
      // events_ |= (EPOLLIN | EPOLLET | EPOLLONESHOT);
      int timeout = (DEFAULT_KEEP_ALIVE_TIME >> 1);
      loop_->updatePoller(channel_, timeout);
    }
  } else if (!error_ && connectionState_ == H_DISCONNECTING &&
             (events_ & EPOLLOUT)) {
    events_ = (EPOLLOUT | EPOLLET);
  } else {
    // cout << "close with errors" << endl;
    loop_->runInLoop(bind(&HttpData::handleClose, shared_from_this()));
  }
}

其中if ((events_ & EPOLLIN) && (events_ & EPOLLOUT)) { events_ = __uint32_t(0); events_ |= EPOLLOUT; }为何要去掉EPOLLIN ???

adlternative avatar Sep 08 '20 14:09 adlternative

EPOLLIN 在任何情况下都可以有的,这里只是暂时不处理而已,后面epollout事件处理完了会加上的,如果你想同时处理epollin,也可以加上的,只是实现上的差别 @adlternative

linyacool avatar Sep 13 '20 11:09 linyacool

EPOLLIN 在任何情况下都可以有的,这里只是暂时不处理而已,后面epollout事件处理完了会加上的,如果你想同时处理epollin,也可以加上的,只是实现上的差别 @adlternative

谢谢指点!!!

adlternative avatar Sep 15 '20 06:09 adlternative