diff --git a/fastcgi.cc b/fastcgi.cc index 3230fe8..391c6b6 100644 --- a/fastcgi.cc +++ b/fastcgi.cc @@ -62,8 +62,9 @@ void FastCGIServer::Serve() { NewConn(); } else { auto conn = static_cast(events[i].data.ptr); - if (!conn->Read()) { - PCHECK(epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, conn->Sock(), nullptr) == 0); + auto fd = conn->Read(); + if (fd != -1) { + PCHECK(epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, fd, nullptr) == 0); delete conn; } } diff --git a/fastcgi_conn.cc b/fastcgi_conn.cc index 3bb8b11..603562a 100644 --- a/fastcgi_conn.cc +++ b/fastcgi_conn.cc @@ -31,9 +31,9 @@ bool FastCGIConn::Write(const std::vector& vecs) { return writev(sock_, vecs.data(), vecs.size()) == total_size; } -bool FastCGIConn::Read() { +int FastCGIConn::Read() { if (!buf_.Refill()) { - return false; + return sock_; } while (true) { @@ -102,9 +102,5 @@ bool FastCGIConn::Read() { } buf_.Consume(); - return true; -} - -int FastCGIConn::Sock() { - return sock_; + return -1; } diff --git a/fastcgi_conn.h b/fastcgi_conn.h index 1db0c47..939dfeb 100644 --- a/fastcgi_conn.h +++ b/fastcgi_conn.h @@ -14,11 +14,9 @@ class FastCGIConn { FastCGIConn(int sock, const sockaddr_in6& client_addr, const std::function)>& callback, const std::unordered_set& headers); ~FastCGIConn(); - [[nodiscard]] bool Read(); + [[nodiscard]] int Read(); [[nodiscard]] bool Write(const std::vector& vecs); - [[nodiscard]] int Sock(); - private: const int sock_; const std::function)>& callback_;