void TcpChannel::handleRead(int cond) { _DBG("begin tcp handle read..."); struct sockaddr_in addr; int error; int fd = Socket::Accept(TcpIO_->Fd(), addr, error); if(fd < 0) { _ERR("Accept fail"); if (error == EMFILE) { close(IdleFd_); IdleFd_ = accept(TcpIO_->Fd(), NULL, NULL); close(IdleFd_); IdleFd_ = open("/dev/null", O_RDONLY | O_CLOEXEC); } return; } if(Callback_) { InetAddress iAddr; iAddr.addr = addr.sin_addr.s_addr; iAddr.saddr = inet_ntoa(addr.sin_addr); iAddr.port = addr.sin_port; Callback_(fd, iAddr); } else { close(fd); } }
void LoopThread::threadProcess() { try { bool ret = false; do { if(Loop_) { break; } Loop_.reset(new EventLoopL()); if (Callback_ && (!Callback_())) { break; } ret = Loop_->Prepare(); }while(0); Created_.set_value(ret); if(!ret) { _ERR("Loop prepare fail!"); return; } } catch(const std::exception& ex) { std::stringstream sstream; std::string result; sstream << "LoopThread thread creation failed : " << ex.what(); result = sstream.str(); Created_.set_exception(std::make_exception_ptr(Exception(result))); return; } catch (...) { Created_.set_exception(std::current_exception()); return; } Loop_->Loop(); _DBG("threadProcess end."); }