- NULL/nullptr round for Common
authorAkiko <akiko@linux-addicted.net>
Mon, 1 Jun 2015 08:01:46 +0000 (10:01 +0200)
committerAkiko <akiko@linux-addicted.net>
Mon, 1 Jun 2015 08:01:46 +0000 (10:01 +0200)
TinNS/Source/Common/Message.cxx
TinNS/Source/Common/Message.hxx
TinNS/Source/Common/Netcode.cxx
TinNS/Source/Common/RegEx.cxx
TinNS/Source/Common/RegEx.hxx

index e3bb8ef..af263fa 100644 (file)
@@ -51,7 +51,7 @@ void PMessage::GetMsgBuffer(uint16_t nRequestedSize) //no optimisation to try to
   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];
@@ -63,9 +63,9 @@ void PMessage::GetMsgBuffer(uint16_t nRequestedSize) //no optimisation to try to
       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
@@ -265,12 +265,12 @@ PMessage& PMessage::operator = (PMessage& nMessage)
       ReleaseMsgBuffer();
       GetMsgBuffer(nMessage.mMaxSize);
     }
-  
+
     mUsedSize = nMessage.mUsedSize;
     mNextByteOffset = nMessage.mNextByteOffset;
     memcpy((void*)(mData->mBuffer), (void*)(nMessage.mData->mBuffer), (size_t)mMaxSize);
   }
-  
+
   return *this;
 }
 
