]> git.stg.codes - stg.git/blobdiff - projects/rscriptd/listener.cpp
Remove 'stg' prefixes from headers and add it to libraries
[stg.git] / projects / rscriptd / listener.cpp
index aca5da445c4dec4346d4c38dc9cd0374313f7c56..47adc93b82aed9c29491f5f7532a077c415b9d45 100644 (file)
 #include <sstream>
 #include <algorithm>
 
+#include "stg/script_executer.h"
+#include "stg/locker.h"
+#include "stg/common.h"
 #include "listener.h"
-#include "script_executer.h"
-#include "stg_locker.h"
-#include "common.h"
 
 void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password);
 void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
@@ -162,9 +162,9 @@ return false;
 //-----------------------------------------------------------------------------
 void * LISTENER::Run(void * d)
 {
-LISTENER * ia = static_cast<LISTENER *>(d);
+LISTENER * listener = static_cast<LISTENER *>(d);
 
-ia->Runner();
+listener->Runner();
 
 return NULL;
 }
@@ -183,9 +183,9 @@ receiverStopped = true;
 //-----------------------------------------------------------------------------
 void * LISTENER::RunProcessor(void * d)
 {
-LISTENER * ia = static_cast<LISTENER *>(d);
+LISTENER * listener = static_cast<LISTENER *>(d);
 
-ia->ProcessorRunner();
+listener->ProcessorRunner();
 
 return NULL;
 }
@@ -215,8 +215,6 @@ if (listenSocket < 0)
     return true;
     }
 
-printfd(__FILE__, "Port: %d\n", port);
-
 struct sockaddr_in listenAddr;
 listenAddr.sin_family = AF_INET;
 listenAddr.sin_port = htons(port);
@@ -250,7 +248,7 @@ RS_PACKET_HEADER packetHead;
 iov[0].iov_base = reinterpret_cast<char *>(&packetHead);
 iov[0].iov_len = sizeof(packetHead);
 iov[1].iov_base = buffer;
-iov[1].iov_len = sizeof(buffer);
+iov[1].iov_len = sizeof(buffer) - sizeof(packetHead);
 
 size_t dataLen = 0;
 while (dataLen < sizeof(buffer))
@@ -321,7 +319,7 @@ if (strncmp((char *)packetTail.magic, RS_ID, RS_MAGIC_LEN))
     }
 
 std::stringstream params;
-params << data.login << " "
+params << "\"" << data.login << "\" "
        << inet_ntostring(data.ip) << " "
        << data.id << " "
        << (char *)packetTail.params;
@@ -333,16 +331,10 @@ return false;
 //-----------------------------------------------------------------------------
 void LISTENER::ProcessPending()
 {
-std::list<PendingData> localPending;
-
-    {
-    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-    printfd(__FILE__, "Pending data size: %d\n", pending.size());
-    localPending.swap(pending);
-    }
-
-std::list<PendingData>::iterator it(localPending.begin());
-while (it != localPending.end())
+std::list<PendingData>::iterator it(pending.begin());
+size_t count = 0;
+printfd(__FILE__, "Pending: %d\n", pending.size());
+while (it != pending.end() && count < 256)
     {
     std::vector<AliveData>::iterator uit(
             std::lower_bound(
@@ -383,7 +375,10 @@ while (it != localPending.end())
             }
         }
     ++it;
+    ++count;
     }
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+pending.erase(pending.begin(), it);
 }
 //-----------------------------------------------------------------------------
 void LISTENER::ProcessTimeouts()