newer standards prefer nullptr over NULL - this is most of them but there are others too

This commit is contained in:
DarthArgus
2016-02-15 00:07:31 -06:00
parent 6bb5137dc4
commit 03dc62efba
937 changed files with 14983 additions and 14983 deletions
@@ -96,7 +96,7 @@ void UdpConnection::Init(UdpManager *udpManager, UdpPlatformAddress destIp, int
mLastClockSyncTime = 0;
mDataHoldTime = 0;
mGettingTime = false;
mHandler = NULL;
mHandler = nullptr;
mOtherSideProtocolVersion = 0;
mNoDataTimeout = mUdpManager->mParams.noDataTimeout;
@@ -108,7 +108,7 @@ void UdpConnection::Init(UdpManager *udpManager, UdpPlatformAddress destIp, int
mIcmpErrorRetryStartStamp = 0; // when the timer started for ICMP error retry delay (gets reset on a successful packet receive)
mPortRemapRequestStartStamp = 0;
mEncryptXorBuffer = NULL;
mEncryptXorBuffer = nullptr;
mEncryptExpansionBytes = 0;
mOrderedCountOutgoing = 0;
mOrderedCountOutgoing2 = 0;
@@ -120,7 +120,7 @@ void UdpConnection::Init(UdpManager *udpManager, UdpPlatformAddress destIp, int
mConnectAttemptTimeout = 0;
mConnectionCreateTime = mUdpManager->CachedClock();
mSimulateOutgoingQueueBytes = 0;
mPassThroughData = NULL;
mPassThroughData = nullptr;
mSilentDisconnect = false;
mLastSendBin = 0;
@@ -140,7 +140,7 @@ UdpConnection::~UdpConnection()
{
UdpGuard myGuard(&mGuard);
assert(mUdpManager == NULL); // this should not be possible, since the UdpManager holds a reference to us until we are disconnected and disassociated from the manager. If you are hitting this, then odds are the application is releasing the UdpConnection object more times than it should
assert(mUdpManager == nullptr); // this should not be possible, since the UdpManager holds a reference to us until we are disconnected and disassociated from the manager. If you are hitting this, then odds are the application is releasing the UdpConnection object more times than it should
for (int i = 0; i < cReliableChannelCount; i++)
delete mChannel[i];
@@ -189,7 +189,7 @@ void UdpConnection::InternalDisconnect(int flushTimeout, DisconnectReason reason
if (mStatus == cStatusNegotiating)
flushTimeout = 0;
if (mUdpManager != NULL)
if (mUdpManager != nullptr)
{
if (flushTimeout > 0)
{
@@ -219,7 +219,7 @@ void UdpConnection::InternalDisconnect(int flushTimeout, DisconnectReason reason
}
UdpManager *holdUdpManager = mUdpManager;
mUdpManager = NULL;
mUdpManager = nullptr;
mStatus = cStatusDisconnected;
// only hold a reference to the UdpManager if it is not currently being destructed.
@@ -274,7 +274,7 @@ bool UdpConnection::Send(UdpChannel channel, const void *data, int dataLen)
if (dataLen == 0) // zero length packets are ignored
return(false);
assert(data != NULL); // can't send a null packet
assert(data != nullptr); // can't send a nullptr packet
// zero-escape application packets that start with 0
if ((*(const udp_uchar *)data) == 0)
@@ -290,7 +290,7 @@ bool UdpConnection::Send(UdpChannel channel, const LogicalPacket *packet)
{
UdpGuard myGuard(&mGuard);
assert(packet != NULL); // can't send a null packet
assert(packet != nullptr); // can't send a nullptr packet
if (mStatus != cStatusConnected) // if we are no longer connected
return(false);
@@ -337,7 +337,7 @@ bool UdpConnection::InternalSend(UdpChannel channel, const udp_uchar *data, int
{
udp_uchar *bufPtr = tempBuffer;
memcpy(bufPtr, data, dataLen);
if (data2 != NULL)
if (data2 != nullptr)
memcpy(bufPtr + dataLen, data2, dataLen2);
PhysicalSend(bufPtr, totalDataLen, true);
return(true);
@@ -350,9 +350,9 @@ bool UdpConnection::InternalSend(UdpChannel channel, const udp_uchar *data, int
bufPtr[1] = cUdpPacketOrdered;
UdpMisc::PutValue16(bufPtr + 2, (udp_ushort)(++mOrderedCountOutgoing & 0xffff));
memcpy(bufPtr + 4, data, dataLen);
if (data2 != NULL)
if (data2 != nullptr)
memcpy(bufPtr + 4 + dataLen, data2, dataLen2);
BufferedSend(bufPtr, totalDataLen + 4, NULL, 0, true);
BufferedSend(bufPtr, totalDataLen + 4, nullptr, 0, true);
return(true);
break;
}
@@ -363,7 +363,7 @@ bool UdpConnection::InternalSend(UdpChannel channel, const udp_uchar *data, int
bufPtr[1] = cUdpPacketOrdered2;
UdpMisc::PutValue16(bufPtr + 2, (udp_ushort)(++mOrderedCountOutgoing2 & 0xffff));
memcpy(bufPtr + 4, data, dataLen);
if (data2 != NULL)
if (data2 != nullptr)
memcpy(bufPtr + 4 + dataLen, data2, dataLen2);
PhysicalSend(bufPtr, totalDataLen + 4, true);
return(true);
@@ -375,7 +375,7 @@ bool UdpConnection::InternalSend(UdpChannel channel, const udp_uchar *data, int
case cUdpChannelReliable4:
{
int num = channel - cUdpChannelReliable1;
if (mChannel[num] == NULL)
if (mChannel[num] == nullptr)
mChannel[num] = new UdpReliableChannel(num, this, &mUdpManager->mParams.reliable[num]);
mChannel[num]->Send(data, dataLen, data2, dataLen2);
return(true);
@@ -410,9 +410,9 @@ void UdpConnection::GetStats(UdpConnectionStatistics *cs)
{
UdpGuard myGuard(&mGuard);
assert(cs != NULL);
assert(cs != nullptr);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return;
*cs = mConnectionStats;
@@ -428,7 +428,7 @@ void UdpConnection::GetStats(UdpConnectionStatistics *cs)
if (cs->syncTheirSent > 0)
cs->percentReceivedSuccess = (float)cs->syncOurReceived / (float)cs->syncTheirSent;
cs->reliableAveragePing = 0;
if (mChannel[0] != NULL)
if (mChannel[0] != nullptr)
cs->reliableAveragePing = mChannel[0]->GetAveragePing();
}
@@ -437,7 +437,7 @@ void UdpConnection::ProcessRawPacket(const UdpManager::PacketHistoryEntry *e)
UdpRef ref(this);
UdpGuard guard(&mGuard);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return;
if (e->mLen == 0)
@@ -572,7 +572,7 @@ void UdpConnection::ProcessRawPacket(const UdpManager::PacketHistoryEntry *e)
*decryptPtr++ = finalStart[1];
int len = (this->*(mDecryptFunction[j]))(decryptPtr, finalStart + 2, finalLen - 2);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return;
if (len == -1)
@@ -627,7 +627,7 @@ void UdpConnection::ProcessCookedPacket(const udp_uchar *data, int dataLen)
{
udp_uchar buf[256];
udp_uchar *bufPtr;
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return;
if (data[0] == 0 && dataLen > 1)
@@ -826,7 +826,7 @@ void UdpConnection::ProcessCookedPacket(const udp_uchar *data, int dataLen)
// (while processing this packet) ended up touching the packet-data and corrupting the next
// packet in the multi-sequence.
CallbackCorruptPacket(data, dataLen, cUdpCorruptionReasonMultiPacket);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return;
}
else
@@ -943,7 +943,7 @@ void UdpConnection::ProcessCookedPacket(const udp_uchar *data, int dataLen)
case cUdpPacketFragment4:
{
int num = (data[1] - cUdpPacketReliable1) % cReliableChannelCount;
if (mChannel[num] == NULL)
if (mChannel[num] == nullptr)
mChannel[num] = new UdpReliableChannel(num, this, &mUdpManager->mParams.reliable[num]);
mChannel[num]->ReliablePacket(data, dataLen);
break;
@@ -954,7 +954,7 @@ void UdpConnection::ProcessCookedPacket(const udp_uchar *data, int dataLen)
case cUdpPacketAck4:
{
int num = data[1] - cUdpPacketAck1;
if (mChannel[num] != NULL)
if (mChannel[num] != nullptr)
mChannel[num]->AckPacket(data, dataLen);
break;
}
@@ -964,7 +964,7 @@ void UdpConnection::ProcessCookedPacket(const udp_uchar *data, int dataLen)
case cUdpPacketAckAll4:
{
int num = data[1] - cUdpPacketAckAll1;
if (mChannel[num] != NULL)
if (mChannel[num] != nullptr)
mChannel[num]->AckAllPacket(data, dataLen);
break;
}
@@ -1015,7 +1015,7 @@ void UdpConnection::FlagPortUnreachable()
void UdpConnection::GiveTime(bool fromManager)
{
UdpGuard myGuard(&mGuard);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return;
if (fromManager && GetRefCount() == 2)
@@ -1115,11 +1115,11 @@ void UdpConnection::InternalGiveTime()
int totalPendingBytes = 0;
for (int i = 0; i < cReliableChannelCount; i++)
{
if (mChannel[i] != NULL)
if (mChannel[i] != nullptr)
{
totalPendingBytes += mChannel[i]->TotalPendingBytes();
int myNext = mChannel[i]->GiveTime();
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return; // giving the reliable channel time caused it to callback the application which may disconnect us
nextSchedule = udpMin(nextSchedule, myNext);
}
@@ -1208,7 +1208,7 @@ void UdpConnection::InternalGiveTime()
break;
}
if (mUdpManager != NULL)
if (mUdpManager != nullptr)
{
// safety to prevent us for scheduling ourselves for a time period that has already passed,
// as doing so could result in infinite looping in the priority queue processing.
@@ -1227,7 +1227,7 @@ int UdpConnection::TotalPendingBytes() const
int total = 0;
for (int i = 0; i < cReliableChannelCount; i++)
{
if (mChannel[i] != NULL)
if (mChannel[i] != nullptr)
total += mChannel[i]->TotalPendingBytes();
}
return(total);
@@ -1293,7 +1293,7 @@ void UdpConnection::ExpireReceiveBin()
void UdpConnection::PhysicalSend(const udp_uchar *data, int dataLen, bool appendAllowed)
{
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return;
// if we attempt to do a physical send (ie. encrypt/compress/crc a packet) while we are not connected
@@ -1322,7 +1322,7 @@ void UdpConnection::PhysicalSend(const udp_uchar *data, int dataLen, bool append
// we know this internal packet will not be a connect or confirm packet since they are sent directly to RawSend to avoid getting encrypted
*destPtr++ = finalStart[1];
int len = (this->*(mEncryptFunction[j]))(destPtr, finalStart + 2, finalLen - 2);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return;
// if this assert triggers, it means the encryption pass expanded the size of the encrypted
@@ -1393,8 +1393,8 @@ void UdpConnection::PhysicalSend(const udp_uchar *data, int dataLen, bool append
// can note where the ack was placed and replace it
udp_uchar *UdpConnection::BufferedSend(const udp_uchar *data, int dataLen, const udp_uchar *data2, int dataLen2, bool appendAllowed)
{
if (mUdpManager == NULL)
return(NULL);
if (mUdpManager == nullptr)
return(nullptr);
int used = (int)(mMultiBufferPtr - mMultiBufferData);
int actualMaxDataHoldSize = udpMin(mUdpManager->mParams.maxDataHoldSize, mConnectionConfig.maxRawPacketSize);
@@ -1409,7 +1409,7 @@ udp_uchar *UdpConnection::BufferedSend(const udp_uchar *data, int dataLen, const
FlushMultiBuffer();
// now send it (the multi-buffer is empty if you need to use it temporarily to concatenate two data chunks -- it is large enough to hold the largest raw packet)
if (data2 != NULL)
if (data2 != nullptr)
{
memcpy(mMultiBufferData, data, dataLen);
memcpy(mMultiBufferData + dataLen, data2, dataLen2);
@@ -1417,7 +1417,7 @@ udp_uchar *UdpConnection::BufferedSend(const udp_uchar *data, int dataLen, const
}
else
PhysicalSend(data, dataLen, appendAllowed);
return(NULL);
return(nullptr);
}
// if this data will not fit into buffer
@@ -1445,7 +1445,7 @@ udp_uchar *UdpConnection::BufferedSend(const udp_uchar *data, int dataLen, const
udp_uchar *placementPtr = mMultiBufferPtr;
memcpy(mMultiBufferPtr, data, dataLen);
mMultiBufferPtr += dataLen;
if (data2 != NULL)
if (data2 != nullptr)
{
memcpy(mMultiBufferPtr, data2, dataLen2);
mMultiBufferPtr += dataLen2;
@@ -1454,7 +1454,7 @@ udp_uchar *UdpConnection::BufferedSend(const udp_uchar *data, int dataLen, const
if ((mMultiBufferPtr - mMultiBufferData) >= actualMaxDataHoldSize)
{
FlushMultiBuffer();
placementPtr = NULL; // it got flushed
placementPtr = nullptr; // it got flushed
}
return(placementPtr);
}
@@ -1474,7 +1474,7 @@ void UdpConnection::FlushMultiBuffer()
// notify all the reliable channels to clear their buffered acks
for (int i = 0; i < cReliableChannelCount; i++)
{
if (mChannel[i] != NULL)
if (mChannel[i] != nullptr)
{
mChannel[i]->ClearBufferedAck();
}
@@ -1684,7 +1684,7 @@ void UdpConnection::SetupEncryptModel()
mEncryptExpansionBytes += 0;
// set up encrypt buffer (random numbers generated based on seed)
if (mEncryptXorBuffer == NULL)
if (mEncryptXorBuffer == nullptr)
{
int len = ((mUdpManager->mParams.maxRawPacketSize + 1) / 4) * 4;
mEncryptXorBuffer = new udp_uchar[len];
@@ -1718,7 +1718,7 @@ void UdpConnection::GetChannelStatus(UdpChannel channel, ChannelStatus *channelS
case cUdpChannelReliable2:
case cUdpChannelReliable3:
case cUdpChannelReliable4:
if (mChannel[channel - cUdpChannelReliable1] != NULL)
if (mChannel[channel - cUdpChannelReliable1] != nullptr)
{
mChannel[channel - cUdpChannelReliable1]->GetChannelStatus(channelStatus);
}
@@ -1763,7 +1763,7 @@ char *UdpConnection::GetDestinationString(char *buf, int bufLen) const
UdpGuard myGuard(&mGuard);
if (bufLen < 22)
return(NULL);
return(nullptr);
UdpPlatformAddress ip = GetDestinationIp();
int port = GetDestinationPort();
char hold[256];
@@ -1794,7 +1794,7 @@ void UdpConnection::OnRoutePacket(const udp_uchar *data, int dataLen)
{
UdpGuard myGuard(&mHandlerGuard);
if (mHandler != NULL)
if (mHandler != nullptr)
{
mHandler->OnRoutePacket(this, data, dataLen);
}
@@ -1814,7 +1814,7 @@ void UdpConnection::OnRoutePacket(const udp_uchar *data, int dataLen)
void UdpConnection::OnConnectComplete()
{
UdpGuard myGuard(&mHandlerGuard);
if (mHandler != NULL)
if (mHandler != nullptr)
{
mHandler->OnConnectComplete(this);
}
@@ -1823,7 +1823,7 @@ void UdpConnection::OnConnectComplete()
void UdpConnection::OnTerminated()
{
UdpGuard myGuard(&mHandlerGuard);
if (mHandler != NULL)
if (mHandler != nullptr)
{
mHandler->OnTerminated(this);
}
@@ -1832,7 +1832,7 @@ void UdpConnection::OnTerminated()
void UdpConnection::OnCrcReject(const udp_uchar *data, int dataLen)
{
UdpGuard myGuard(&mHandlerGuard);
if (mHandler != NULL)
if (mHandler != nullptr)
{
mHandler->OnCrcReject(this, data, dataLen);
}
@@ -1841,7 +1841,7 @@ void UdpConnection::OnCrcReject(const udp_uchar *data, int dataLen)
void UdpConnection::OnPacketCorrupt(const udp_uchar *data, int dataLen, UdpCorruptionReason reason)
{
UdpGuard myGuard(&mHandlerGuard);
if (mHandler != NULL)
if (mHandler != nullptr)
{
mHandler->OnPacketCorrupt(this, data, dataLen, reason);
}
@@ -153,7 +153,7 @@ class UdpConnection : public UdpGuardedRefCount, public PriorityQueueMember, pub
int ConnectionAge() const;
// returns the UdpManager object that is managing this connection
// will return NULL if the connection has been disconnected for some reason (because disconnecting severes the link to UdpManager)
// will return nullptr if the connection has been disconnected for some reason (because disconnecting severes the link to UdpManager)
UdpManager *GetUdpManager() const;
// returns the 32-bit encryption-code that was negotiated as part of the connection-establishment process.
@@ -234,9 +234,9 @@ class UdpConnection : public UdpGuardedRefCount, public PriorityQueueMember, pub
friend class UdpManager;
friend class UdpReliableChannel;
// note: if connectPacket is NULL, that means this connection object is being created to establish
// note: if connectPacket is nullptr, that means this connection object is being created to establish
// a new connection to the specified ip/port (ie. the connection starts out in cStatusNegotiating mode)
// if connectPacket is non-NULL, that menas this connection object is being created to handle an
// if connectPacket is non-nullptr, that menas this connection object is being created to handle an
// incoming connect request and it will start out in cStatusConnected mode.
UdpConnection(UdpManager *udpManager, UdpPlatformAddress destIp, int destPort, int timeout); // starts connection-establishment protocol
UdpConnection(UdpManager *udpManager, const UdpManager::PacketHistoryEntry *e); // starts already connected, replying to connection request
@@ -281,7 +281,7 @@ class UdpConnection : public UdpGuardedRefCount, public PriorityQueueMember, pub
void RawSend(const udp_uchar *data, int dataLen); // nothing happens to the data here, it is given to the udpmanager and sent out the port
void PhysicalSend(const udp_uchar *data, int dataLen, bool appendAllowed); // sends a physical packet (encrypts and adds crc bytes)
udp_uchar *BufferedSend(const udp_uchar *data, int dataLen, const udp_uchar *data2, int dataLen2, bool appendAllowed); // buffers logical packets waiting til we have more data (makes multi-packets)
bool InternalSend(UdpChannel channel, const udp_uchar *data, int dataLen, const udp_uchar *data2 = NULL, int dataLen2 = 0);
bool InternalSend(UdpChannel channel, const udp_uchar *data, int dataLen, const udp_uchar *data2 = nullptr, int dataLen2 = 0);
void InternalGiveTime();
void InternalDisconnect(int flushTimeout, DisconnectReason reason);
@@ -527,7 +527,7 @@ inline void UdpConnection::ScheduleTimeNow()
// prevents us from reprioritizing to 0, only to shortly thereafter be reprioritized to where we actually belong.
if (!mGettingTime)
{
if (mUdpManager != NULL)
if (mUdpManager != nullptr)
mUdpManager->SetPriority(this, 0);
}
}
@@ -575,7 +575,7 @@ inline int UdpConnection::LastReceive(UdpClockStamp useStamp) const
inline int UdpConnection::LastReceive() const
{
UdpGuard guard(&mGuard);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return(0);
return(mUdpManager->CachedClockElapsed(mLastReceiveTime));
}
@@ -583,7 +583,7 @@ inline int UdpConnection::LastReceive() const
inline int UdpConnection::ConnectionAge() const
{
UdpGuard guard(&mGuard);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return(0);
return(mUdpManager->CachedClockElapsed(mConnectionCreateTime));
}
@@ -591,7 +591,7 @@ inline int UdpConnection::ConnectionAge() const
inline int UdpConnection::LastSend() const
{
UdpGuard guard(&mGuard);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return(0);
return(mUdpManager->CachedClockElapsed(mLastSendTime));
}
@@ -599,7 +599,7 @@ inline int UdpConnection::LastSend() const
inline udp_ushort UdpConnection::ServerSyncStampShort() const
{
UdpGuard guard(&mGuard);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return(0);
return((udp_ushort)(mUdpManager->LocalSyncStampShort() + (mSyncTimeDelta & 0xffff)));
}
@@ -607,7 +607,7 @@ inline udp_ushort UdpConnection::ServerSyncStampShort() const
inline udp_uint UdpConnection::ServerSyncStampLong() const
{
UdpGuard guard(&mGuard);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return(0);
return(mUdpManager->LocalSyncStampLong() + mSyncTimeDelta);
}
@@ -649,7 +649,7 @@ inline UdpConnection::DisconnectReason UdpConnection::GetOtherSideDisconnectReas
inline int UdpConnection::OutgoingBytesLastSecond()
{
UdpGuard guard(&mGuard);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return(0);
ExpireSendBin();
@@ -659,7 +659,7 @@ inline int UdpConnection::OutgoingBytesLastSecond()
inline int UdpConnection::IncomingBytesLastSecond()
{
UdpGuard guard(&mGuard);
if (mUdpManager == NULL)
if (mUdpManager == nullptr)
return(0);
ExpireReceiveBin();
@@ -101,7 +101,7 @@ bool UdpPlatformDriver::SocketOpen(int port, int incomingBufferSize, int outgoin
addr_loc.sin_family = PF_INET;
addr_loc.sin_port = htons((unsigned short)port);
addr_loc.sin_addr.s_addr = htonl(INADDR_ANY);
if (bindIpAddress != NULL && bindIpAddress[0] != 0)
if (bindIpAddress != nullptr && bindIpAddress[0] != 0)
{
unsigned long address = inet_addr(bindIpAddress);
if (address != INADDR_NONE)
@@ -201,7 +201,7 @@ bool UdpPlatformDriver::GetHostByName(UdpPlatformAddress *ipAddress, const char
{
struct hostent *lphp;
lphp = gethostbyname(hostName);
if (lphp == NULL)
if (lphp == nullptr)
{
address = 0;
}
@@ -223,7 +223,7 @@ bool UdpPlatformDriver::GetSelfAddress(UdpPlatformAddress *ipAddress, bool prefe
if (gethostname(hostname, sizeof(hostname)) == 0)
{
struct hostent *entry = gethostbyname(hostname);
if (entry != NULL)
if (entry != nullptr)
{
for (int i = 0; entry->h_addr_list[i] != 0; i++)
{
@@ -273,7 +273,7 @@ UdpClockStamp UdpPlatformDriver::Clock()
UdpGuard guard(&mData->clockGuard);
struct timeval tv;
gettimeofday(&tv, NULL);
gettimeofday(&tv, nullptr);
UdpClockStamp cs = static_cast<UdpClockStamp>(tv.tv_sec) * 1000 + static_cast<UdpClockStamp>(tv.tv_usec / 1000);
cs += mData->currentCorrection;
if (cs < mData->lastStamp)
@@ -319,7 +319,7 @@ int IcmpReceive(SOCKET socket, unsigned *address, int *port)
return(-1);
struct cmsghdr *cmsg;
for(cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(&msgh, cmsg))
for(cmsg = CMSG_FIRSTHDR(&msgh); cmsg != nullptr; cmsg = CMSG_NXTHDR(&msgh, cmsg))
{
if(cmsg->cmsg_level == SOL_IP && cmsg->cmsg_type == IP_RECVERR)
{
@@ -378,7 +378,7 @@ void *GoThread(void *param)
thread->mThreadData->running = false;
thread->mThreadData->handle = 0;
thread->Release();
return(NULL);
return(nullptr);
}
UdpPlatformThreadObject::~UdpPlatformThreadObject()
@@ -435,7 +435,7 @@ char *UdpPlatformAddress::GetAddress(char *buffer, int bufferLen) const
*buffer = 0;
return(buffer);
}
assert(buffer != NULL);
assert(buffer != nullptr);
sprintf(buffer, "%d.%d.%d.%d", mData[0], mData[1], mData[2], mData[3]);
return(buffer);
}
@@ -444,7 +444,7 @@ void UdpPlatformAddress::SetAddress(const char *address)
{
for (int i = 0; i < 4; i++)
{
mData[i] = (unsigned char)strtol(address, NULL, 10);
mData[i] = (unsigned char)strtol(address, nullptr, 10);
while (*address >= '0' && *address <= '9')
address++;
if (*address != 0)
@@ -102,7 +102,7 @@ bool UdpPlatformDriver::SocketOpen(int port, int incomingBufferSize, int outgoin
addr_loc.sin_family = PF_INET;
addr_loc.sin_port = htons((unsigned short)port);
addr_loc.sin_addr.s_addr = htonl(INADDR_ANY);
if (bindIpAddress != NULL && bindIpAddress[0] != 0)
if (bindIpAddress != nullptr && bindIpAddress[0] != 0)
{
unsigned long address = inet_addr(bindIpAddress);
if (address != INADDR_NONE)
@@ -205,7 +205,7 @@ bool UdpPlatformDriver::GetHostByName(UdpPlatformAddress *ipAddress, const char
{
struct hostent *lphp;
lphp = gethostbyname(hostName);
if (lphp == NULL)
if (lphp == nullptr)
{
address = 0;
}
@@ -227,7 +227,7 @@ bool UdpPlatformDriver::GetSelfAddress(UdpPlatformAddress *ipAddress, bool prefe
if (gethostname(hostname, sizeof(hostname)) == 0)
{
struct hostent *entry = gethostbyname(hostname);
if (entry != NULL)
if (entry != nullptr)
{
for (int i = 0; entry->h_addr_list[i] != 0; i++)
{
@@ -329,10 +329,10 @@ unsigned __stdcall GoThread(void *param)
UdpPlatformThreadObject::~UdpPlatformThreadObject()
{
#ifndef UDPLIBRARY_SINGLE_THREAD
if (mThreadData->handle != NULL)
if (mThreadData->handle != nullptr)
{
CloseHandle(mThreadData->handle);
mThreadData->handle = NULL;
mThreadData->handle = nullptr;
}
#endif
delete mThreadData;
@@ -343,7 +343,7 @@ void UdpPlatformThreadObject::Start()
AddRef();
#ifndef UDPLIBRARY_SINGLE_THREAD
unsigned threadId;
mThreadData->handle = (HANDLE)_beginthreadex(NULL, 0, &GoThread, this, 0, &threadId);
mThreadData->handle = (HANDLE)_beginthreadex(nullptr, 0, &GoThread, this, 0, &threadId);
#else
GoThread(this); // run it inline in main thread (blocks til it's finished, so odds are it won't work, but they shouldn't be using it anyhow in this mode)
#endif
@@ -352,7 +352,7 @@ void UdpPlatformThreadObject::Start()
UdpPlatformThreadObject::UdpPlatformThreadObject()
{
mThreadData = new UdpPlatformThreadData;
mThreadData->handle = NULL;
mThreadData->handle = nullptr;
mThreadData->running = false;
}
@@ -389,7 +389,7 @@ char *UdpPlatformAddress::GetAddress(char *buffer, int bufferLen) const
*buffer = 0;
return(buffer);
}
assert(buffer != NULL);
assert(buffer != nullptr);
sprintf(buffer, "%d.%d.%d.%d", mData[0], mData[1], mData[2], mData[3]);
return(buffer);
}
@@ -38,11 +38,11 @@ template<typename T> class HashTable
bool Remove(T& obj, int hashValue);
void Reset(); // removes all entries from the table
T *FindFirst(int hashValue) const; // returns NULL if not found
T *FindNext(T *prevResult) const; // returns NULL if not found
T *FindFirst(int hashValue) const; // returns nullptr if not found
T *FindNext(T *prevResult) const; // returns nullptr if not found
T *WalkFirst() const; // returns NULL if not found
T *WalkNext(T *prevResult) const; // returns NULL if not found
T *WalkFirst() const; // returns nullptr if not found
T *WalkNext(T *prevResult) const; // returns nullptr if not found
void Resize(int hashSize); // the actual hash size will be rounded up to the next larger prime number (very slow, not recommended)
void GetStatistics(HashTableStatistics *stats) const;
@@ -64,7 +64,7 @@ template<typename T> class HashTable
template<typename T> HashTable<T>::HashTable(int hashSize)
{
mTable = NULL;
mTable = nullptr;
mTableSize = 0;
mEntryCount = 0;
mStatUsedSlots = 0;
@@ -84,9 +84,9 @@ template<typename T> void HashTable<T>::Insert(T& obj, int hashValue)
entry->hashValue = hashValue;
int spot = ((unsigned)hashValue) % mTableSize;
if (mTable[spot] == NULL)
if (mTable[spot] == nullptr)
{
entry->nextEntry = NULL;
entry->nextEntry = nullptr;
mTable[spot] = entry;
mStatUsedSlots++;
}
@@ -103,14 +103,14 @@ template<typename T> bool HashTable<T>::Remove(T& obj, int hashValue)
int spot = ((unsigned)hashValue) % mTableSize;
HashEntry* next = mTable[spot];
HashEntry** prev = &mTable[spot];
while (next != NULL)
while (next != nullptr)
{
if (next->obj == obj && next->hashValue == hashValue)
{
*prev = next->nextEntry;
delete next;
mEntryCount--;
if (mTable[spot] == NULL)
if (mTable[spot] == nullptr)
mStatUsedSlots--;
return(true);
break;
@@ -127,17 +127,17 @@ template<typename T> void HashTable<T>::Reset()
for (int spot = 0; spot < mTableSize; spot++)
{
HashEntry *curr = mTable[spot];
if (curr != NULL)
if (curr != nullptr)
{
mStatUsedSlots--;
while (curr != NULL)
while (curr != nullptr)
{
HashEntry *next = curr->nextEntry;
delete curr;
mEntryCount--;
curr = next;
}
mTable[spot] = NULL;
mTable[spot] = nullptr;
}
}
}
@@ -145,13 +145,13 @@ template<typename T> void HashTable<T>::Reset()
template<typename T> T *HashTable<T>::FindFirst(int hashValue) const
{
HashEntry *entry = mTable[((unsigned)hashValue) % mTableSize];
while (entry != NULL)
while (entry != nullptr)
{
if (entry->hashValue == hashValue)
return(&entry->obj);
entry = entry->nextEntry;
}
return(NULL);
return(nullptr);
}
template<typename T> T *HashTable<T>::FindNext(T *prevResult) const
@@ -159,13 +159,13 @@ template<typename T> T *HashTable<T>::FindNext(T *prevResult) const
HashEntry *entry = (HashEntry *)(((char *)prevResult) - offsetof(HashEntry, obj));
int hashValue = entry->hashValue;
entry = entry->nextEntry;
while (entry != NULL)
while (entry != nullptr)
{
if (entry->hashValue == hashValue)
return(&entry->obj);
entry = entry->nextEntry;
}
return(NULL);
return(nullptr);
}
template<typename T> T *HashTable<T>::WalkFirst() const
@@ -173,10 +173,10 @@ template<typename T> T *HashTable<T>::WalkFirst() const
for (int bucket = 0; bucket < mTableSize; bucket++)
{
HashEntry *entry = mTable[bucket];
if (entry != NULL)
if (entry != nullptr)
return(&entry->obj);
}
return(NULL);
return(nullptr);
}
template<typename T> T *HashTable<T>::WalkNext(T *prevResult) const
@@ -185,17 +185,17 @@ template<typename T> T *HashTable<T>::WalkNext(T *prevResult) const
int bucket = ((unsigned)entry->hashValue) % mTableSize;
entry = entry->nextEntry;
if (entry != NULL)
if (entry != nullptr)
return(&entry->obj);
bucket++; // go onto next bucket
for (; bucket < mTableSize; bucket++)
{
HashEntry *entry = mTable[bucket];
if (entry != NULL)
if (entry != nullptr)
return(&entry->obj);
}
return(NULL);
return(nullptr);
}
template<typename T> void HashTable<T>::Resize(int hashSize)
@@ -215,16 +215,16 @@ template<typename T> void HashTable<T>::Resize(int hashSize)
for (int i = 0; i < oldSize; i++)
{
HashEntry* next = oldTable[i];
while (next != NULL)
while (next != nullptr)
{
HashEntry* hold = next;
next = next->nextEntry;
// insert hold into new table
int spot = ((unsigned)hold->hashValue) % mTableSize;
if (mTable[spot] == NULL)
if (mTable[spot] == nullptr)
{
hold->nextEntry = NULL;
hold->nextEntry = nullptr;
mTable[spot] = hold;
mStatUsedSlots++;
}
@@ -284,11 +284,11 @@ template<typename T, typename C = T> class ObjectHashTable
bool Remove(T *obj);
void Reset(); // removes all entries from the table
T *FindFirst(int hashValue) const; // returns NULL if not found
T *FindNext(T *prevResult) const; // returns NULL if not found
T *FindFirst(int hashValue) const; // returns nullptr if not found
T *FindNext(T *prevResult) const; // returns nullptr if not found
T *WalkFirst() const; // returns NULL if not found
T *WalkNext(T *prevResult) const; // returns NULL if not found
T *WalkFirst() const; // returns nullptr if not found
T *WalkNext(T *prevResult) const; // returns nullptr if not found
void Resize(int hashSize); // the actual hash size will be rounded up to the next larger prime number (very slow, not recommended)
void GetStatistics(HashTableStatistics *stats) const;
@@ -303,7 +303,7 @@ template<typename T, typename C = T> class ObjectHashTable
template<typename T, typename C> ObjectHashTable<T, C>::ObjectHashTable(int hashSize)
{
mTable = NULL;
mTable = nullptr;
mTableSize = 0;
mEntryCount = 0;
mStatUsedSlots = 0;
@@ -320,9 +320,9 @@ template<typename T, typename C> void ObjectHashTable<T, C>::Insert(T *obj, int
static_cast<C *>(obj)->mHashValue = hashValue;
int spot = ((unsigned)hashValue) % mTableSize;
if (mTable[spot] == NULL)
if (mTable[spot] == nullptr)
{
static_cast<C *>(obj)->mHashNextEntry = NULL;
static_cast<C *>(obj)->mHashNextEntry = nullptr;
mTable[spot] = obj;
mStatUsedSlots++;
}
@@ -339,14 +339,14 @@ template<typename T, typename C> bool ObjectHashTable<T, C>::Remove(T *obj)
int spot = ((unsigned)static_cast<C *>(obj)->mHashValue) % mTableSize;
T *cur = mTable[spot];
T **prev = &mTable[spot];
while (cur != NULL)
while (cur != nullptr)
{
if (cur == obj)
{
*prev = static_cast<C *>(cur)->mHashNextEntry;
static_cast<C *>(cur)->mHashNextEntry = NULL;
static_cast<C *>(cur)->mHashNextEntry = nullptr;
mEntryCount--;
if (mTable[spot] == NULL)
if (mTable[spot] == nullptr)
mStatUsedSlots--;
return(true);
break;
@@ -368,13 +368,13 @@ template<typename T, typename C> void ObjectHashTable<T, C>::Reset()
template<typename T, typename C> T *ObjectHashTable<T, C>::FindFirst(int hashValue) const
{
T *entry = mTable[((unsigned)hashValue) % mTableSize];
while (entry != NULL)
while (entry != nullptr)
{
if (static_cast<C *>(entry)->mHashValue == hashValue)
return(entry);
entry = static_cast<C *>(entry)->mHashNextEntry;
}
return(NULL);
return(nullptr);
}
template<typename T, typename C> T *ObjectHashTable<T, C>::FindNext(T *prevResult) const
@@ -382,13 +382,13 @@ template<typename T, typename C> T *ObjectHashTable<T, C>::FindNext(T *prevResul
T *entry = prevResult;
int hashValue = static_cast<C *>(entry)->mHashValue;
entry = static_cast<C *>(entry)->mHashNextEntry;
while (entry != NULL)
while (entry != nullptr)
{
if (static_cast<C *>(entry)->mHashValue == hashValue)
return(entry);
entry = static_cast<C *>(entry)->mHashNextEntry;
}
return(NULL);
return(nullptr);
}
template<typename T, typename C> T *ObjectHashTable<T, C>::WalkFirst() const
@@ -396,10 +396,10 @@ template<typename T, typename C> T *ObjectHashTable<T, C>::WalkFirst() const
for (int bucket = 0; bucket < mTableSize; bucket++)
{
T *entry = mTable[bucket];
if (entry != NULL)
if (entry != nullptr)
return(entry);
}
return(NULL);
return(nullptr);
}
template<typename T, typename C> T *ObjectHashTable<T, C>::WalkNext(T *prevResult) const
@@ -408,17 +408,17 @@ template<typename T, typename C> T *ObjectHashTable<T, C>::WalkNext(T *prevResul
int bucket = ((unsigned)static_cast<C *>(entry)->mHashValue) % mTableSize;
entry = static_cast<C *>(entry)->mHashNextEntry;
if (entry != NULL)
if (entry != nullptr)
return(entry);
bucket++; // go onto next bucket
for (; bucket < mTableSize; bucket++)
{
entry = mTable[bucket];
if (entry != NULL)
if (entry != nullptr)
return(entry);
}
return(NULL);
return(nullptr);
}
template<typename T, typename C> void ObjectHashTable<T, C>::Resize(int hashSize)
@@ -438,16 +438,16 @@ template<typename T, typename C> void ObjectHashTable<T, C>::Resize(int hashSize
for (int i = 0; i < oldSize; i++)
{
T *cur = oldTable[i];
while (cur != NULL)
while (cur != nullptr)
{
T *hold = cur;
cur = static_cast<C *>(cur)->mHashNextEntry;
// insert hold into new table
int spot = ((unsigned)static_cast<C *>(hold)->mHashValue) % mTableSize;
if (mTable[spot] == NULL)
if (mTable[spot] == nullptr)
{
static_cast<C *>(hold)->mHashNextEntry = NULL;
static_cast<C *>(hold)->mHashNextEntry = nullptr;
mTable[spot] = hold;
mStatUsedSlots++;
}
@@ -14,8 +14,8 @@ template<typename T> class UdpLinkedList;
template<typename M> class UdpLinkedListMember
{
public:
UdpLinkedListMember() { mPrev = NULL; mNext = NULL; }
UdpLinkedListMember(const UdpLinkedListMember &) { mPrev = NULL; mNext = NULL; }
UdpLinkedListMember() { mPrev = nullptr; mNext = nullptr; }
UdpLinkedListMember(const UdpLinkedListMember &) { mPrev = nullptr; mNext = nullptr; }
~UdpLinkedListMember() {}
#if defined(_MSC_VER) && (_MSC_VER < 1300) // MSVC 7.0 is the first version to support friend templates
@@ -60,8 +60,8 @@ template<typename T> class UdpLinkedList
template<typename T> UdpLinkedList<T>::UdpLinkedList(UdpLinkedListMember<T> T::*node)
{
mHead = NULL;
mTail = NULL;
mHead = nullptr;
mTail = nullptr;
mNode = node;
mCount = 0;
}
@@ -98,7 +98,7 @@ template<typename T> int UdpLinkedList<T>::Count() const
template<typename T> T *UdpLinkedList<T>::Position(int index) const
{
T *cur = mHead;
while (cur != NULL && index > 0)
while (cur != nullptr && index > 0)
{
cur = Next(cur);
index--;
@@ -109,43 +109,43 @@ template<typename T> T *UdpLinkedList<T>::Position(int index) const
template<typename T> T *UdpLinkedList<T>::Remove(T *cur)
{
UdpLinkedListMember<T> *node = &(cur->*mNode);
if (node->mPrev == NULL)
if (node->mPrev == nullptr)
mHead = node->mNext;
else
((node->mPrev)->*mNode).mNext = node->mNext;
if (node->mNext == NULL)
if (node->mNext == nullptr)
mTail = node->mPrev;
else
((node->mNext)->*mNode).mPrev = node->mPrev;
node->mNext = NULL;
node->mPrev = NULL;
node->mNext = nullptr;
node->mPrev = nullptr;
mCount--;
return(cur);
}
template<typename T> T *UdpLinkedList<T>::RemoveHead()
{
if (mHead == NULL)
return(NULL);
if (mHead == nullptr)
return(nullptr);
return(Remove(mHead));
}
template<typename T> T *UdpLinkedList<T>::RemoveTail()
{
if (mTail == NULL)
return(NULL);
if (mTail == nullptr)
return(nullptr);
return(Remove(mTail));
}
template<typename T> T *UdpLinkedList<T>::InsertHead(T *cur)
{
assert((cur->*mNode).mPrev == NULL);
assert((cur->*mNode).mNext == NULL);
assert((cur->*mNode).mPrev == nullptr);
assert((cur->*mNode).mNext == nullptr);
(cur->*mNode).mNext = mHead;
if (mHead != NULL)
if (mHead != nullptr)
{
(mHead->*mNode).mPrev = cur;
mHead = cur;
@@ -161,12 +161,12 @@ template<typename T> T *UdpLinkedList<T>::InsertHead(T *cur)
template<typename T> T *UdpLinkedList<T>::InsertTail(T *cur)
{
assert((cur->*mNode).mPrev == NULL);
assert((cur->*mNode).mNext == NULL);
assert((cur->*mNode).mPrev == nullptr);
assert((cur->*mNode).mNext == nullptr);
(cur->*mNode).mPrev = mTail;
if (mTail != NULL)
if (mTail != nullptr)
{
(mTail->*mNode).mNext = cur;
mTail = cur;
@@ -182,17 +182,17 @@ template<typename T> T *UdpLinkedList<T>::InsertTail(T *cur)
template<typename T> T *UdpLinkedList<T>::InsertAfter(T *cur, T *prev)
{
assert((cur->*mNode).mPrev == NULL);
assert((cur->*mNode).mNext == NULL);
assert((cur->*mNode).mPrev == nullptr);
assert((cur->*mNode).mNext == nullptr);
if (prev == NULL)
if (prev == nullptr)
return(InsertHead(cur));
(cur->*mNode).mPrev = prev;
(cur->*mNode).mNext = (prev->*mNode).mNext;
(prev->*mNode).mNext = cur;
if ((cur->*mNode).mNext != NULL)
if ((cur->*mNode).mNext != nullptr)
(((cur->*mNode).mNext)->*mNode).mPrev = cur;
else
mTail = cur;
@@ -204,7 +204,7 @@ template<typename T> T *UdpLinkedList<T>::InsertAfter(T *cur, T *prev)
template<typename T> void UdpLinkedList<T>::DeleteAll()
{
T *cur = First();
while (cur != NULL)
while (cur != nullptr)
{
T *next = Next(cur);
Remove(cur);
@@ -216,7 +216,7 @@ template<typename T> void UdpLinkedList<T>::DeleteAll()
template<typename T> void UdpLinkedList<T>::ReleaseAll()
{
T *cur = First();
while (cur != NULL)
while (cur != nullptr)
{
T *next = Next(cur);
Remove(cur);
@@ -31,7 +31,7 @@ SimpleLogicalPacket::SimpleLogicalPacket(const void *data, int dataLen)
{
mDataLen = dataLen;
mData = new udp_uchar[mDataLen];
if (data != NULL)
if (data != nullptr)
memcpy(mData, data, mDataLen);
}
@@ -66,7 +66,7 @@ void SimpleLogicalPacket::SetDataLen(int len)
GroupLogicalPacket::GroupLogicalPacket() : LogicalPacket()
{
mDataLen = 0;
mData = NULL;
mData = nullptr;
}
GroupLogicalPacket::~GroupLogicalPacket()
@@ -76,13 +76,13 @@ GroupLogicalPacket::~GroupLogicalPacket()
void GroupLogicalPacket::AddPacket(const LogicalPacket *packet)
{
assert(packet != NULL);
assert(packet != nullptr);
AddPacketInternal(packet->GetDataPtr(), packet->GetDataLen(), packet->IsInternalPacket());
}
void GroupLogicalPacket::AddPacket(const void *data, int dataLen)
{
assert(data != NULL);
assert(data != nullptr);
assert(dataLen >= 0);
AddPacketInternal(data, dataLen, false);
}
@@ -152,10 +152,10 @@ PooledLogicalPacket::PooledLogicalPacket(UdpManager *manager, int len)
PooledLogicalPacket::~PooledLogicalPacket()
{
if (mUdpManager != NULL)
if (mUdpManager != nullptr)
{
mUdpManager->PoolDestroyed(this);
mUdpManager = NULL;
mUdpManager = nullptr;
}
delete[] mData;
@@ -168,7 +168,7 @@ void PooledLogicalPacket::AddRef() const
void PooledLogicalPacket::Release() const
{
if (GetRefCount() == 1 && mUdpManager != NULL)
if (GetRefCount() == 1 && mUdpManager != nullptr)
{
// the PoolReturn function steals our reference (ie, we don't release, they don't addref), this is for thread safety reasons
mUdpManager->PoolReturn(const_cast<PooledLogicalPacket *>(this));
@@ -208,9 +208,9 @@ void PooledLogicalPacket::SetDataLen(int len)
void PooledLogicalPacket::SetData(const void *data, int dataLen, const void *data2, int dataLen2)
{
mDataLen = dataLen + dataLen2;
if (data != NULL)
if (data != nullptr)
memcpy(mData, data, dataLen);
if (data2 != NULL)
if (data2 != nullptr)
memcpy(mData + dataLen, data2, dataLen2);
}
@@ -81,7 +81,7 @@ class SimpleLogicalPacket : public LogicalPacket
// it was originally created to allow the internal code to handle reliable data that was sent
// via the Send(char *, int) api call.
public:
SimpleLogicalPacket(const void *data, int dataLen); // data can be NULL if you want to populate it after it is allocated (get the pointer and write to it)
SimpleLogicalPacket(const void *data, int dataLen); // data can be nullptr if you want to populate it after it is allocated (get the pointer and write to it)
virtual void *GetDataPtr();
virtual const void *GetDataPtr() const;
virtual int GetDataLen() const;
@@ -152,7 +152,7 @@ template<typename T> class StructLogicalPacket : public LogicalPacket
// with virtual functions) via this method as they may contain hidden data-members (such as pointers
// to vtables).
public:
StructLogicalPacket(T *initData = NULL);
StructLogicalPacket(T *initData = nullptr);
virtual void *GetDataPtr();
virtual const void *GetDataPtr() const;
virtual int GetDataLen() const;
@@ -226,7 +226,7 @@ class PooledLogicalPacket : public LogicalPacket
protected:
friend class UdpManager;
void TrueRelease() const;
void SetData(const void *data, int dataLen, const void *data2 = NULL, int dataLen2 = 0);
void SetData(const void *data, int dataLen, const void *data2 = nullptr, int dataLen2 = 0);
UdpManager *mUdpManager;
UdpLinkedListMember<PooledLogicalPacket> mAvailableLink; // for available linked list in manager
UdpLinkedListMember<PooledLogicalPacket> mCreatedLink; // for created linked list in manager
@@ -240,7 +240,7 @@ class PooledLogicalPacket : public LogicalPacket
template<int t_quickSize> FixedLogicalPacket<t_quickSize>::FixedLogicalPacket(const void *data, int dataLen)
{
mDataLen = dataLen;
if (data != NULL)
if (data != nullptr)
memcpy(mData, data, mDataLen);
}
@@ -270,7 +270,7 @@ template<int t_quickSize> void FixedLogicalPacket<t_quickSize>::SetDataLen(int l
/////////////////////////////////////////////////////////////////////////
template<typename T> StructLogicalPacket<T>::StructLogicalPacket(T *initData)
{
if (initData != NULL)
if (initData != nullptr)
mStruct = *initData;
}
@@ -111,10 +111,10 @@ UdpManager::UdpManager(const UdpParams *params) : mConnectionList(&UdpConnection
mParams.maxDataHoldSize = udpMin(mParams.maxDataHoldSize, mParams.maxRawPacketSize);
mParams.packetHistoryMax = udpMax(1, mParams.packetHistoryMax);
mPacketHistoryPosition = 0;
mPassThroughData = NULL;
mBackgroundThread = NULL;
mPassThroughData = nullptr;
mBackgroundThread = nullptr;
if (mParams.udpDriver != NULL)
if (mParams.udpDriver != nullptr)
{
mDriver = mParams.udpDriver;
}
@@ -154,7 +154,7 @@ UdpManager::UdpManager(const UdpParams *params) : mConnectionList(&UdpConnection
mSimulateOutgoingQueueBytes = 0;
if (mParams.avoidPriorityQueue)
mPriorityQueue = NULL;
mPriorityQueue = nullptr;
else
mPriorityQueue = new PriorityQueue<UdpConnection, UdpClockStamp>(mParams.maxConnections);
@@ -181,7 +181,7 @@ UdpManager::~UdpManager()
{
// Since the background thread holds a reference to the UdpManager while it is running, this should
// not be possible. The only way it could happen is if somebody released the manager who should not have.
assert(mBackgroundThread == NULL);
assert(mBackgroundThread == nullptr);
// next thing we must do is tell all the connections to disconnect (which severs their link to this dying manager)
// this has to be done first since they will call back into us and have themselves removed from our connection-list/priority-queue/etc
@@ -191,7 +191,7 @@ UdpManager::~UdpManager()
UdpGuard cg(&mConnectionGuard);
UdpConnection *cur = mConnectionList.First();
while (cur != NULL)
while (cur != nullptr)
{
cur->AddRef();
cur->InternalDisconnect(0, UdpConnection::cDisconnectReasonManagerDeleted); // this will cause it to remove us from the mConnectionList
@@ -216,9 +216,9 @@ UdpManager::~UdpManager()
UdpGuard guard(&mPoolGuard);
PooledLogicalPacket *walk = mPoolCreatedList.RemoveHead();
while (walk != NULL)
while (walk != nullptr)
{
walk->mUdpManager = NULL;
walk->mUdpManager = nullptr;
walk = mPoolCreatedList.RemoveHead();
}
// next release the ones we have in our available pool
@@ -232,11 +232,11 @@ UdpManager::~UdpManager()
CloseSocket();
if (mParams.udpDriver == NULL)
if (mParams.udpDriver == nullptr)
{
delete mDriver; // we were not given a driver to use, so we must own this driver we have, so destroy it
}
mDriver = NULL;
mDriver = nullptr;
delete mAddressHashTable;
delete mConnectCodeHashTable;
@@ -295,7 +295,7 @@ void UdpManager::ProcessDisconnectPending()
UdpGuard guard(&mDisconnectPendingGuard);
UdpConnection *entry = mDisconnectPendingList.First();
while (entry != NULL)
while (entry != nullptr)
{
UdpConnection *next = mDisconnectPendingList.Next(entry);
if (entry->GetStatus() == UdpConnection::cStatusDisconnected)
@@ -309,12 +309,12 @@ void UdpManager::ProcessDisconnectPending()
void UdpManager::RemoveConnection(UdpConnection *con)
{
assert(con != NULL); // attemped to remove a NULL connection object
assert(con != nullptr); // attemped to remove a nullptr connection object
// note: it's a bug to Remove a connection object that is already removed...should never be able to happen.
UdpGuard cg(&mConnectionGuard);
if (mPriorityQueue != NULL)
if (mPriorityQueue != nullptr)
{
mPriorityQueue->Remove(con);
}
@@ -326,7 +326,7 @@ void UdpManager::RemoveConnection(UdpConnection *con)
void UdpManager::AddConnection(UdpConnection *con)
{
assert(con != NULL); // attemped to add a NULL connection object
assert(con != nullptr); // attemped to add a nullptr connection object
UdpGuard cg(&mConnectionGuard);
con->AddRef(); // UdpManager keeps a soft reference to the connection (ie. if it sees it is the only one holding a reference, it releases it)
@@ -341,17 +341,17 @@ void UdpManager::FlushAllMultiBuffer()
mConnectionGuard.Enter();
UdpConnection *cur = mConnectionList.First();
if (cur != NULL)
if (cur != nullptr)
cur->AddRef();
mConnectionGuard.Leave();
while (cur != NULL)
while (cur != nullptr)
{
cur->FlushMultiBuffer();
mConnectionGuard.Enter();
UdpConnection *next = mConnectionList.Next(cur);
if (next != NULL)
if (next != nullptr)
next->AddRef();
mConnectionGuard.Leave();
@@ -366,15 +366,15 @@ void UdpManager::DisconnectAll()
mConnectionGuard.Enter();
UdpConnection *cur = mConnectionList.First();
if (cur != NULL)
if (cur != nullptr)
cur->AddRef();
mConnectionGuard.Leave();
while (cur != NULL)
while (cur != nullptr)
{
mConnectionGuard.Enter();
UdpConnection *next = mConnectionList.Next(cur);
if (next != NULL)
if (next != nullptr)
next->AddRef();
mConnectionGuard.Leave();
@@ -392,7 +392,7 @@ void UdpManager::DeliverEvents(int maxProcessingTime)
for (;;)
{
CallbackEvent *ce = EventListPop();
if (ce == NULL)
if (ce == nullptr)
break;
switch(ce->mEventType)
@@ -426,13 +426,13 @@ void UdpManager::DeliverEvents(int maxProcessingTime)
{
{ // guard block
UdpGuard hguard(&mHandlerGuard);
if (mParams.handler != NULL)
if (mParams.handler != nullptr)
{
mParams.handler->OnConnectRequest(ce->mSource);
}
}
if (ce->mSource->GetHandler() == NULL) // if application did not set a handler, then the connection is considered refused
if (ce->mSource->GetHandler() == nullptr) // if application did not set a handler, then the connection is considered refused
{
ce->mSource->InternalDisconnect(0, UdpConnection::cDisconnectReasonConnectionRefused);
}
@@ -513,7 +513,7 @@ bool UdpManager::GiveTime(int maxPollingTime, bool giveConnectionsTime)
PacketHistoryEntry *e = SimulationReceive();
#endif
if (e == NULL)
if (e == nullptr)
{
mLastEmptySocketBufferStamp = CachedClock();
break;
@@ -545,7 +545,7 @@ bool UdpManager::GiveTime(int maxPollingTime, bool giveConnectionsTime)
if (giveConnectionsTime)
{
if (mPriorityQueue != NULL)
if (mPriorityQueue != nullptr)
{
// give time to everybody in the priority-queue that needs it
UdpClockStamp curPriority = CachedClock();
@@ -570,10 +570,10 @@ bool UdpManager::GiveTime(int maxPollingTime, bool giveConnectionsTime)
mConnectionGuard.Enter();
top = mPriorityQueue->TopRemove(curPriority);
if (top != NULL)
if (top != nullptr)
top->AddRef(); // must always addref connections while inside the connection guard
mConnectionGuard.Leave();
if (top == NULL)
if (top == nullptr)
break;
top->GiveTime(true);
@@ -593,17 +593,17 @@ bool UdpManager::GiveTime(int maxPollingTime, bool giveConnectionsTime)
// give time to everybody
mConnectionGuard.Enter();
UdpConnection *cur = mConnectionList.First();
if (cur != NULL)
if (cur != nullptr)
cur->AddRef();
mConnectionGuard.Leave();
while (cur != NULL)
while (cur != nullptr)
{
cur->GiveTime(true);
mConnectionGuard.Enter();
UdpConnection *next = mConnectionList.Next(cur);
if (next != NULL)
if (next != nullptr)
next->AddRef();
mConnectionGuard.Leave();
@@ -621,13 +621,13 @@ bool UdpManager::GiveTime(int maxPollingTime, bool giveConnectionsTime)
UdpClockStamp curStamp = CachedClock();
SimulateQueueEntry *entry = mSimulateOutgoingList.First();
while (entry != NULL && curStamp >= mSimulateNextOutgoingTime)
while (entry != nullptr && curStamp >= mSimulateNextOutgoingTime)
{
mSimulateOutgoingList.Remove(entry);
SimulateQueueEntry *next = mSimulateOutgoingList.First();
// simulate a delay before next packet is considered (ie. simple lag)
if (next != NULL)
if (next != nullptr)
{
int latencyDelay = (mSimulation.simulateOutgoingLatency - CachedClockElapsed(next->mQueueTime));
mSimulateNextOutgoingTime = curStamp + latencyDelay;
@@ -644,7 +644,7 @@ bool UdpManager::GiveTime(int maxPollingTime, bool giveConnectionsTime)
ActualSendHelper(entry->mData, entry->mDataLen, entry->mIp, entry->mPort);
UdpConnection *con = AddressGetConnection(entry->mIp, entry->mPort);
if (con != NULL)
if (con != nullptr)
{
con->mSimulateOutgoingQueueBytes -= entry->mDataLen;
con->Release();
@@ -664,12 +664,12 @@ UdpConnection *UdpManager::EstablishConnection(const char *serverAddress, int se
{
UdpGuard guard(&mGiveTimeGuard); // probably not needed, I don't see any reason we can't do this while GiveTime is happening in the background...the connection list is protected independently...still, better safe than sorry
assert(serverAddress != NULL);
assert(serverAddress != nullptr);
char useServerAddress[512];
UdpLibrary::UdpMisc::Strncpy(useServerAddress, serverAddress, sizeof(useServerAddress));
char *portPtr = strchr(useServerAddress, ':');
if (portPtr != NULL)
if (portPtr != nullptr)
{
*portPtr++ = 0;
serverPort = atoi(portPtr);
@@ -679,21 +679,21 @@ UdpConnection *UdpManager::EstablishConnection(const char *serverAddress, int se
assert(serverPort != 0); // can't connect to no port
if (mConnectionList.Count() >= mParams.maxConnections)
return(NULL);
return(nullptr);
// get server address
UdpPlatformAddress destIp;
if (!mDriver->GetHostByName(&destIp, useServerAddress))
{
return(NULL); // could not resolve name
return(nullptr); // could not resolve name
}
// first, see if we already have a connection object managing this ip/port, if we do, then fail
UdpConnection *con = AddressGetConnection(destIp, serverPort);
if (con != NULL)
if (con != nullptr)
{
con->Release();
return(NULL); // already connected to this address/port
return(nullptr); // already connected to this address/port
}
return(new UdpConnection(this, destIp, serverPort, timeout));
}
@@ -709,7 +709,7 @@ void UdpManager::GetStats(UdpManagerStatistics *stats)
{
UdpGuard sg(&mStatsGuard);
assert(stats != NULL);
assert(stats != nullptr);
*stats = mManagerStats;
stats->poolAvailable = mPoolAvailableList.Count();
stats->poolCreated = mPoolCreatedList.Count();
@@ -737,10 +737,10 @@ void UdpManager::DumpPacketHistory(const char *filename) const
{
UdpGuard guard(&mGiveTimeGuard);
assert(filename != NULL);
assert(filename != nullptr);
assert(filename[0] != 0);
FILE *file = fopen(filename, "wt");
if (file != NULL)
if (file != nullptr)
{
// dump history of packets...
for (int i = 0; i < mParams.packetHistoryMax; i++)
@@ -789,7 +789,7 @@ UdpManager::PacketHistoryEntry *UdpManager::SimulationReceive()
for (;;)
{
PacketHistoryEntry *entry = ActualReceive();
if (entry == NULL)
if (entry == nullptr)
break;
SimulateQueueEntry *qe = new SimulateQueueEntry(entry->mBuffer, entry->mLen, entry->mIp, entry->mPort, curStamp);
@@ -797,7 +797,7 @@ UdpManager::PacketHistoryEntry *UdpManager::SimulationReceive()
}
SimulateQueueEntry *winner = mSimulateIncomingList.First();
if (winner != NULL && CachedClockElapsed(winner->mQueueTime) >= mSimulation.simulateIncomingLatency)
if (winner != nullptr && CachedClockElapsed(winner->mQueueTime) >= mSimulation.simulateIncomingLatency)
{
mSimulateIncomingList.Remove(winner);
int pos = mPacketHistoryPosition;
@@ -809,14 +809,14 @@ UdpManager::PacketHistoryEntry *UdpManager::SimulationReceive()
delete winner;
return(mPacketHistory[pos]);
}
return(NULL);
return(nullptr);
}
UdpManager::PacketHistoryEntry *UdpManager::ActualReceive()
{
UdpClockStamp curStamp = CachedClock();
if (mSimulation.simulateIncomingByteRate > 0 && curStamp < mSimulateNextIncomingTime)
return(NULL);
return(nullptr);
UdpPlatformAddress fromAddress;
int fromPort = 0;
@@ -855,7 +855,7 @@ UdpManager::PacketHistoryEntry *UdpManager::ActualReceive()
}
return(mPacketHistory[pos]);
}
return(NULL);
return(nullptr);
}
void UdpManager::ActualSend(const udp_uchar *data, int dataLen, UdpPlatformAddress ip, int port)
@@ -876,7 +876,7 @@ void UdpManager::ActualSend(const udp_uchar *data, int dataLen, UdpPlatformAddre
return; // no room, packet gets lost
UdpConnection *con = AddressGetConnection(ip, port);
if (con != NULL)
if (con != nullptr)
{
if (mSimulation.simulateDestinationOverloadLevel > 0 && con->mSimulateOutgoingQueueBytes + dataLen > mSimulation.simulateDestinationOverloadLevel)
{
@@ -928,7 +928,7 @@ void UdpManager::ProcessRawPacket(const PacketHistoryEntry *e)
UdpConnection *con = AddressGetConnection(e->mIp, e->mPort);
if (con == NULL)
if (con == nullptr)
{
if (e->mLen == 0) // len = 0 = ICMP error
{
@@ -946,7 +946,7 @@ void UdpManager::ProcessRawPacket(const PacketHistoryEntry *e)
if (mConnectionList.Count() >= mParams.maxConnections)
return; // can't handle any more connections, so ignore this request entirely
if (mParams.handler != NULL)
if (mParams.handler != nullptr)
{
UdpConnection *newcon = new UdpConnection(this, e);
CallbackConnectRequest(newcon);
@@ -968,7 +968,7 @@ void UdpManager::ProcessRawPacket(const PacketHistoryEntry *e)
int encryptCode = UdpMisc::GetValue32(ptr);
UdpConnection *con = ConnectCodeGetConnection(connectCode);
if (con != NULL)
if (con != nullptr)
{
if (mParams.allowAddressRemapping || con->mIp == e->mIp)
{
@@ -1025,7 +1025,7 @@ UdpConnection *UdpManager::AddressGetConnection(UdpPlatformAddress ip, int port)
UdpGuard guard(&mConnectionGuard);
UdpConnection *found = mAddressHashTable->FindFirst(AddressHashValue(ip, port));
while (found != NULL)
while (found != nullptr)
{
if (found->mIp == ip && found->mPort == port)
{
@@ -1034,7 +1034,7 @@ UdpConnection *UdpManager::AddressGetConnection(UdpPlatformAddress ip, int port)
}
found = mAddressHashTable->FindNext(found);
}
return(NULL);
return(nullptr);
}
UdpConnection *UdpManager::ConnectCodeGetConnection(int connectCode) const
@@ -1042,7 +1042,7 @@ UdpConnection *UdpManager::ConnectCodeGetConnection(int connectCode) const
UdpGuard guard(&mConnectionGuard);
UdpConnection *found = mConnectCodeHashTable->FindFirst(connectCode);
while (found != NULL)
while (found != nullptr)
{
if (found->mConnectCode == connectCode)
{
@@ -1051,7 +1051,7 @@ UdpConnection *UdpManager::ConnectCodeGetConnection(int connectCode) const
}
found = mConnectCodeHashTable->FindNext(found);
}
return(NULL);
return(nullptr);
}
LogicalPacket *UdpManager::CreatePacket(const void *data, int dataLen, const void *data2, int dataLen2)
@@ -1063,7 +1063,7 @@ LogicalPacket *UdpManager::CreatePacket(const void *data, int dataLen, const voi
{
UdpGuard guard(&mPoolGuard);
PooledLogicalPacket *lp = mPoolAvailableList.RemoveHead();
if (lp == NULL)
if (lp == nullptr)
{
// create a new pooled packet to fulfil request
lp = new PooledLogicalPacket(this, mParams.pooledPacketSize);
@@ -1091,7 +1091,7 @@ void UdpManager::PoolDestroyed(PooledLogicalPacket *packet)
char *UdpManager::GetLocalString(char *buf, int bufLen) const
{
if (bufLen < 22)
return(NULL);
return(nullptr);
UdpPlatformAddress ip = GetLocalIp();
int port = GetLocalPort();
char hold[256];
@@ -1103,7 +1103,7 @@ UdpManager::CallbackEvent *UdpManager::AvailableEventBorrow()
{
UdpGuard guard(&mAvailableEventGuard);
CallbackEvent *ce = mAvailableEventList.RemoveHead();
if (ce == NULL)
if (ce == nullptr)
{
ce = new CallbackEvent();
}
@@ -1127,7 +1127,7 @@ void UdpManager::EventListAppend(CallbackEvent *ce)
{
UdpGuard guard(&mEventListGuard);
mEventList.InsertTail(ce);
if (ce->mPayload != NULL)
if (ce->mPayload != nullptr)
{
mEventListBytes += ce->mPayload->GetDataLen();
}
@@ -1137,7 +1137,7 @@ UdpManager::CallbackEvent *UdpManager::EventListPop()
{
UdpGuard guard(&mEventListGuard);
CallbackEvent *event = mEventList.RemoveHead();
if (event != NULL && event->mPayload != NULL)
if (event != nullptr && event->mPayload != nullptr)
{
mEventListBytes -= event->mPayload->GetDataLen();
}
@@ -1148,7 +1148,7 @@ UdpManager::CallbackEvent *UdpManager::EventListPop()
void UdpManager::ThreadStart()
{
UdpGuard guard(&mThreadGuard);
if (mBackgroundThread == NULL)
if (mBackgroundThread == nullptr)
{
mBackgroundThread = new UdpManagerThread(this, mParams.threadSleepTime);
mBackgroundThread->Start();
@@ -1158,12 +1158,12 @@ void UdpManager::ThreadStart()
void UdpManager::ThreadStop()
{
UdpGuard guard(&mThreadGuard);
if (mBackgroundThread != NULL)
if (mBackgroundThread != nullptr)
{
assert(mRefCount > 1); // caller must hold a reference, and thread must hold a reference, so this should be true. If it asserts, it means the caller is using a UdpManager that it does not hold a reference to.
mBackgroundThread->Stop(true);
mBackgroundThread->Release();
mBackgroundThread = NULL;
mBackgroundThread = nullptr;
}
}
@@ -1256,13 +1256,13 @@ void UdpManager::CallbackConnectRequest(UdpConnection *con)
{
{ // guard block
UdpGuard hguard(&mHandlerGuard);
if (mParams.handler != NULL)
if (mParams.handler != nullptr)
{
mParams.handler->OnConnectRequest(con);
}
}
if (con->GetHandler() == NULL) // if application did not set a handler, then the connection is considered refused
if (con->GetHandler() == nullptr) // if application did not set a handler, then the connection is considered refused
{
con->InternalDisconnect(0, UdpConnection::cDisconnectReasonConnectionRefused);
}
@@ -1276,8 +1276,8 @@ void UdpManager::CallbackConnectRequest(UdpConnection *con)
UdpManager::CallbackEvent::CallbackEvent()
{
mEventType = cCallbackEventNone;
mSource = NULL;
mPayload = NULL;
mSource = nullptr;
mPayload = nullptr;
mReason = cUdpCorruptionReasonNone;
}
@@ -1291,7 +1291,7 @@ void UdpManager::CallbackEvent::SetEventData(CallbackEventType eventType, UdpCon
mEventType = eventType;
mSource = con;
mSource->AddRef();
if (payload != NULL)
if (payload != nullptr)
{
mPayload = payload;
mPayload->AddRef();
@@ -1300,16 +1300,16 @@ void UdpManager::CallbackEvent::SetEventData(CallbackEventType eventType, UdpCon
void UdpManager::CallbackEvent::ClearEventData()
{
if (mSource != NULL)
if (mSource != nullptr)
{
mSource->Release();
mSource = NULL;
mSource = nullptr;
}
if (mPayload != NULL)
if (mPayload != nullptr)
{
mPayload->Release();
mPayload = NULL;
mPayload = nullptr;
}
}
@@ -178,7 +178,7 @@ struct UdpParams
// pointer equal to your object and the UdpManager will call it as appropriate. The UdpConnection object
// also has a handler mechanism that replaces the other callback functions below, see UdpConnection::SetHandler
// if a handler is specified, the callback function is ignored, even if specified.
// default = NULL (not used)
// default = nullptr (not used)
UdpManagerHandler *handler;
// this is the maximum number of connections that can be established by this manager, any incoming/outgoing connections
@@ -496,7 +496,7 @@ struct UdpParams
// the UdpPlatformDriver object itself and chain the calls on through, plus do whatever else it wants;
// however, that is not required. The application maintains ownership of this object and the object must
// not be destroyed by the application until the UdpManager using it is destroyed.
// default = NULL, meaning the UdpManager it will create it's own UdpPlatformDriver for use.
// default = nullptr, meaning the UdpManager it will create it's own UdpPlatformDriver for use.
UdpDriver *udpDriver;
@@ -642,7 +642,7 @@ class UdpManager : public UdpGuardedRefCount
// will call EstablishConnection, then sit in a loop calling UdpManager::GiveTime and checking to see
// if the status of the returned UdpConnection object is changed from cStatusNegotiating. This allows
// the application to look for the ESC key or timeout an attempted connection.
// This function will return NULL if the manager object has exceeded its maximum number of connections
// This function will return nullptr if the manager object has exceeded its maximum number of connections
// or if the serverAddress cannot be resolved to an IP address
// as is noted in the declaration, it is the responsibility of the application establishing the connection to delete it
// setting the timeout value (in milliseconds) to something greater than 0 will cause the UdpConnection object to change
@@ -685,13 +685,13 @@ class UdpManager : public UdpGuardedRefCount
// a terminated packet.
void DisconnectAll();
// creates a logical packet and populates it with data. data can be NULL, in which case it gives you logical packet
// creates a logical packet and populates it with data. data can be nullptr, in which case it gives you logical packet
// of the size specified, but copies no data into it. If you are using pool management (see Params::poolPacketMax),
// it will give you a packet out of the pool if possible, otherwise it will create a packet for you. When logical
// are packets are needed internally for various things (like reliable channel sends that use the (void *, int) interface)
// they are gotten from this function, so your application can likely take advantage of pooling, even if it never bothers
// to explicitly call this function.
LogicalPacket *CreatePacket(const void *data, int dataLen, const void *data2 = NULL, int dataLen2 = 0);
LogicalPacket *CreatePacket(const void *data, int dataLen, const void *data2 = nullptr, int dataLen2 = 0);
void GetSimulation(UdpSimulationParameters *simulationParameters) const;
void SetSimulation(const UdpSimulationParameters *simulationParameters);
@@ -796,7 +796,7 @@ class UdpManager : public UdpGuardedRefCount
CallbackEvent();
~CallbackEvent();
void SetEventData(CallbackEventType eventType, UdpConnection *con, const LogicalPacket *payload = NULL);
void SetEventData(CallbackEventType eventType, UdpConnection *con, const LogicalPacket *payload = nullptr);
void ClearEventData();
CallbackEventType mEventType;
@@ -926,7 +926,7 @@ inline void UdpManager::SetPriority(UdpConnection *con, UdpClockStamp stamp)
if (stamp < mMinimumScheduledStamp)
stamp = mMinimumScheduledStamp;
if (mPriorityQueue != NULL)
if (mPriorityQueue != nullptr)
{
mPriorityQueue->Add(con, stamp);
}
@@ -1025,7 +1025,7 @@ inline int UdpManager::CachedClockElapsed(UdpClockStamp start)
inline int UdpManager::EncryptUserSupplied(UdpConnection *con, udp_uchar *destData, const udp_uchar *sourceData, int sourceLen)
{
UdpGuard guard(&mHandlerGuard);
if (mParams.handler != NULL)
if (mParams.handler != nullptr)
{
return(mParams.handler->OnUserSuppliedEncrypt(con, destData, sourceData, sourceLen));
}
@@ -1035,7 +1035,7 @@ inline int UdpManager::EncryptUserSupplied(UdpConnection *con, udp_uchar *destDa
inline int UdpManager::EncryptUserSupplied2(UdpConnection *con, udp_uchar *destData, const udp_uchar *sourceData, int sourceLen)
{
UdpGuard guard(&mHandlerGuard);
if (mParams.handler != NULL)
if (mParams.handler != nullptr)
{
return(mParams.handler->OnUserSuppliedEncrypt2(con, destData, sourceData, sourceLen));
}
@@ -1045,7 +1045,7 @@ inline int UdpManager::EncryptUserSupplied2(UdpConnection *con, udp_uchar *destD
inline int UdpManager::DecryptUserSupplied(UdpConnection *con, udp_uchar *destData, const udp_uchar *sourceData, int sourceLen)
{
UdpGuard guard(&mHandlerGuard);
if (mParams.handler != NULL)
if (mParams.handler != nullptr)
{
return(mParams.handler->OnUserSuppliedDecrypt(con, destData, sourceData, sourceLen));
}
@@ -1055,7 +1055,7 @@ inline int UdpManager::DecryptUserSupplied(UdpConnection *con, udp_uchar *destDa
inline int UdpManager::DecryptUserSupplied2(UdpConnection *con, udp_uchar *destData, const udp_uchar *sourceData, int sourceLen)
{
UdpGuard guard(&mHandlerGuard);
if (mParams.handler != NULL)
if (mParams.handler != nullptr)
{
return(mParams.handler->OnUserSuppliedDecrypt2(con, destData, sourceData, sourceLen));
}
@@ -1070,7 +1070,7 @@ inline int UdpManager::DecryptUserSupplied2(UdpConnection *con, udp_uchar *destD
/////////////////////////////////////////////////////////////////////////////////////////////////////
inline UdpParams::UdpParams(ManagerRole role)
{
handler = NULL;
handler = nullptr;
outgoingBufferSize = 64 * 1024;
incomingBufferSize = 64 * 1024;
packetHistoryMax = 4;
@@ -1103,7 +1103,7 @@ inline UdpParams::UdpParams(ManagerRole role)
reliableOverflowBytes = 0;
lingerDelay = 10;
bindIpAddress[0] = 0;
udpDriver = NULL;
udpDriver = nullptr;
callbackEventPoolMax = 5000;
eventQueuing = false;
threadSleepTime = 20;
@@ -113,19 +113,19 @@ void *UdpMisc::SmartResize(void *ptr, int bytes, int round)
if (bytes == 0)
{
if (ptr != NULL)
if (ptr != nullptr)
{
free((udp_uchar *)ptr - cAlignment);
}
return(NULL);
return(nullptr);
}
udp_uchar *ptr2;
if (ptr == NULL)
if (ptr == nullptr)
{
ptr2 = (udp_uchar *)malloc(bytes + cAlignment);
if (ptr2 == NULL)
return(NULL);
if (ptr2 == nullptr)
return(nullptr);
*(int *)ptr2 = bytes;
return(ptr2 + cAlignment);
}
@@ -135,8 +135,8 @@ void *UdpMisc::SmartResize(void *ptr, int bytes, int round)
return(ptr);
ptr2 = (udp_uchar *)realloc((udp_uchar *)ptr - cAlignment, bytes + cAlignment);
if (ptr2 == NULL)
return(NULL);
if (ptr2 == nullptr)
return(nullptr);
*(int *)ptr2 = bytes;
return(ptr2 + cAlignment);
@@ -199,30 +199,30 @@ LogicalPacket *UdpMisc::CreateQuickLogicalPacket(const void *data, int dataLen,
switch(q)
{
case 0:
tlp = new FixedLogicalPacket<cQuickFactor>(NULL, totalDataLen);
tlp = new FixedLogicalPacket<cQuickFactor>(nullptr, totalDataLen);
break;
case 1:
tlp = new FixedLogicalPacket<cQuickFactor * 2>(NULL, totalDataLen);
tlp = new FixedLogicalPacket<cQuickFactor * 2>(nullptr, totalDataLen);
break;
case 2:
case 3:
tlp = new FixedLogicalPacket<cQuickFactor * 4>(NULL, totalDataLen);
tlp = new FixedLogicalPacket<cQuickFactor * 4>(nullptr, totalDataLen);
break;
case 4:
case 5:
case 6:
case 7:
tlp = new FixedLogicalPacket<cQuickFactor * 8>(NULL, totalDataLen);
tlp = new FixedLogicalPacket<cQuickFactor * 8>(nullptr, totalDataLen);
break;
default:
tlp = new SimpleLogicalPacket(NULL, totalDataLen);
tlp = new SimpleLogicalPacket(nullptr, totalDataLen);
break;
}
udp_uchar *dest = (udp_uchar *)tlp->GetDataPtr();
if (data != NULL)
if (data != nullptr)
memcpy(dest, data, dataLen);
if (data2 != NULL)
if (data2 != nullptr)
memcpy(dest + dataLen, data2, dataLen2);
return(tlp);
}
@@ -57,7 +57,7 @@ class UdpMisc
// memory manager does a little bit of this, but if you know you have an allocation that is likely
// to grow quite a bit, you can set the round'ing size up to a fairly large number and avoid
// unnecessary reallocs at the cost of a little potentially wasted space
// initial allocations are done by passing in ptr==NULL, freeing is done by passing in bytes==0
// initial allocations are done by passing in ptr==nullptr, freeing is done by passing in bytes==0
static void *SmartResize(void *ptr, int bytes, int round = 1);
// the following two functions store values in the buffer as a variable length (B1, 0xffB2B1, 0xffffffB4B3B2B1)
@@ -78,7 +78,7 @@ class UdpMisc
static udp_uint GetValue24(const void *buffer); // gets a 24-bit value from the buffer in big-endian format
static udp_ushort GetValue16(const void *buffer); // gets a 16-bit value from the buffer in big-endian format
static LogicalPacket *CreateQuickLogicalPacket(const void *data, int dataLen, const void *data2 = NULL, int dataLen2 = 0);
static LogicalPacket *CreateQuickLogicalPacket(const void *data, int dataLen, const void *data2 = nullptr, int dataLen2 = 0);
// looks up the specified name and translates it to an IP address
// this is a blocking call that can at times take a significant amount of time, but will generally be fast (less than 300ms)
@@ -43,12 +43,12 @@ template<typename T, typename P> class PriorityQueue
PriorityQueue(int queueSize);
~PriorityQueue();
T* Top(); // returns NULL if queue is empty
T* TopRemove(); // returns NULL if queue is empty
T* TopRemove(P priority); // removes item from queue if it has a lower priority value, otherwise return NULL
T* Top(); // returns nullptr if queue is empty
T* TopRemove(); // returns nullptr if queue is empty
T* TopRemove(P priority); // removes item from queue if it has a lower priority value, otherwise return nullptr
T* Add(T* entry, P priority); // reprioritizes if already in queue, returns entry always
T* Remove(T* entry); // returns entry always (even if it was not in the queue)
P *GetPriority(T* entry); // returns NULL if entry is not in the queue
P *GetPriority(T* entry); // returns nullptr if entry is not in the queue
int QueueUsed(); // returns how many entries are in the queue
protected:
struct QueueEntry
@@ -94,14 +94,14 @@ template<typename T, typename P> PriorityQueue<T, P>::~PriorityQueue()
template<typename T, typename P> T* PriorityQueue<T, P>::Top()
{
if (mQueueEnd == 0)
return(NULL);
return(nullptr);
return(mQueue[0].entry);
}
template<typename T, typename P> T* PriorityQueue<T, P>::TopRemove()
{
if (mQueueEnd == 0)
return(NULL);
return(nullptr);
T* top = mQueue[0].entry;
Remove(top);
return(top);
@@ -111,14 +111,14 @@ template<typename T, typename P> T* PriorityQueue<T, P>::TopRemove(P priority)
{
if (mQueueEnd > 0 && mQueue[0].priority <= priority)
return(Remove(mQueue[0].entry));
return(NULL);
return(nullptr);
}
template<typename T, typename P> P* PriorityQueue<T, P>::GetPriority(T* entry)
{
if (entry->mPriorityQueuePosition >= 0)
return(&mQueue[entry->mPriorityQueuePosition].priority);
return(NULL);
return(nullptr);
}
template<typename T, typename P> T* PriorityQueue<T, P>::Add(T* entry, P priority)
@@ -127,7 +127,7 @@ template<typename T, typename P> T* PriorityQueue<T, P>::Add(T* entry, P priorit
{
// not in queue, so add it to the bottom
if (mQueueEnd >= mQueueSize)
return(NULL);
return(nullptr);
mQueue[mQueueEnd].entry = entry;
mQueue[mQueueEnd].priority = priority;
mQueue[mQueueEnd].entry->mPriorityQueuePosition = mQueueEnd;
@@ -48,12 +48,12 @@ UdpReliableChannel::UdpReliableChannel(int channelNumber, UdpConnection *con, Ud
mReliableOutgoingBytes = 0;
mLogicalBytesQueued = 0;
mCoalescePacket = NULL;
mCoalesceStartPtr = NULL;
mCoalesceEndPtr = NULL;
mCoalescePacket = nullptr;
mCoalesceStartPtr = nullptr;
mCoalesceEndPtr = nullptr;
mCoalesceCount = 0;
mBufferedAckPtr = NULL;
mBufferedAckPtr = nullptr;
mStatDuplicatePacketsReceived = 0;
mStatResentPacketsAccelerated = 0;
@@ -69,7 +69,7 @@ UdpReliableChannel::UdpReliableChannel(int channelNumber, UdpConnection *con, Ud
mBigDataLen = 0;
mBigDataTargetLen = 0;
mBigDataPtr = NULL;
mBigDataPtr = nullptr;
mFragmentNextPos = 0;
mLastTimeStampAcknowledged = 0;
mMaxxedOutCurrentWindow = false;
@@ -81,14 +81,14 @@ UdpReliableChannel::UdpReliableChannel(int channelNumber, UdpConnection *con, Ud
UdpReliableChannel::~UdpReliableChannel()
{
if (mCoalescePacket != NULL)
if (mCoalescePacket != nullptr)
{
mCoalescePacket->Release();
mCoalescePacket = NULL;
mCoalescePacket = nullptr;
}
const LogicalPacket *cur = mLogicalPacketList.RemoveHead();
while (cur != NULL)
while (cur != nullptr)
{
cur->Release();
cur = mLogicalPacketList.RemoveHead();
@@ -103,7 +103,7 @@ UdpReliableChannel::~UdpReliableChannel()
void UdpReliableChannel::Send(const udp_uchar *data, int dataLen, const udp_uchar *data2, int dataLen2)
{
if (mLogicalPacketList.Count() == 0 && mCoalescePacket == NULL)
if (mLogicalPacketList.Count() == 0 && mCoalescePacket == nullptr)
{
// if we are adding something to a previously empty logical queue, then it is possible that
// we may be able to send it, so mark ourselves to take time the next time it is offered
@@ -126,7 +126,7 @@ void UdpReliableChannel::Send(const udp_uchar *data, int dataLen, const udp_ucha
void UdpReliableChannel::FlushCoalesce()
{
if (mCoalescePacket != NULL)
if (mCoalescePacket != nullptr)
{
if (mCoalesceCount == 1)
{
@@ -140,16 +140,16 @@ void UdpReliableChannel::FlushCoalesce()
mCoalescePacket->SetDataLen((int)(mCoalesceEndPtr - mCoalesceStartPtr));
QueueLogicalPacket(mCoalescePacket);
mCoalescePacket->Release();
mCoalescePacket = NULL;
mCoalescePacket = nullptr;
}
}
void UdpReliableChannel::SendCoalesce(const udp_uchar *data, int dataLen, const udp_uchar *data2, int dataLen2)
{
int totalLen = dataLen + dataLen2;
if (mCoalescePacket == NULL)
if (mCoalescePacket == nullptr)
{
mCoalescePacket = mUdpConnection->mUdpManager->CreatePacket(NULL, mMaxDataBytes);
mCoalescePacket = mUdpConnection->mUdpManager->CreatePacket(nullptr, mMaxDataBytes);
mCoalesceEndPtr = mCoalesceStartPtr = (udp_uchar *)mCoalescePacket->GetDataPtr();
*mCoalesceEndPtr++ = 0;
*mCoalesceEndPtr++ = UdpConnection::cUdpPacketGroup;
@@ -169,10 +169,10 @@ void UdpReliableChannel::SendCoalesce(const udp_uchar *data, int dataLen, const
// append on end of coalesce
mCoalesceCount++;
mCoalesceEndPtr += UdpMisc::PutVariableValue(mCoalesceEndPtr, totalLen);
if (data != NULL)
if (data != nullptr)
memcpy(mCoalesceEndPtr, data, dataLen);
mCoalesceEndPtr += dataLen;
if (data2 != NULL)
if (data2 != nullptr)
memcpy(mCoalesceEndPtr, data2, dataLen2);
mCoalesceEndPtr += dataLen2;
}
@@ -287,7 +287,7 @@ int UdpReliableChannel::GiveTime()
mMaxxedOutCurrentWindow = false;
int outstandingNextSendTime = 10 * 60000;
// if we have something to do
if (mReliableOutgoingPendingId < mReliableOutgoingId || mLogicalPacketList.Count() != 0 || mCoalescePacket != NULL)
if (mReliableOutgoingPendingId < mReliableOutgoingId || mLogicalPacketList.Count() != 0 || mCoalescePacket != nullptr)
{
// first, let's calculate how many bytes we figure is outstanding based on who is still waiting for an ack-packet
UdpClockStamp oldestResendTime = udpMax(hotClock - optimalResendDelay, mLastTimeStampAcknowledged); // anything older than this, we need to resend
@@ -317,7 +317,7 @@ int UdpReliableChannel::GiveTime()
// if this packet has not been acked and it is NOT ready to be sent (was recently sent) then we consider it outstanding
// note: packets needing re-sending probably got lost and are therefore not outstanding
PhysicalPacket *entry = &mPhysicalPackets[i % mConfig.maxOutstandingPackets];
if (entry->mDataPtr != NULL) // acked packets set the dataPtr to NULL
if (entry->mDataPtr != nullptr) // acked packets set the dataPtr to nullptr
{
// if this packet is ready to be sent (ie: needs time now, or some later packet has already been ack'ed)
windowSpaceLeft -= entry->mDataLen; // window-space is effectively taken whether we have sent it yet or not
@@ -524,7 +524,7 @@ int UdpReliableChannel::GiveTime()
void UdpReliableChannel::GetChannelStatus(UdpConnection::ChannelStatus *channelStatus) const
{
int coalesceBytes = 0;
if (mCoalescePacket != NULL)
if (mCoalescePacket != nullptr)
coalesceBytes = (int)(mCoalesceEndPtr - mCoalesceStartPtr);
channelStatus->totalPendingBytes = mLogicalBytesQueued + mReliableOutgoingBytes + coalesceBytes;
@@ -550,7 +550,7 @@ void UdpReliableChannel::GetChannelStatus(UdpConnection::ChannelStatus *channelS
PhysicalPacket *entry = &mPhysicalPackets[mReliableOutgoingPendingId % mConfig.maxOutstandingPackets];
if (entry->mFirstTimeStamp != 0) // if has been sent (we know it hasn't been acknowledged or we couldn't possibly be pointing at it as pending)
{
if (mUdpConnection->GetUdpManager() != NULL)
if (mUdpConnection->GetUdpManager() != nullptr)
{
channelStatus->oldestUnacknowledgedAge = mUdpConnection->GetUdpManager()->CachedClockElapsed(entry->mFirstTimeStamp);
}
@@ -588,7 +588,7 @@ void UdpReliableChannel::ReliablePacket(const udp_uchar *data, int dataLen)
mReliableIncomingId++;
// process other packets that have arrived
while (mReliableIncoming[mReliableIncomingId % mConfig.maxInstandingPackets].mPacket != NULL)
while (mReliableIncoming[mReliableIncomingId % mConfig.maxInstandingPackets].mPacket != nullptr)
{
int spot = (int)(mReliableIncomingId % mConfig.maxInstandingPackets);
if (mReliableIncoming[spot].mMode != cReliablePacketModeDelivered)
@@ -597,7 +597,7 @@ void UdpReliableChannel::ReliablePacket(const udp_uchar *data, int dataLen)
}
mReliableIncoming[spot].mPacket->Release();
mReliableIncoming[spot].mPacket = NULL;
mReliableIncoming[spot].mPacket = nullptr;
mReliableIncomingId++;
}
}
@@ -605,7 +605,7 @@ void UdpReliableChannel::ReliablePacket(const udp_uchar *data, int dataLen)
{
// not the one we need next, but it is later than the one we need , so store it in our buffer until it's turn comes up
int spot = (int)(reliableId % mConfig.maxInstandingPackets);
if (mReliableIncoming[spot].mPacket == NULL) // only make the copy of it if we don't already have it in our buffer (in cases where it was sent twice, there would be no harm in the copy again since it must be the same packet, it's just inefficient)
if (mReliableIncoming[spot].mPacket == nullptr) // only make the copy of it if we don't already have it in our buffer (in cases where it was sent twice, there would be no harm in the copy again since it must be the same packet, it's just inefficient)
{
mReliableIncoming[spot].mMode = mode;
mReliableIncoming[spot].mPacket = mUdpConnection->mUdpManager->CreatePacket(data + UdpConnection::cUdpPacketReliableSize, dataLen - UdpConnection::cUdpPacketReliableSize);
@@ -651,14 +651,14 @@ void UdpReliableChannel::ReliablePacket(const udp_uchar *data, int dataLen)
bufPtr += UdpMisc::PutValue16(bufPtr, (udp_ushort)(reliableId & 0xffff));
}
if (mBufferedAckPtr != NULL && mConfig.ackDeduping && ackAll)
if (mBufferedAckPtr != nullptr && mConfig.ackDeduping && ackAll)
{
memcpy(mBufferedAckPtr, buf, bufPtr - buf);
}
else
{
udp_uchar *ptr = mUdpConnection->BufferedSend(buf, (int)(bufPtr - buf), NULL, 0, true); // safe to append on our data, it is stack data
if (mBufferedAckPtr == NULL)
udp_uchar *ptr = mUdpConnection->BufferedSend(buf, (int)(bufPtr - buf), nullptr, 0, true); // safe to append on our data, it is stack data
if (mBufferedAckPtr == nullptr)
{
// the buffered-ack ptr should always point to the earliest ack in the buffer, such that
// a replacement ack-all will be processed by the receiver before any selective acks that may
@@ -676,7 +676,7 @@ void UdpReliableChannel::ProcessPacket(ReliablePacketMode mode, const udp_uchar
if (mode == cReliablePacketModeReliable)
{
// we are not a fragment, nor was there a fragment in progress, so we are a simple reliable packet, just send it to the app
if (mBigDataPtr != NULL)
if (mBigDataPtr != nullptr)
{
mUdpConnection->CallbackCorruptPacket(data, dataLen, cUdpCorruptionReasonFragmentExpected);
return;
@@ -687,7 +687,7 @@ void UdpReliableChannel::ProcessPacket(ReliablePacketMode mode, const udp_uchar
else if (mode == cReliablePacketModeFragment)
{
// append onto end of big packet (or create new big packet if not existing already)
if (mBigDataPtr == NULL)
if (mBigDataPtr == nullptr)
{
if (dataLen < 4)
{
@@ -729,7 +729,7 @@ void UdpReliableChannel::ProcessPacket(ReliablePacketMode mode, const udp_uchar
delete[] mBigDataPtr;
mBigDataLen = 0;
mBigDataTargetLen = 0;
mBigDataPtr = NULL;
mBigDataPtr = nullptr;
}
}
}
@@ -767,7 +767,7 @@ void UdpReliableChannel::Ack(udp_int64 reliableId)
int pos = (int)(reliableId % mConfig.maxOutstandingPackets);
PhysicalPacket *entry = &mPhysicalPackets[pos];
if (entry->mDataPtr != NULL) // if this packet has not been acknowledged yet (sometimes we get back two acks for the same packet)
if (entry->mDataPtr != nullptr) // if this packet has not been acknowledged yet (sometimes we get back two acks for the same packet)
{
mNextNeedTime = 0; // something got acked, so we actually need to take the time next time it is offered
@@ -829,14 +829,14 @@ void UdpReliableChannel::Ack(udp_int64 reliableId)
// this packet we have queued has been acknowledged, so delete it from queue
mReliableOutgoingBytes -= entry->mDataLen;
entry->mDataLen = 0;
entry->mDataPtr = NULL;
entry->mDataPtr = nullptr;
entry->mParent->Release();
entry->mParent = NULL;
entry->mParent = nullptr;
// advance the pending ptr until it reaches outgoingId or an entry that has yet to acknowledged
while (mReliableOutgoingPendingId < mReliableOutgoingId)
{
if (mPhysicalPackets[mReliableOutgoingPendingId % mConfig.maxOutstandingPackets].mDataPtr != NULL)
if (mPhysicalPackets[mReliableOutgoingPendingId % mConfig.maxOutstandingPackets].mDataPtr != nullptr)
break;
mReliableOutgoingPendingId++;
}
@@ -855,25 +855,25 @@ void UdpReliableChannel::Ack(udp_int64 reliableId)
UdpReliableChannel::IncomingQueueEntry::IncomingQueueEntry()
{
mPacket = NULL;
mPacket = nullptr;
mMode = UdpReliableChannel::cReliablePacketModeReliable;
}
UdpReliableChannel::IncomingQueueEntry::~IncomingQueueEntry()
{
if (mPacket != NULL)
if (mPacket != nullptr)
mPacket->Release();
}
UdpReliableChannel::PhysicalPacket::PhysicalPacket()
{
mParent = NULL;
mParent = nullptr;
}
UdpReliableChannel::PhysicalPacket::~PhysicalPacket()
{
if (mParent != NULL)
if (mParent != nullptr)
mParent->Release();
}
@@ -64,7 +64,7 @@ class UdpReliableChannel
void ProcessPacket(ReliablePacketMode mode, const udp_uchar *data, int dataLen);
bool PullDown(int windowSpaceLeft);
void FlushCoalesce();
void SendCoalesce(const udp_uchar *data, int dataLen, const udp_uchar *data2 = NULL, int dataLen2 = 0);
void SendCoalesce(const udp_uchar *data, int dataLen, const udp_uchar *data2 = nullptr, int dataLen2 = 0);
void QueueLogicalPacket(LogicalPacket *packet);
UdpReliableConfig mConfig;
@@ -138,7 +138,7 @@ inline int UdpReliableChannel::TotalPendingBytes() const
inline void UdpReliableChannel::ClearBufferedAck()
{
mBufferedAckPtr = NULL;
mBufferedAckPtr = nullptr;
}
inline udp_int64 UdpReliableChannel::GetReliableOutgoingId(int reliableStamp) const