size_t header_or_error_bytes_sent;
// Number of bytes we are into the stream (ie., the end of last send).
- // Only relevant for SENDING_DATA.
+ // -1 means we want to send from the end of the backlog (the normal case),
+ // -2 means we want to send from the _beginning_ of the backlog.
+ // Once we go into SENDING_DATA, these negative values will be translated
+ // to real numbers.
size_t stream_pos;
// Number of bytes we've sent of data. Only relevant for SENDING_DATA.
// but we'll start sending immediately as we get data.
// This is postcondition #3.
client->state = Client::SENDING_DATA;
- client->stream_pos = client->stream->bytes_received;
+ if (client->stream_pos == size_t(-2)) {
+ client->stream_pos = std::min<size_t>(
+ client->stream->bytes_received - client->stream->backlog_size,
+ 0);
+ } else {
+ // client->stream_pos should be -1, but it might not be,
+ // if we have clients from an older version.
+ client->stream_pos = client->stream->bytes_received;
+ }
client->stream->put_client_to_sleep(client);
return;
}
return 400; // Should maybe be 405 instead?
}
- map<string, int>::const_iterator url_map_it = url_map.find(request_tokens[1]);
+ string url = request_tokens[1];
+ if (url.find("?backlog") == url.size() - 8) {
+ client->stream_pos = -2;
+ url = url.substr(0, url.size() - 8);
+ } else {
+ client->stream_pos = -1;
+ }
+
+ map<string, int>::const_iterator url_map_it = url_map.find(url);
if (url_map_it == url_map.end()) {
return 404; // Not found.
}