linyacool / WebServer

A C++ High Performance Web Server
MIT License
7.77k stars 2.1k forks source link

handleConn 为何要去掉EPOLLIN ??? #103

Open adlternative opened 4 years ago

adlternative commented 4 years ago
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 ???

linyacool commented 4 years ago

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

adlternative commented 4 years ago

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

谢谢指点!!!