X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=server.cpp;h=2ec2fe0c2cdc1e9b60bfa029ddbfda457eb7f873;hb=a0fe013448d188b324c00383cfd91695d9d3d076;hp=0b4d076cd9f3fd36ac71fea0508e2e58d6d478cb;hpb=26fe3ab755034ea3be8321ec0af548670f8c3bd8;p=cubemap diff --git a/server.cpp b/server.cpp index 0b4d076..2ec2fe0 100644 --- a/server.cpp +++ b/server.cpp @@ -57,8 +57,8 @@ inline bool is_earlier(timespec a, timespec b) Server::Server() { - pthread_mutex_init(&mutex, NULL); - pthread_mutex_init(&queued_clients_mutex, NULL); + pthread_mutex_init(&mutex, nullptr); + pthread_mutex_init(&queued_clients_mutex, nullptr); epoll_fd = epoll_create(1024); // Size argument is ignored. if (epoll_fd == -1) { @@ -241,7 +241,7 @@ void Server::add_client(int sock, Acceptor *acceptor) if (is_tls) { assert(tls_server_contexts.count(acceptor)); client_ptr->tls_context = tls_accept(tls_server_contexts[acceptor]); - if (client_ptr->tls_context == NULL) { + if (client_ptr->tls_context == nullptr) { log(ERROR, "tls_accept() failed"); close_client(client_ptr); return; @@ -259,7 +259,7 @@ void Server::add_client_from_serialized(const ClientProto &client) int stream_index = lookup_stream_by_url(client.url()); if (stream_index == -1) { assert(client.state() != Client::SENDING_DATA); - stream = NULL; + stream = nullptr; } else { stream = streams[stream_index].get(); } @@ -418,7 +418,7 @@ void Server::process_client(Client *client) { switch (client->state) { case Client::READING_REQUEST: { - if (client->tls_context != NULL) { + if (client->tls_context != nullptr) { if (send_pending_tls_data(client)) { // send_pending_tls_data() hit postconditions #1 or #4. return; @@ -429,7 +429,7 @@ read_request_again: // Try to read more of the request. char buf[1024]; int ret; - if (client->tls_context == NULL) { + if (client->tls_context == nullptr) { ret = read_nontls_data(client, buf, sizeof(buf)); if (ret == -1) { // read_nontls_data() hit postconditions #1 or #2. @@ -661,9 +661,9 @@ sending_data_again: bool Server::send_pending_tls_data(Client *client) { // See if there's data from the TLS library to write. - if (client->tls_data_to_send == NULL) { + if (client->tls_data_to_send == nullptr) { client->tls_data_to_send = tls_get_write_buffer(client->tls_context, &client->tls_data_left_to_send); - if (client->tls_data_to_send == NULL) { + if (client->tls_data_to_send == nullptr) { // Really no data to send. return false; } @@ -692,7 +692,7 @@ send_data_again: if (ret > 0 && size_t(ret) == client->tls_data_left_to_send) { // All data has been sent, so we don't need to go to sleep. tls_buffer_clear(client->tls_context); - client->tls_data_to_send = NULL; + client->tls_data_to_send = nullptr; return false; } @@ -790,7 +790,7 @@ read_again: void Server::skip_lost_data(Client *client) { Stream *stream = client->stream; - if (stream == NULL) { + if (stream == nullptr) { return; } size_t bytes_to_send = stream->bytes_received - client->stream_pos; @@ -939,13 +939,13 @@ void delete_from(vector *v, T elem) void Server::close_client(Client *client) { - if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, client->sock, NULL) == -1) { + if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, client->sock, nullptr) == -1) { log_perror("epoll_ctl(EPOLL_CTL_DEL)"); exit(1); } // This client could be sleeping, so we'll need to fix that. (Argh, O(n).) - if (client->stream != NULL) { + if (client->stream != nullptr) { delete_from(&client->stream->sleeping_clients, client); delete_from(&client->stream->to_process, client); }