using namespace std;
Client::Client(int sock)
- : sock(sock),
- state(Client::READING_REQUEST),
- stream(NULL),
- header_or_short_response_bytes_sent(0),
- stream_pos(0),
- bytes_sent(0),
- bytes_lost(0),
- num_loss_events(0),
- tls_context(NULL),
- tls_data_to_send(NULL),
- tls_data_left_to_send(0),
- in_ktls_mode(false)
+ : sock(sock)
{
request.reserve(1024);
char buf[INET6_ADDRSTRLEN];
if (IN6_IS_ADDR_V4MAPPED(&addr.sin6_addr)) {
// IPv4 address, really.
- if (inet_ntop(AF_INET, &addr.sin6_addr.s6_addr32[3], buf, sizeof(buf)) == NULL) {
+ if (inet_ntop(AF_INET, &addr.sin6_addr.s6_addr32[3], buf, sizeof(buf)) == nullptr) {
log_perror("inet_ntop");
remote_addr = "";
} else {
remote_addr = buf;
}
} else {
- if (inet_ntop(addr.sin6_family, &addr.sin6_addr, buf, sizeof(buf)) == NULL) {
+ if (inet_ntop(addr.sin6_family, &addr.sin6_addr, buf, sizeof(buf)) == nullptr) {
log_perror("inet_ntop");
remote_addr = "";
} else {
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())
{
- if (stream != NULL) {
+ if (stream != nullptr) {
if (setsockopt(sock, SOL_SOCKET, SO_MAX_PACING_RATE, &stream->pacing_rate, sizeof(stream->pacing_rate)) == -1) {
if (stream->pacing_rate != ~0U) {
log_perror("setsockopt(SO_MAX_PACING_RATE)");
tls_context = tls_import_context(
reinterpret_cast<const unsigned char *>(serialized.tls_context().data()),
serialized.tls_context().size());
- if (tls_context == NULL) {
+ if (tls_context == nullptr) {
log(WARNING, "tls_import_context() failed, TLS client might not survive across restart");
} else {
tls_data_to_send = tls_get_write_buffer(tls_context, &tls_data_left_to_send);
assert(serialized.tls_output_bytes_already_consumed() <= tls_data_left_to_send);
if (serialized.tls_output_bytes_already_consumed() >= tls_data_left_to_send) {
tls_buffer_clear(tls_context);
- tls_data_to_send = NULL;
+ tls_data_to_send = nullptr;
} else {
tls_data_to_send += serialized.tls_output_bytes_already_consumed();
tls_data_left_to_send -= serialized.tls_output_bytes_already_consumed();
in_ktls_mode = serialized.in_ktls_mode();
}
} else {
- tls_context = NULL;
+ tls_context = nullptr;
}
}
serialized.set_header_or_short_response(header_or_short_response);
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);
- if (tls_context != NULL) {
+ if (tls_context != nullptr) {
bool small_version = false;
- int required_size = tls_export_context(tls_context, NULL, 0, small_version);
+ int required_size = tls_export_context(tls_context, nullptr, 0, small_version);
if (required_size <= 0) {
// Can happen if we're in the middle of the key exchange, unfortunately.
// We'll get an error fairly fast, and this client hasn't started playing
// currently serialize in-progress key exchanges.
unsigned base_tls_data_left_to_send;
const unsigned char *base_tls_data_to_send = tls_get_write_buffer(tls_context, &base_tls_data_left_to_send);
- if (base_tls_data_to_send == NULL) {
- assert(tls_data_to_send == NULL);
+ if (base_tls_data_to_send == nullptr) {
+ assert(tls_data_to_send == nullptr);
} else {
assert(tls_data_to_send + tls_data_left_to_send == base_tls_data_to_send + base_tls_data_left_to_send);
}