]> git.sesse.net Git - cubemap/blobdiff - server.cpp
Small microoptimization in do_work().
[cubemap] / server.cpp
index 949d6a4d6958eff742c6c75783ed18f48d7f49c2..a11b55f72e6f62d7e1401925e4c113a58df9ceec 100644 (file)
@@ -153,7 +153,13 @@ void Server::add_client(int sock)
 void Server::add_client_from_serialized(const ClientProto &client)
 {
        MutexLock lock(&mutex);
-       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()];
 
@@ -357,6 +363,8 @@ sending_data_again:
                                client->sock,
                                (long long int)(bytes_to_send - 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;
                        bytes_to_send = stream->backlog_size;
                }
 
@@ -386,12 +394,13 @@ sending_data_again:
                        return;
                }
                client->stream_pos += ret;
+               client->bytes_sent += ret;
 
                if (client->stream_pos == stream->bytes_received) {
                        // 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);
-               } else if (more_data) {
+               } else if (more_data && ret == bytes_to_send) {
                        goto sending_data_again;
                }
                break;