@@ -268,22 +268,29 @@ void Client::write_to_pipe()
268268
269269void Client::read_from_virtual_file ()
270270{
271+ LOG (DEBUG) << " Client::read_from_virtual_file()" ;
272+ LOG (DEBUG) << " !handler_->is_done() == " << !handler_->is_done ();
273+ // LOG(DEBUG) << "handler_->has_output() == " << handler_->has_output();
274+ LOG (DEBUG) << " sendbuf_available_size() > 0 == " << (sendbuf_available_size () > 0 );
275+ int i = 0 ;
271276 char buf[4096 ];
272-
273- while (!handler_->is_done () && handler_-> has_output () && sendbuf_available_size () > 0 ) {
277+ // while (!handler_->is_done() && handler_->has_output() && sendbuf_available_size() > 0) {
278+ while (!handler_->is_done () && sendbuf_available_size () > 0 ) {
274279 size_t max = std::min (sizeof (buf), sendbuf_available_size ());
275280 size_t n = handler_->read_output (buf, max);
276- if (n == 0 ) {
281+ LOG (DEBUG) << " n == " << n;
282+ if (n == 0 && i > 5 ) {
277283 break ;
278284 }
285+ i++;
279286 sendbuf_.append (buf, n);
280287 }
281288}
282289
283290void Client::write_to_virtual_file ()
284291{
292+ LOG (DEBUG) << " Client::write_to_virtual_file()" ;
285293 char buf[4096 ];
286-
287294 while (!handler_->is_done () && handler_->needs_input () && parser_.has_body_chunk ()) {
288295 size_t n = parser_.read_next_body_chunk (buf, sizeof (buf));
289296 size_t written = handler_->write_input (buf, n);
@@ -308,17 +315,22 @@ void Client::refresh_interest_list()
308315 }
309316 else if (state_ == Client::kProcessingRequest ) {
310317 assert (handler_ != NULL );
311-
312- if (handler_->needs_input ()) {
318+ LOG (DEBUG) << " Client::kProcessingRequest " ;
319+ if (handler_->needs_input ()) { // socket
313320 want_read (sockfd_);
314321 }
315- if (handler_->has_output ()) {
322+ // if (handler_->has_output()) { // socket
323+ if (!sendbuf_.empty ()) {
324+ LOG (DEBUG) << " EPOLLOUT on socket fd" ;
316325 want_write (sockfd_);
317326 }
318- if (pipefd_[0 ] != -1 && handler_->has_output ()) {
327+ if (pipefd_[0 ] != -1 ) {
328+ // && handler_->has_output()) {
329+ LOG (DEBUG) << " Client::kProcessingRequest => pipefd_[0] != -1 {want_read}" ;
319330 want_read (pipefd_[0 ]);
320331 }
321332 if (pipefd_[1 ] != -1 && handler_->needs_input ()) {
333+ LOG (DEBUG) << " Client::kProcessingRequest => pipefd_[0] != -1 {want_write}" ;
322334 want_write (pipefd_[1 ]);
323335 }
324336 }
@@ -328,6 +340,5 @@ void Client::refresh_interest_list()
328340 else {
329341 assert (0 && " UNREACHABLE" );
330342 }
331-
332343 epoll_fds_[sockfd_] |= EPOLLRDHUP;
333344}
0 commit comments