diff options
author | Henry Wilson <m3henry@googlemail.com> | 2019-04-10 22:07:06 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-10 23:22:20 +0200 |
commit | 7c8e7c6b6e16d4a26259a676db32d8776b99817e (patch) | |
tree | 99f134b7e66367cf11e10bc5061896eab4a3264f /src/network/core | |
parent | 3b4f224c0bc50e7248050d4bcbb6d83fd510c1cc (diff) | |
download | openttd-7c8e7c6b6e16d4a26259a676db32d8776b99817e.tar.xz |
Codechange: Use null pointer literal instead of the NULL macro
Diffstat (limited to 'src/network/core')
-rw-r--r-- | src/network/core/address.cpp | 24 | ||||
-rw-r--r-- | src/network/core/address.h | 2 | ||||
-rw-r--r-- | src/network/core/host.cpp | 8 | ||||
-rw-r--r-- | src/network/core/packet.cpp | 14 | ||||
-rw-r--r-- | src/network/core/tcp.cpp | 38 | ||||
-rw-r--r-- | src/network/core/tcp.h | 2 | ||||
-rw-r--r-- | src/network/core/tcp_admin.cpp | 2 | ||||
-rw-r--r-- | src/network/core/tcp_connect.cpp | 2 | ||||
-rw-r--r-- | src/network/core/tcp_content.cpp | 14 | ||||
-rw-r--r-- | src/network/core/tcp_game.cpp | 4 | ||||
-rw-r--r-- | src/network/core/tcp_game.h | 6 | ||||
-rw-r--r-- | src/network/core/tcp_http.cpp | 30 | ||||
-rw-r--r-- | src/network/core/tcp_http.h | 10 | ||||
-rw-r--r-- | src/network/core/tcp_listen.h | 2 | ||||
-rw-r--r-- | src/network/core/udp.cpp | 8 | ||||
-rw-r--r-- | src/network/core/udp.h | 2 |
16 files changed, 84 insertions, 84 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp index 11b5d753f..3d5bd5d64 100644 --- a/src/network/core/address.cpp +++ b/src/network/core/address.cpp @@ -25,7 +25,7 @@ const char *NetworkAddress::GetHostname() { if (StrEmpty(this->hostname) && this->address.ss_family != AF_UNSPEC) { assert(this->address_length != 0); - getnameinfo((struct sockaddr *)&this->address, this->address_length, this->hostname, sizeof(this->hostname), NULL, 0, NI_NUMERICHOST); + getnameinfo((struct sockaddr *)&this->address, this->address_length, this->hostname, sizeof(this->hostname), nullptr, 0, NI_NUMERICHOST); } return this->hostname; } @@ -131,7 +131,7 @@ const sockaddr_storage *NetworkAddress::GetAddress() * bothered to implement the specifications and allow '0' as value * that means "don't care whether it is SOCK_STREAM or SOCK_DGRAM". */ - this->Resolve(this->address.ss_family, SOCK_STREAM, AI_ADDRCONFIG, NULL, ResolveLoopProc); + this->Resolve(this->address.ss_family, SOCK_STREAM, AI_ADDRCONFIG, nullptr, ResolveLoopProc); this->resolved = true; } return &this->address; @@ -145,7 +145,7 @@ const sockaddr_storage *NetworkAddress::GetAddress() bool NetworkAddress::IsFamily(int family) { if (!this->IsResolved()) { - this->Resolve(family, SOCK_STREAM, AI_ADDRCONFIG, NULL, ResolveLoopProc); + this->Resolve(family, SOCK_STREAM, AI_ADDRCONFIG, nullptr, ResolveLoopProc); } return this->address.ss_family == family; } @@ -167,7 +167,7 @@ bool NetworkAddress::IsInNetmask(const char *netmask) /* Check for CIDR separator */ const char *chr_cidr = strchr(netmask, '/'); - if (chr_cidr != NULL) { + if (chr_cidr != nullptr) { int tmp_cidr = atoi(chr_cidr + 1); /* Invalid CIDR, treat as single host */ @@ -232,7 +232,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList * seprintf(port_name, lastof(port_name), "%u", this->GetPort()); bool reset_hostname = false; - /* Setting both hostname to NULL and port to 0 is not allowed. + /* Setting both hostname to nullptr and port to 0 is not allowed. * As port 0 means bind to any port, the other must mean that * we want to bind to 'all' IPs. */ if (StrEmpty(this->hostname) && this->address_length == 0 && this->GetPort() == 0) { @@ -242,7 +242,7 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList * strecpy(this->hostname, fam == AF_INET ? "0.0.0.0" : "::", lastof(this->hostname)); } - int e = getaddrinfo(StrEmpty(this->hostname) ? NULL : this->hostname, port_name, &hints, &ai); + int e = getaddrinfo(StrEmpty(this->hostname) ? nullptr : this->hostname, port_name, &hints, &ai); if (reset_hostname) strecpy(this->hostname, "", lastof(this->hostname)); @@ -255,18 +255,18 @@ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList * } SOCKET sock = INVALID_SOCKET; - for (struct addrinfo *runp = ai; runp != NULL; runp = runp->ai_next) { + for (struct addrinfo *runp = ai; runp != nullptr; runp = runp->ai_next) { /* When we are binding to multiple sockets, make sure we do not * connect to one with exactly the same address twice. That's * of course totally unneeded ;) */ - if (sockets != NULL) { + if (sockets != nullptr) { NetworkAddress address(runp->ai_addr, (int)runp->ai_addrlen); if (sockets->Contains(address)) continue; } sock = func(runp); if (sock == INVALID_SOCKET) continue; - if (sockets == NULL) { + if (sockets == nullptr) { this->address_length = (int)runp->ai_addrlen; assert(sizeof(this->address) >= runp->ai_addrlen); memcpy(&this->address, runp->ai_addr, runp->ai_addrlen); @@ -323,7 +323,7 @@ SOCKET NetworkAddress::Connect() { DEBUG(net, 1, "Connecting to %s", this->GetAddressAsString()); - return this->Resolve(AF_UNSPEC, SOCK_STREAM, AI_ADDRCONFIG, NULL, ConnectLoopProc); + return this->Resolve(AF_UNSPEC, SOCK_STREAM, AI_ADDRCONFIG, nullptr, ConnectLoopProc); } /** @@ -386,9 +386,9 @@ static SOCKET ListenLoopProc(addrinfo *runp) */ void NetworkAddress::Listen(int socktype, SocketList *sockets) { - assert(sockets != NULL); + assert(sockets != nullptr); - /* Setting both hostname to NULL and port to 0 is not allowed. + /* Setting both hostname to nullptr and port to 0 is not allowed. * As port 0 means bind to any port, the other must mean that * we want to bind to 'all' IPs. */ if (this->address_length == 0 && this->address.ss_family == AF_UNSPEC && diff --git a/src/network/core/address.h b/src/network/core/address.h index bd1bab676..4dd0edbc0 100644 --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -84,7 +84,7 @@ public: if (*hostname == '[') hostname++; strecpy(this->hostname, StrEmpty(hostname) ? "" : hostname, lastof(this->hostname)); char *tmp = strrchr(this->hostname, ']'); - if (tmp != NULL) *tmp = '\0'; + if (tmp != nullptr) *tmp = '\0'; memset(&this->address, 0, sizeof(this->address)); this->address.ss_family = family; diff --git a/src/network/core/host.cpp b/src/network/core/host.cpp index 2bf862a4f..98a706e2f 100644 --- a/src/network/core/host.cpp +++ b/src/network/core/host.cpp @@ -45,7 +45,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // BE return; } - char *output_pointer = NULL; + char *output_pointer = nullptr; int output_length = _netstat(sock, &output_pointer, 1); if (output_length < 0) { DEBUG(net, 0, "[core] error running _netstat"); @@ -94,9 +94,9 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // GE if (getifaddrs(&ifap) != 0) return; - for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { + for (ifa = ifap; ifa != nullptr; ifa = ifa->ifa_next) { if (!(ifa->ifa_flags & IFF_BROADCAST)) continue; - if (ifa->ifa_broadaddr == NULL) continue; + if (ifa->ifa_broadaddr == nullptr) continue; if (ifa->ifa_broadaddr->sa_family != AF_INET) continue; NetworkAddress addr(ifa->ifa_broadaddr, sizeof(sockaddr)); @@ -116,7 +116,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // Wi INTERFACE_INFO *ifo = CallocT<INTERFACE_INFO>(num); for (;;) { - if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, NULL, 0, ifo, num * sizeof(*ifo), &len, NULL, NULL) == 0) break; + if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, nullptr, 0, ifo, num * sizeof(*ifo), &len, nullptr, nullptr) == 0) break; free(ifo); if (WSAGetLastError() != WSAEFAULT) { closesocket(sock); diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp index 8cecd9bd2..fda8fdfeb 100644 --- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -24,10 +24,10 @@ */ Packet::Packet(NetworkSocketHandler *cs) { - assert(cs != NULL); + assert(cs != nullptr); this->cs = cs; - this->next = NULL; + this->next = nullptr; this->pos = 0; // We start reading from here this->size = 0; this->buffer = MallocT<byte>(SEND_MTU); @@ -39,8 +39,8 @@ Packet::Packet(NetworkSocketHandler *cs) */ Packet::Packet(PacketType type) { - this->cs = NULL; - this->next = NULL; + this->cs = nullptr; + this->next = nullptr; /* Skip the size so we can write that in before sending the packet */ this->pos = 0; @@ -62,7 +62,7 @@ Packet::~Packet() */ void Packet::PrepareToSend() { - assert(this->cs == NULL && this->next == NULL); + assert(this->cs == nullptr && this->next == nullptr); this->buffer[0] = GB(this->size, 0, 8); this->buffer[1] = GB(this->size, 8, 8); @@ -149,7 +149,7 @@ void Packet::Send_uint64(uint64 data) */ void Packet::Send_string(const char *data) { - assert(data != NULL); + assert(data != nullptr); /* The <= *is* valid due to the fact that we are comparing sizes and not the index. */ assert(this->size + strlen(data) + 1 <= SEND_MTU); while ((this->buffer[this->size++] = *data++) != '\0') {} @@ -187,7 +187,7 @@ bool Packet::CanReadFromPacket(uint bytes_to_read) */ void Packet::ReadRawPacketSize() { - assert(this->cs != NULL && this->next == NULL); + assert(this->cs != nullptr && this->next == nullptr); this->size = (PacketSize)this->buffer[0]; this->size += (PacketSize)this->buffer[1] << 8; } diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index 33b61688d..63d004a8f 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -24,7 +24,7 @@ */ NetworkTCPSocketHandler::NetworkTCPSocketHandler(SOCKET s) : NetworkSocketHandler(), - packet_queue(NULL), packet_recv(NULL), + packet_queue(nullptr), packet_recv(nullptr), sock(s), writable(false) { } @@ -43,13 +43,13 @@ NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection(bool error) NetworkSocketHandler::CloseConnection(error); /* Free all pending and partially received packets */ - while (this->packet_queue != NULL) { + while (this->packet_queue != nullptr) { Packet *p = this->packet_queue->next; delete this->packet_queue; this->packet_queue = p; } delete this->packet_recv; - this->packet_recv = NULL; + this->packet_recv = nullptr; return NETWORK_RECV_STATUS_OKAY; } @@ -63,7 +63,7 @@ NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection(bool error) void NetworkTCPSocketHandler::SendPacket(Packet *packet) { Packet *p; - assert(packet != NULL); + assert(packet != nullptr); packet->PrepareToSend(); @@ -74,12 +74,12 @@ void NetworkTCPSocketHandler::SendPacket(Packet *packet) /* Locate last packet buffered for the client */ p = this->packet_queue; - if (p == NULL) { + if (p == nullptr) { /* No packets yet */ this->packet_queue = packet; } else { /* Skip to the last packet */ - while (p->next != NULL) p = p->next; + while (p->next != nullptr) p = p->next; p->next = packet; } } @@ -104,7 +104,7 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down) if (!this->IsConnected()) return SPS_CLOSED; p = this->packet_queue; - while (p != NULL) { + while (p != nullptr) { res = send(this->sock, (const char*)p->buffer + p->pos, p->size - p->pos, 0); if (res == -1) { int err = GET_LAST_ERROR(); @@ -142,15 +142,15 @@ SendPacketsState NetworkTCPSocketHandler::SendPackets(bool closing_down) /** * Receives a packet for the given client - * @return The received packet (or NULL when it didn't receive one) + * @return The received packet (or nullptr when it didn't receive one) */ Packet *NetworkTCPSocketHandler::ReceivePacket() { ssize_t res; - if (!this->IsConnected()) return NULL; + if (!this->IsConnected()) return nullptr; - if (this->packet_recv == NULL) { + if (this->packet_recv == nullptr) { this->packet_recv = new Packet(this); } @@ -167,15 +167,15 @@ Packet *NetworkTCPSocketHandler::ReceivePacket() /* Something went wrong... (104 is connection reset by peer) */ if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); this->CloseConnection(); - return NULL; + return nullptr; } /* Connection would block, so stop for now */ - return NULL; + return nullptr; } if (res == 0) { /* Client/server has left */ this->CloseConnection(); - return NULL; + return nullptr; } p->pos += res; } @@ -185,7 +185,7 @@ Packet *NetworkTCPSocketHandler::ReceivePacket() if (p->size > SEND_MTU) { this->CloseConnection(); - return NULL; + return nullptr; } } @@ -198,22 +198,22 @@ Packet *NetworkTCPSocketHandler::ReceivePacket() /* Something went wrong... (104 is connection reset by peer) */ if (err != 104) DEBUG(net, 0, "recv failed with error %d", err); this->CloseConnection(); - return NULL; + return nullptr; } /* Connection would block */ - return NULL; + return nullptr; } if (res == 0) { /* Client/server has left */ this->CloseConnection(); - return NULL; + return nullptr; } p->pos += res; } /* Prepare for receiving a new packet */ - this->packet_recv = NULL; + this->packet_recv = nullptr; p->PrepareToRead(); return p; @@ -236,7 +236,7 @@ bool NetworkTCPSocketHandler::CanSendReceive() FD_SET(this->sock, &write_fd); tv.tv_sec = tv.tv_usec = 0; // don't block at all. - if (select(FD_SETSIZE, &read_fd, &write_fd, NULL, &tv) < 0) return false; + if (select(FD_SETSIZE, &read_fd, &write_fd, nullptr, &tv) < 0) return false; this->writable = !!FD_ISSET(this->sock, &write_fd); return FD_ISSET(this->sock, &read_fd) != 0; diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h index f9e1e00cb..451b93071 100644 --- a/src/network/core/tcp.h +++ b/src/network/core/tcp.h @@ -52,7 +52,7 @@ public: * Whether there is something pending in the send queue. * @return true when something is pending in the send queue. */ - bool HasSendQueue() { return this->packet_queue != NULL; } + bool HasSendQueue() { return this->packet_queue != nullptr; } NetworkTCPSocketHandler(SOCKET s = INVALID_SOCKET); ~NetworkTCPSocketHandler(); diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp index 226bae024..98ef0f0a0 100644 --- a/src/network/core/tcp_admin.cpp +++ b/src/network/core/tcp_admin.cpp @@ -115,7 +115,7 @@ NetworkRecvStatus NetworkAdminSocketHandler::HandlePacket(Packet *p) NetworkRecvStatus NetworkAdminSocketHandler::ReceivePackets() { Packet *p; - while ((p = this->ReceivePacket()) != NULL) { + while ((p = this->ReceivePacket()) != nullptr) { NetworkRecvStatus res = this->HandlePacket(p); if (res != NETWORK_RECV_STATUS_OKAY) return res; } diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp index d923688b1..13330108a 100644 --- a/src/network/core/tcp_connect.cpp +++ b/src/network/core/tcp_connect.cpp @@ -33,7 +33,7 @@ TCPConnecter::TCPConnecter(const NetworkAddress &address) : address(address) { _tcp_connecters.push_back(this); - if (!StartNewThread(NULL, "ottd:tcp", &TCPConnecter::ThreadEntry, this)) { + if (!StartNewThread(nullptr, "ottd:tcp", &TCPConnecter::ThreadEntry, this)) { this->Connect(); } } diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp index 8257a7252..ee8baf48e 100644 --- a/src/network/core/tcp_content.cpp +++ b/src/network/core/tcp_content.cpp @@ -47,8 +47,8 @@ void ContentInfo::TransferFrom(ContentInfo *other) free(this->dependencies); free(this->tags); memcpy(this, other, sizeof(ContentInfo)); - other->dependencies = NULL; - other->tags = NULL; + other->dependencies = nullptr; + other->tags = nullptr; } } @@ -98,11 +98,11 @@ bool ContentInfo::IsValid() const /** * Search a textfile file next to this file in the content list. * @param type The type of the textfile to search for. - * @return The filename for the textfile, \c NULL otherwise. + * @return The filename for the textfile, \c nullptr otherwise. */ const char *ContentInfo::GetTextfile(TextfileType type) const { - if (this->state == INVALID) return NULL; + if (this->state == INVALID) return nullptr; const char *tmp; switch (this->type) { default: NOT_REACHED(); @@ -120,7 +120,7 @@ const char *ContentInfo::GetTextfile(TextfileType type) const break; case CONTENT_TYPE_NEWGRF: { const GRFConfig *gc = FindGRFConfig(BSWAP32(this->unique_id), FGCM_EXACT, this->md5sum); - tmp = gc != NULL ? gc->filename : NULL; + tmp = gc != nullptr ? gc->filename : nullptr; break; } case CONTENT_TYPE_BASE_GRAPHICS: @@ -138,7 +138,7 @@ const char *ContentInfo::GetTextfile(TextfileType type) const tmp = FindScenario(this, true); break; } - if (tmp == NULL) return NULL; + if (tmp == nullptr) return nullptr; return ::GetTextfile(type, GetContentInfoSubDir(this->type), tmp); } #endif /* OPENTTD_MSU */ @@ -209,7 +209,7 @@ bool NetworkContentSocketHandler::ReceivePackets() Packet *p; static const int MAX_PACKETS_TO_RECEIVE = 42; int i = MAX_PACKETS_TO_RECEIVE; - while (--i != 0 && (p = this->ReceivePacket()) != NULL) { + while (--i != 0 && (p = this->ReceivePacket()) != nullptr) { bool cont = this->HandlePacket(p); delete p; if (!cont) return true; diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp index 2d8a74a11..6d69d10d2 100644 --- a/src/network/core/tcp_game.cpp +++ b/src/network/core/tcp_game.cpp @@ -26,7 +26,7 @@ * Create a new socket for the game connection. * @param s The socket to connect with. */ -NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s) : info(NULL), client_id(INVALID_CLIENT_ID), +NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s) : info(nullptr), client_id(INVALID_CLIENT_ID), last_frame(_frame_counter), last_frame_server(_frame_counter), last_packet(_realtime_tick) { this->sock = s; @@ -134,7 +134,7 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p) NetworkRecvStatus NetworkGameSocketHandler::ReceivePackets() { Packet *p; - while ((p = this->ReceivePacket()) != NULL) { + while ((p = this->ReceivePacket()) != nullptr) { NetworkRecvStatus res = HandlePacket(p); delete p; if (res != NETWORK_RECV_STATUS_OKAY) return res; diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h index b392cf717..eb8881adc 100644 --- a/src/network/core/tcp_game.h +++ b/src/network/core/tcp_game.h @@ -130,12 +130,12 @@ struct CommandPacket; /** A queue of CommandPackets. */ class CommandQueue { CommandPacket *first; ///< The first packet in the queue. - CommandPacket *last; ///< The last packet in the queue; only valid when first != NULL. + CommandPacket *last; ///< The last packet in the queue; only valid when first != nullptr. uint count; ///< The number of items in the queue. public: /** Initialise the command queue. */ - CommandQueue() : first(NULL), last(NULL), count(0) {} + CommandQueue() : first(nullptr), last(nullptr), count(0) {} /** Clear the command queue. */ ~CommandQueue() { this->Free(); } void Append(CommandPacket *p); @@ -537,7 +537,7 @@ public: */ inline void SetInfo(NetworkClientInfo *info) { - assert(info != NULL && this->info == NULL); + assert(info != nullptr && this->info == nullptr); this->info = info; } diff --git a/src/network/core/tcp_http.cpp b/src/network/core/tcp_http.cpp index 3e9cc8141..116232402 100644 --- a/src/network/core/tcp_http.cpp +++ b/src/network/core/tcp_http.cpp @@ -43,11 +43,11 @@ NetworkHTTPSocketHandler::NetworkHTTPSocketHandler(SOCKET s, redirect_depth(depth), sock(s) { - size_t bufferSize = strlen(url) + strlen(host) + strlen(GetNetworkRevisionString()) + (data == NULL ? 0 : strlen(data)) + 128; + size_t bufferSize = strlen(url) + strlen(host) + strlen(GetNetworkRevisionString()) + (data == nullptr ? 0 : strlen(data)) + 128; char *buffer = AllocaM(char, bufferSize); DEBUG(net, 7, "[tcp/http] requesting %s%s", host, url); - if (data != NULL) { + if (data != nullptr) { seprintf(buffer, buffer + bufferSize - 1, "POST %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s\r\n", url, host, GetNetworkRevisionString(), (int)strlen(data), data); } else { seprintf(buffer, buffer + bufferSize - 1, "GET %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\n\r\n", url, host, GetNetworkRevisionString()); @@ -108,7 +108,7 @@ static const char * const LOCATION = "Location: "; ///< Header for l int NetworkHTTPSocketHandler::HandleHeader() { assert(strlen(HTTP_1_0) == strlen(HTTP_1_1)); - assert(strstr(this->recv_buffer, END_OF_HEADER) != NULL); + assert(strstr(this->recv_buffer, END_OF_HEADER) != nullptr); /* We expect a HTTP/1.[01] reply */ if (strncmp(this->recv_buffer, HTTP_1_0, strlen(HTTP_1_0)) != 0 && @@ -122,7 +122,7 @@ int NetworkHTTPSocketHandler::HandleHeader() /* Get the length of the document to receive */ char *length = strcasestr(this->recv_buffer, CONTENT_LENGTH); - if (length == NULL) return_error("[tcp/http] missing 'content-length' header"); + if (length == nullptr) return_error("[tcp/http] missing 'content-length' header"); /* Skip the header */ length += strlen(CONTENT_LENGTH); @@ -163,7 +163,7 @@ int NetworkHTTPSocketHandler::HandleHeader() /* Redirect to other URL */ char *uri = strcasestr(this->recv_buffer, LOCATION); - if (uri == NULL) return_error("[tcp/http] missing 'location' header for redirect"); + if (uri == nullptr) return_error("[tcp/http] missing 'location' header for redirect"); uri += strlen(LOCATION); @@ -178,7 +178,7 @@ int NetworkHTTPSocketHandler::HandleHeader() if (ret != 0) return ret; /* We've relinquished control of data now. */ - this->data = NULL; + this->data = nullptr; /* Restore the header. */ *end_of_line = '\r'; @@ -195,22 +195,22 @@ int NetworkHTTPSocketHandler::HandleHeader() /* static */ int NetworkHTTPSocketHandler::Connect(char *uri, HTTPCallback *callback, const char *data, int depth) { char *hname = strstr(uri, "://"); - if (hname == NULL) return_error("[tcp/http] invalid location"); + if (hname == nullptr) return_error("[tcp/http] invalid location"); hname += 3; char *url = strchr(hname, '/'); - if (url == NULL) return_error("[tcp/http] invalid location"); + if (url == nullptr) return_error("[tcp/http] invalid location"); *url = '\0'; /* Fetch the hostname, and possible port number. */ - const char *company = NULL; - const char *port = NULL; + const char *company = nullptr; + const char *port = nullptr; ParseConnectionString(&company, &port, hname); - if (company != NULL) return_error("[tcp/http] invalid hostname"); + if (company != nullptr) return_error("[tcp/http] invalid hostname"); - NetworkAddress address(hname, port == NULL ? 80 : atoi(port)); + NetworkAddress address(hname, port == nullptr ? 80 : atoi(port)); /* Restore the URL. */ *url = '/'; @@ -246,7 +246,7 @@ int NetworkHTTPSocketHandler::Receive() if (res == 0) { if (this->recv_length != 0) return -1; - this->callback->OnReceiveData(NULL, 0); + this->callback->OnReceiveData(nullptr, 0); return 0; } @@ -261,7 +261,7 @@ int NetworkHTTPSocketHandler::Receive() char *end_of_header = strstr(this->recv_buffer, END_OF_HEADER); this->recv_buffer[end] = prev; - if (end_of_header == NULL) { + if (end_of_header == nullptr) { if (read == lengthof(this->recv_buffer)) { DEBUG(net, 0, "[tcp/http] header too big"); return -1; @@ -308,7 +308,7 @@ int NetworkHTTPSocketHandler::Receive() } tv.tv_sec = tv.tv_usec = 0; // don't block at all. - int n = select(FD_SETSIZE, &read_fd, NULL, NULL, &tv); + int n = select(FD_SETSIZE, &read_fd, nullptr, nullptr, &tv); if (n == -1) return; for (auto iter = _http_connections.begin(); iter < _http_connections.end(); /* nothing */) { diff --git a/src/network/core/tcp_http.h b/src/network/core/tcp_http.h index 5a5cdd9f2..001942ffb 100644 --- a/src/network/core/tcp_http.h +++ b/src/network/core/tcp_http.h @@ -26,9 +26,9 @@ struct HTTPCallback { /** * We're receiving data. - * @param data the received data, NULL when all data has been received. + * @param data the received data, nullptr when all data has been received. * @param length the amount of received data, 0 when all data has been received. - * @note When NULL is sent the HTTP socket handler is closed/freed. + * @note When nullptr is sent the HTTP socket handler is closed/freed. */ virtual void OnReceiveData(const char *data, size_t length) = 0; @@ -68,7 +68,7 @@ public: ~NetworkHTTPSocketHandler(); static int Connect(char *uri, HTTPCallback *callback, - const char *data = NULL, int depth = 0); + const char *data = nullptr, int depth = 0); static void HTTPReceive(); }; @@ -91,7 +91,7 @@ public: */ NetworkHTTPContentConnecter(const NetworkAddress &address, HTTPCallback *callback, const char *url, - const char *data = NULL, int depth = 0) : + const char *data = nullptr, int depth = 0) : TCPConnecter(address), callback(callback), url(stredup(url)), @@ -116,7 +116,7 @@ public: { new NetworkHTTPSocketHandler(s, this->callback, this->address.GetHostname(), this->url, this->data, this->depth); /* We've relinquished control of data now. */ - this->data = NULL; + this->data = nullptr; } }; diff --git a/src/network/core/tcp_listen.h b/src/network/core/tcp_listen.h index 5668e48b2..28b6de8ac 100644 --- a/src/network/core/tcp_listen.h +++ b/src/network/core/tcp_listen.h @@ -116,7 +116,7 @@ public: } tv.tv_sec = tv.tv_usec = 0; // don't block at all. - if (select(FD_SETSIZE, &read_fd, &write_fd, NULL, &tv) < 0) return false; + if (select(FD_SETSIZE, &read_fd, &write_fd, nullptr, &tv) < 0) return false; /* accept clients.. */ for (auto &s : sockets) { diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp index 70bb0b9f0..853b19e1a 100644 --- a/src/network/core/udp.cpp +++ b/src/network/core/udp.cpp @@ -24,12 +24,12 @@ */ NetworkUDPSocketHandler::NetworkUDPSocketHandler(NetworkAddressList *bind) { - if (bind != NULL) { + if (bind != nullptr) { for (NetworkAddress &addr : *bind) { this->bind.push_back(addr); } } else { - /* As hostname NULL and port 0/NULL don't go well when + /* As hostname nullptr and port 0/nullptr don't go well when * resolving it we need to add an address for each of * the address families we support. */ this->bind.emplace_back(nullptr, 0, AF_INET); @@ -176,13 +176,13 @@ void NetworkUDPSocketHandler::SendNetworkGameInfo(Packet *p, const NetworkGameIn uint count = 0; /* Count number of GRFs to send information about */ - for (c = info->grfconfig; c != NULL; c = c->next) { + for (c = info->grfconfig; c != nullptr; c = c->next) { if (!HasBit(c->flags, GCF_STATIC)) count++; } p->Send_uint8 (count); // Send number of GRFs /* Send actual GRF Identifications */ - for (c = info->grfconfig; c != NULL; c = c->next) { + for (c = info->grfconfig; c != nullptr; c = c->next) { if (!HasBit(c->flags, GCF_STATIC)) this->SendGRFIdentifier(p, &c->ident); } } diff --git a/src/network/core/udp.h b/src/network/core/udp.h index fab232492..9ed2705ef 100644 --- a/src/network/core/udp.h +++ b/src/network/core/udp.h @@ -229,7 +229,7 @@ protected: */ virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) { NOT_REACHED(); } public: - NetworkUDPSocketHandler(NetworkAddressList *bind = NULL); + NetworkUDPSocketHandler(NetworkAddressList *bind = nullptr); /** On destructing of this class, the socket needs to be closed */ virtual ~NetworkUDPSocketHandler() { this->Close(); } |