diff options
Diffstat (limited to 'src/network/core/tcp.cpp')
-rw-r--r-- | src/network/core/tcp.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
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; |