mMaxSize = smMsgSizes[mPoolId];
//Console->Print("Using Pool n� %d (size %d)", mPoolId, smMsgSizes[mPoolId]);
- if ((mData = smMsgPoolHead[mPoolId]) == NULL)
+ if ((mData = smMsgPoolHead[mPoolId]) == nullptr)
{
//Console->Print("Pool Empty, creating new buffers");
mData = new PMsgData[MESSAGE_ALLOC_NB];
smMsgPoolHead[mPoolId] = mData + 1;
for (int i = 1; i < MESSAGE_ALLOC_NB-1; i++)
mData[i].mNextMsgData = mData + i + 1;
- mData[MESSAGE_ALLOC_NB-1].mNextMsgData = NULL;
+ mData[MESSAGE_ALLOC_NB-1].mNextMsgData = nullptr;
}
-
+
smMsgPoolCount[mPoolId] += MESSAGE_ALLOC_NB;
}
else
ReleaseMsgBuffer();
GetMsgBuffer(nMessage.mMaxSize);
}
-
+
mUsedSize = nMessage.mUsedSize;
mNextByteOffset = nMessage.mNextByteOffset;
memcpy((void*)(mData->mBuffer), (void*)(nMessage.mData->mBuffer), (size_t)mMaxSize);
}
-
+
return *this;
}
{
uint16_t ReqStartOffset = StartOffset + ChunkNumber * ChunkSize;
if (ReqStartOffset >= mUsedSize)
- return NULL;
+ return nullptr;
uint16_t RealChunkSize = (ChunkSize < mUsedSize - ReqStartOffset) ? ChunkSize : mUsedSize - ReqStartOffset;
PMessage* MsgChunk = new PMessage(RealChunkSize);
{
iBuff = smMsgPoolHead[i];
n = 0;
- while (iBuff != NULL)
+ while (iBuff != nullptr)
{
++n;
iBuff = iBuff->mNextMsgData;
for (int i = 0; i < MESSAGE_SIZES_NB; i++)
{
- if ((iBuff = smMsgPoolHead[i]) != NULL)
+ if ((iBuff = smMsgPoolHead[i]) != nullptr)
{
n = 0;
Console->Print("\tBuffer pool %d (size %d):", i, smMsgSizes[i]);
- while (iBuff != NULL)
+ while (iBuff != nullptr)
{
Console->Print("\t\t%d : 0x%08x", n++, iBuff);
iBuff = iBuff->mNextMsgData;
mbConnected = true; // client obviously is connected at creation...
mTimeOutValue = DEFAULT_TCP_TIMEOUT;
- mLastActive = std::time(NULL);
+ mLastActive = std::time(nullptr);
- mReceiveBufferMsg = NULL;
- mSendBufferMsg = NULL;
+ mReceiveBufferMsg = nullptr;
+ mSendBufferMsg = nullptr;
}
ConnectionTCP::~ConnectionTCP()
bool ConnectionTCP::timeOut() const
{
- time_t now = std::time(NULL);
+ time_t now = std::time(nullptr);
if((now-mLastActive) >= mTimeOutValue)
return true;
PMessage* RetVal;
if (mQueueIn.empty())
- RetVal = NULL;
+ RetVal = nullptr;
else
{
RetVal = mQueueIn.front();
if(mServerSocket->isDataAvailable(mSockfd))
{
//Console->Print("ConnectionTCP::update() - IN Data avail");
- if (mReceiveBufferMsg == NULL)
+ if (mReceiveBufferMsg == nullptr)
{
mReceiveBufferMsg = new PMessage(RECVBUFFERSIZE);
}
//Console->Print(GREEN, BLACK, "ConnectionTCP::update() - Data received");
mbConnected = true;
mReceiveBufferMsg->ForceSize(DataSize + numBytes);
- mLastActive = std::time(NULL);
+ mLastActive = std::time(nullptr);
while(mReceiveBufferMsg && mReceiveBufferMsg->GetSize())
{
}
else
{
- tmpMsg = NULL;
+ tmpMsg = nullptr;
}
delete mReceiveBufferMsg;
else if(numBytes > 0)
{
//Console->Print(GREEN, BLACK, "ConnectionTCP::update() - Data sent");
- mLastActive = std::time(NULL);
+ mLastActive = std::time(nullptr);
mQueueOut.pop(); // message written, we can remove it from queue
delete tmpMsg; // and delete the message
}
int ConnectionTCP::getSendBufferSize()
{
- if(mSendBufferMsg == NULL)
+ if(mSendBufferMsg == nullptr)
return 0;
else
return mSendBufferMsg->GetSize();
void ConnectionTCP::flushSendBuffer()
{
//Console->Print("ConnectionTCP::flushSendBuffer()");
- if((mSendBufferMsg != NULL) && (mSendBufferMsg->GetSize() > 0))
+ if((mSendBufferMsg != nullptr) && (mSendBufferMsg->GetSize() > 0))
{
SendMessage(mSendBufferMsg);
- mSendBufferMsg = NULL;
+ mSendBufferMsg = nullptr;
//Console->Print(YELLOW, BLACK, "ConnectionTCP::flushSendBuffer() - Data flushed");
}
}
if (mQueueIn.empty() || !size)
{
//Console->Print("ConnectionTCP::read() - no more packet");
- return NULL;
+ return nullptr;
}
tmpMsg = mQueueIn.front();
if (mQueueIn.empty())
{
//Console->Print("ConnectionUDP::read() - no more packet");
- return NULL;
+ return nullptr;
}
tmpMsg = mQueueIn.front();
_size = tmpMsg->GetSize();
int ConnectionTCP::write(const void* data, int size)
{
// data is stored in mSendBufferMsg. Gets queued in next flushSendBuffer() or update()
- if (mSendBufferMsg == NULL)
+ if (mSendBufferMsg == nullptr)
{
//Console->Print("ConnectionTCP::write() creating new mSendBufferMsg");
mSendBufferMsg = new PMessage(SENDBUFFERSIZE);
}
mTimeOutValue = DEFAULT_UDP_TIMEOUT;
- mLastActive = std::time(NULL);
+ mLastActive = std::time(nullptr);
mRemoteAddr.sin_family = AF_INET; // host byte order
mRemoteAddr.sin_port = htons(remoteport); // short, network byte order
// mRemoteAddr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
// memset(&(mRemoteAddr.sin_zero), '\0', 8); // zero the rest of the struct
- mSendBufferMsg = NULL;
+ mSendBufferMsg = nullptr;
mUDP_ID = 0;
mSessionID = SESSION_UDP_OFFSET;
// 13 07 00 F2 00 05 03 02 00 11 11 05 03 03 00 11 11 05 03 04 00 11 11 05 03 05 00 11 11 05 03 06 00 11 11 05 03 07 00 11 11
// Grab submessages from packet, check if message is 0x03 commandset. If not, dont add message
- PMessage* tWorkMsg = NULL;
+ PMessage* tWorkMsg = nullptr;
uint16_t tCurPos = 5;
uint8_t tSubMsgLen = 0;
bool ConnectionUDP::timeOut() const
{
- time_t now = std::time(NULL);
+ time_t now = std::time(nullptr);
if((now-mLastActive) >= mTimeOutValue)
return true;
PMessage* RetVal;
if (mQueueIn.empty())
- RetVal = NULL;
+ RetVal = nullptr;
else
{
RetVal = mQueueIn.front();
if(numBytes > 0)
{
//Console->Print(GREEN, BLACK, "ConnectionUDP::update() - Data sent");
- mLastActive = std::time(NULL);
+ mLastActive = std::time(nullptr);
if(gotVIPmsg == true)
{
mVIPQueueOut.pop();
if(numBytes > 0)
{
//Console->Print(GREEN, BLACK, "ConnectionUDP::update() - Data received");
- mLastActive = std::time(NULL);
+ mLastActive = std::time(nullptr);
tmpMsg->ForceSize(numBytes);
mQueueIn.push(tmpMsg);
//tmpMsg->DumpHead("IN Msg :"); // ====
int ConnectionUDP::getSendBufferSize()
{
- if(mSendBufferMsg == NULL)
+ if(mSendBufferMsg == nullptr)
return 0;
else
return mSendBufferMsg->GetSize();
void ConnectionUDP::flushSendBuffer()
{
//Console->Print("ConnectionUDP::flushSendBuffer()");
- if((mSendBufferMsg != NULL) && (mSendBufferMsg->GetSize() > 0))
+ if((mSendBufferMsg != nullptr) && (mSendBufferMsg->GetSize() > 0))
{
SendMessage(mSendBufferMsg);
- mSendBufferMsg = NULL;
+ mSendBufferMsg = nullptr;
//Console->Print(YELLOW, BLACK, "ConnectionUDP::flushSendBuffer() - Data flushed");
}
}
if (mQueueIn.empty() || !size)
{
//Console->Print("ConnectionUDP::read() - no more packet");
- return NULL;
+ return nullptr;
}
tmpMsg = mQueueIn.front();
if (mQueueIn.empty())
{
//Console->Print("ConnectionUDP::read() - no more packet");
- return NULL;
+ return nullptr;
}
tmpMsg = mQueueIn.front();
_size = tmpMsg->GetSize();
int ConnectionUDP::write(const void* data, int size)
{
// data is stored in mSendBufferMsg. Gets queued in next flushSendBuffer() or update()
- if (mSendBufferMsg == NULL)
+ if (mSendBufferMsg == nullptr)
{
//Console->Print("ConnectionUDP::write() creating new mSendBufferMsg");
mSendBufferMsg = new PMessage(SENDBUFFERSIZE);
// select incoming data for tcp & udp
tmp_TimeOut = m_TimeOut; //save m_TimeOut... will be modified by select
- if (select(fdMax+1, &m_ReadSetTCP, NULL, NULL, &tmp_TimeOut) == -1)
+ if (select(fdMax+1, &m_ReadSetTCP, nullptr, nullptr, &tmp_TimeOut) == -1)
{
perror("select");
}
if ((udpSockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
{
perror("udp-socket");
- return NULL;
+ return nullptr;
}
struct sockaddr_in my_addr;
if (Port > maxPort)
{
Console->Print(RED, BLACK,"No more free UDP port in configured range");
- return NULL;
+ return nullptr;
}
}
else
{
perror("udp-bind");
- return NULL;
+ return nullptr;
}
}