: stream_id(serialized.stream_id()),
header(serialized.header()),
data_fd(make_tempfile(serialized.data())),
: stream_id(serialized.stream_id()),
header(serialized.header()),
data_fd(make_tempfile(serialized.data())),
- data_size(serialized.data_size()),
+ backlog_size(serialized.backlog_size()),
+ bytes_received(serialized.bytes_received()),
void Server::add_data(const string &stream_id, const char *data, ssize_t bytes)
{
Stream *stream = find_stream(stream_id);
void Server::add_data(const string &stream_id, const char *data, ssize_t bytes)
{
Stream *stream = find_stream(stream_id);
while (to_copy > 0) {
int ret = pwrite(stream->data_fd, data, to_copy, pos);
if (ret == -1 && errno == EINTR) {
while (to_copy > 0) {
int ret = pwrite(stream->data_fd, data, to_copy, pos);
if (ret == -1 && errno == EINTR) {
// but we'll start sending immediately as we get data.
// This is postcondition #3.
client->state = Client::SENDING_DATA;
// but we'll start sending immediately as we get data.
// This is postcondition #3.
client->state = Client::SENDING_DATA;
// See if there's some data we've lost. Ideally, we should drop to a block boundary,
// but resync will be the mux's problem.
Stream *stream = client->stream;
// See if there's some data we've lost. Ideally, we should drop to a block boundary,
// but resync will be the mux's problem.
Stream *stream = client->stream;
fprintf(stderr, "WARNING: fd %d lost %lld bytes, maybe too slow connection\n",
client->sock,
fprintf(stderr, "WARNING: fd %d lost %lld bytes, maybe too slow connection\n",
client->sock,
- (long long int)(bytes_to_send - BACKLOG_SIZE));
- client->bytes_sent = stream->data_size - BACKLOG_SIZE;
- bytes_to_send = BACKLOG_SIZE;
+ (long long int)(bytes_to_send - stream->backlog_size));
+ client->bytes_sent = stream->bytes_received - stream->backlog_size;
+ bytes_to_send = stream->backlog_size;
- if ((client->bytes_sent % BACKLOG_SIZE) + bytes_to_send > BACKLOG_SIZE) {
- bytes_to_send = BACKLOG_SIZE - (client->bytes_sent % BACKLOG_SIZE);
+ if ((client->bytes_sent % stream->backlog_size) + bytes_to_send > stream->backlog_size) {
+ bytes_to_send = stream->backlog_size - (client->bytes_sent % stream->backlog_size);
ret = sendfile(client->sock, stream->data_fd, &offset, bytes_to_send);
} while (ret == -1 && errno == EINTR);
ret = sendfile(client->sock, stream->data_fd, &offset, bytes_to_send);
} while (ret == -1 && errno == EINTR);
// We don't have any more data for this client, so put it to sleep.
// This is postcondition #3.
stream->put_client_to_sleep(client);
// We don't have any more data for this client, so put it to sleep.
// This is postcondition #3.
stream->put_client_to_sleep(client);