if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_ADD)");
exit(1);
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_ADD)");
exit(1);
- Stream *stream = find_stream(client.stream_id());
+ Stream *stream;
+ map<string, Stream *>::iterator stream_it = streams.find(client.stream_id());
+ if (stream_it == streams.end()) {
+ stream = NULL;
+ } else {
+ stream = stream_it->second;
+ }
clients.insert(make_pair(client.sock(), Client(client, stream)));
Client *client_ptr = &clients[client.sock()];
clients.insert(make_pair(client.sock(), Client(client, stream)));
Client *client_ptr = &clients[client.sock()];
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, client.sock(), &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_ADD)");
exit(1);
}
if (client_ptr->state == Client::SENDING_DATA &&
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, client.sock(), &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_ADD)");
exit(1);
}
if (client_ptr->state == Client::SENDING_DATA &&
// 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",
+ log(WARNING, "fd %d lost %lld bytes, maybe too slow connection",
- client->bytes_sent = stream->bytes_received - stream->backlog_size;
+ client->stream_pos = stream->bytes_received - stream->backlog_size;
+ client->bytes_lost += bytes_to_send - stream->backlog_size;
+ ++client->num_loss_events;
- 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);
+ if ((client->stream_pos % stream->backlog_size) + bytes_to_send > stream->backlog_size) {
+ bytes_to_send = stream->backlog_size - (client->stream_pos % 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);
if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, client->sock, &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_MOD)");
if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, client->sock, &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_MOD)");
if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, client->sock, &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_MOD)");
if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, client->sock, &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_MOD)");