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) {
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;
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();
}
{
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;
// 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.
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;
}
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;
}
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;
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);
}