Skip to content

Commit

Permalink
fcgi/Client: detect END_REQUEST packet in _ConsumeBucketList()
Browse files Browse the repository at this point in the history
Implement the "eof" flag in the _ConsumeBucketList() return value.
  • Loading branch information
MaxKellermann committed Aug 9, 2023
1 parent 00db14f commit 2013af2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/fcgi/Client.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -874,9 +874,12 @@ FcgiClient::_ConsumeBucketList(std::size_t nbytes) noexcept
assert(response.read_state == Response::READ_BODY);
assert(!response.stderr);

if (response.available == 0)
return {0, true};

std::size_t total = 0;

while (nbytes > 0) {
while (true) {
if (content_length > 0) {
std::size_t consumed = std::min(nbytes, content_length);
if (response.available > 0 && (off_t)consumed > response.available)
Expand Down Expand Up @@ -919,6 +922,15 @@ FcgiClient::_ConsumeBucketList(std::size_t nbytes) noexcept
continue;
}

if (header.type == FCGI_END_REQUEST && !socket.IsConnected()) {
/* this condition must have been detected
already in _FillBucketList() */
assert(response.available == 0);

socket.DisposeConsumed(sizeof(header));
return {Consumed(total), true};
}

if (header.type != FCGI_STDOUT)
break;

Expand All @@ -932,7 +944,6 @@ FcgiClient::_ConsumeBucketList(std::size_t nbytes) noexcept

assert(nbytes == 0);

// TODO eof?
return {Consumed(total), false};
}

Expand Down

0 comments on commit 2013af2

Please sign in to comment.