X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=client.cpp;h=23892ac19038406e584241a0ee462583c9447c0b;hp=4b7bcb7e0bdb7604551e4d146f3bb1a4689e358d;hb=f2e7dbf218365e3f47b942ea999796b2724ccc24;hpb=f0621e41fdb96ce1bd58e7561e0aa76345072ba3 diff --git a/client.cpp b/client.cpp index 4b7bcb7..23892ac 100644 --- a/client.cpp +++ b/client.cpp @@ -20,11 +20,6 @@ Client::Client(int sock) { request.reserve(1024); - if (clock_gettime(CLOCK_MONOTONIC_COARSE, &connect_time) == -1) { - log_perror("clock_gettime(CLOCK_MONOTONIC_COARSE)"); - return; - } - // Find the remote address, and convert it to ASCII. sockaddr_in6 addr; socklen_t addr_len = sizeof(addr); @@ -54,7 +49,7 @@ Client::Client(int sock) } } -Client::Client(const ClientProto &serialized, Stream *stream) +Client::Client(const ClientProto &serialized, const vector> &short_responses, Stream *stream) : sock(serialized.sock()), remote_addr(serialized.remote_addr()), referer(serialized.referer()), @@ -63,9 +58,9 @@ Client::Client(const ClientProto &serialized, Stream *stream) request(serialized.request()), url(serialized.url()), stream(stream), - header_or_short_response(serialized.header_or_short_response()), header_or_short_response_bytes_sent(serialized.header_or_short_response_bytes_sent()), stream_pos(serialized.stream_pos()), + stream_pos_end(serialized.stream_pos_end()), bytes_sent(serialized.bytes_sent()), bytes_lost(serialized.bytes_lost()), num_loss_events(serialized.num_loss_events()) @@ -77,6 +72,16 @@ Client::Client(const ClientProto &serialized, Stream *stream) } } } + + if (serialized.has_header_or_short_response_old()) { + // Pre-1.4.0. + header_or_short_response_holder = serialized.header_or_short_response_old(); + header_or_short_response = &header_or_short_response_holder; + } else if (serialized.has_header_or_short_response_index()) { + assert(size_t(serialized.header_or_short_response_index()) < short_responses.size()); + header_or_short_response_ref = short_responses[serialized.header_or_short_response_index()]; + header_or_short_response = header_or_short_response_ref.get(); + } connect_time.tv_sec = serialized.connect_time_sec(); connect_time.tv_nsec = serialized.connect_time_nsec(); @@ -105,7 +110,7 @@ Client::Client(const ClientProto &serialized, Stream *stream) } } -ClientProto Client::serialize() const +ClientProto Client::serialize(unordered_map *short_response_pool) const { ClientProto serialized; serialized.set_sock(sock); @@ -117,9 +122,17 @@ ClientProto Client::serialize() const serialized.set_state(state); serialized.set_request(request); serialized.set_url(url); - serialized.set_header_or_short_response(header_or_short_response); + + if (header_or_short_response != nullptr) { + // See if this string is already in the pool (deduplicated by the pointer); if not, insert it. + auto iterator_and_inserted = short_response_pool->emplace( + header_or_short_response, short_response_pool->size()); + serialized.set_header_or_short_response_index(iterator_and_inserted.first->second); + } + serialized.set_header_or_short_response_bytes_sent(serialized.header_or_short_response_bytes_sent()); serialized.set_stream_pos(stream_pos); + serialized.set_stream_pos_end(stream_pos_end); serialized.set_bytes_sent(bytes_sent); serialized.set_bytes_lost(bytes_lost); serialized.set_num_loss_events(num_loss_events);