@@ -279,7 +279,7 @@ PMessage* PMessage::GetChunk(uint16_t StartOffset, uint16_t ChunkSize, uint16_t
 {
   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);
@@ -362,7 +362,7 @@ void PMessage::ListPools()
   {
     iBuff = smMsgPoolHead[i];
     n = 0;
-    while (iBuff != NULL)
+    while (iBuff != nullptr)
     {
       ++n;
       iBuff = iBuff->mNextMsgData;
@@ -383,11 +383,11 @@ void PMessage::DumpPools()
 
   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;
index 0ff3623..10ac636 100644 (file)
@@ -3,7 +3,7 @@
 #include <cstdint>
 
 #define MESSAGE_SIZES_LIST 32, 64, 128, 256, 512, 1024, 4096
-#define MESSAGE_POOL_INIT NULL, NULL, NULL, NULL, NULL, NULL, NULL
+#define MESSAGE_POOL_INIT nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr
 #define MESSAGE_POOL_COUNT_INIT 0, 0, 0, 0, 0, 0, 0
 #define MESSAGE_SIZES_NB 7
 #define MESSAGE_ALLOC_NB 4
index 47a968f..e1cdec8 100644 (file)
@@ -20,10 +20,10 @@ ConnectionTCP::ConnectionTCP(int sockfd, struct sockaddr_in addr, ServerSocket*
     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()
@@ -58,7 +58,7 @@ char* ConnectionTCP::getRemoteAddress()
 
 bool ConnectionTCP::timeOut() const
 {
-    time_t now = std::time(NULL);
+    time_t now = std::time(nullptr);
     if((now-mLastActive) >= mTimeOutValue)
         return true;
 
@@ -70,7 +70,7 @@ PMessage* ConnectionTCP::GetMessage()
   PMessage* RetVal;
 
   if (mQueueIn.empty())
-    RetVal = NULL;
+    RetVal = nullptr;
   else
   {
     RetVal = mQueueIn.front();
@@ -102,7 +102,7 @@ bool ConnectionTCP::update() // non optimal read-algorithm atm, but well ... :p
   if(mServerSocket->isDataAvailable(mSockfd))
   {
 //Console->Print("ConnectionTCP::update() - IN Data avail");
-    if (mReceiveBufferMsg == NULL)
+    if (mReceiveBufferMsg == nullptr)
     {
       mReceiveBufferMsg = new PMessage(RECVBUFFERSIZE);
     }
@@ -115,7 +115,7 @@ bool ConnectionTCP::update() // non optimal read-algorithm atm, but well ... :p
 //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())
       {
@@ -145,7 +145,7 @@ bool ConnectionTCP::update() // non optimal read-algorithm atm, but well ... :p
               }
               else
               {
-                tmpMsg = NULL;
+                tmpMsg = nullptr;
               }
 
               delete mReceiveBufferMsg;
@@ -202,7 +202,7 @@ bool ConnectionTCP::update() // non optimal read-algorithm atm, but well ... :p
     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
         }
@@ -237,7 +237,7 @@ int ConnectionTCP::getRecvBufferSize()
 
 int ConnectionTCP::getSendBufferSize()
 {
-  if(mSendBufferMsg == NULL)
+  if(mSendBufferMsg == nullptr)
     return 0;
   else
     return mSendBufferMsg->GetSize();
@@ -246,10 +246,10 @@ int ConnectionTCP::getSendBufferSize()
 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");
     }
 }
@@ -261,7 +261,7 @@ const uint8_t* ConnectionTCP::read(int* size)
   if (mQueueIn.empty() || !size)
   {
 //Console->Print("ConnectionTCP::read() - no more packet");
-    return NULL;
+    return nullptr;
   }
 
   tmpMsg = mQueueIn.front();
@@ -275,7 +275,7 @@ const uint8_t* ConnectionTCP::read(int* size)
     if (mQueueIn.empty())
     {
 //Console->Print("ConnectionUDP::read() - no more packet");
-      return NULL;
+      return nullptr;
      }
     tmpMsg = mQueueIn.front();
       _size = tmpMsg->GetSize();
@@ -300,7 +300,7 @@ const uint8_t* ConnectionTCP::read(int* size)
 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);
@@ -355,7 +355,7 @@ ConnectionUDP::ConnectionUDP(int sockfd, int port, int remoteadress, int remotep
     }
 
     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
@@ -376,7 +376,7 @@ ConnectionUDP::ConnectionUDP(int sockfd, int port, int remoteadress, int remotep
 
     //    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;
@@ -431,7 +431,7 @@ void ConnectionUDP::InsertUDPMessage(PMessage* nMsg)
 // 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;
@@ -562,7 +562,7 @@ void ConnectionUDP::ReSendUDPMessage(uint16_t nUDP_ID)
 
 bool ConnectionUDP::timeOut() const
 {
-    time_t now = std::time(NULL);
+    time_t now = std::time(nullptr);
     if((now-mLastActive) >= mTimeOutValue)
         return true;
 
@@ -579,7 +579,7 @@ PMessage* ConnectionUDP::GetMessage()
     PMessage* RetVal;
 
     if (mQueueIn.empty())
-        RetVal = NULL;
+        RetVal = nullptr;
     else
     {
         RetVal = mQueueIn.front();
@@ -646,7 +646,7 @@ bool ConnectionUDP::update()
             if(numBytes > 0)
             {
                 //Console->Print(GREEN, BLACK, "ConnectionUDP::update() - Data sent");
-                mLastActive = std::time(NULL);
+                mLastActive = std::time(nullptr);
                 if(gotVIPmsg == true)
                 {
                     mVIPQueueOut.pop();
@@ -694,7 +694,7 @@ bool ConnectionUDP::update()
             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 :"); // ====
@@ -752,7 +752,7 @@ int ConnectionUDP::getRecvBufferSize()
 
 int ConnectionUDP::getSendBufferSize()
 {
-    if(mSendBufferMsg == NULL)
+    if(mSendBufferMsg == nullptr)
         return 0;
     else
         return mSendBufferMsg->GetSize();
@@ -761,10 +761,10 @@ int ConnectionUDP::getSendBufferSize()
 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");
     }
 }
@@ -776,7 +776,7 @@ const uint8_t *ConnectionUDP::read(int *size)
     if (mQueueIn.empty() || !size)
     {
         //Console->Print("ConnectionUDP::read() - no more packet");
-        return NULL;
+        return nullptr;
     }
 
     tmpMsg = mQueueIn.front();
@@ -790,7 +790,7 @@ const uint8_t *ConnectionUDP::read(int *size)
         if (mQueueIn.empty())
         {
             //Console->Print("ConnectionUDP::read() - no more packet");
-            return NULL;
+            return nullptr;
         }
         tmpMsg = mQueueIn.front();
         _size = tmpMsg->GetSize();
@@ -815,7 +815,7 @@ const uint8_t *ConnectionUDP::read(int *size)
 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);
@@ -978,7 +978,7 @@ void ServerSocket::update()
 
     // 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");
     }
@@ -1058,7 +1058,7 @@ ConnectionUDP* ServerSocket::getUDPConnection(uint32_t remoteadress, int32_t rem
     if ((udpSockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
     {
         perror("udp-socket");
-        return NULL;
+        return nullptr;
     }
 
     struct sockaddr_in my_addr;
@@ -1080,13 +1080,13 @@ ConnectionUDP* ServerSocket::getUDPConnection(uint32_t remoteadress, int32_t rem
         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;
       }
     }
 
index da725cc..f6f4687 100644 (file)
@@ -6,14 +6,14 @@ RegEx::RegEx(const char * regex, int options)
    const char * error;
    int          erroffset;
 
-   re = pcre_compile(regex, options, &error, &erroffset, NULL);
-   if (re == NULL)
+   re = pcre_compile(regex, options, &error, &erroffset, nullptr);
+   if (re == nullptr)
       throw error;
    pe = pcre_study(re, 0, &error);
    pcre_fullinfo(re, pe, PCRE_INFO_CAPTURECOUNT, &substrcount);
    substrcount++;
    ovector = new int[3*substrcount];
-   matchlist = NULL;
+   matchlist = nullptr;
 }
 
 RegEx::~RegEx()
@@ -41,7 +41,7 @@ const char * RegEx::Match(int i)
 {
    if (i < 0)
       return lastsubject;
-   if (matchlist == NULL)
+   if (matchlist == nullptr)
       pcre_get_substring_list(lastsubject, ovector, substrcount, &matchlist);
    return matchlist[i];
 }
index d012af6..afd681d 100644 (file)
@@ -21,7 +21,7 @@ private:
         if (matchlist)
         {
             pcre_free_substring_list(matchlist);
-            matchlist = NULL;
+            matchlist = nullptr;
         }
     }