git.stg.codes
/
stg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Handle string for encryption properly.
[stg.git]
/
projects
/
rscriptd
/
listener.cpp
diff --git
a/projects/rscriptd/listener.cpp
b/projects/rscriptd/listener.cpp
index 9e03988c2f116cd9e8283b372c49afe3f9a6beb1..cc2a05603c88666c9d421fbf752a0e95160563f6 100644
(file)
--- a/
projects/rscriptd/listener.cpp
+++ b/
projects/rscriptd/listener.cpp
@@
-49,10
+49,9
@@
LISTENER::LISTENER()
receiverStopped(true),
processorStopped(true),
userTimeout(0),
receiverStopped(true),
processorStopped(true),
userTimeout(0),
- listenSocket(0)
+ listenSocket(0),
+ version("rscriptd listener v.1.2")
{
{
-version = "rscriptd listener v.1.2";
-
pthread_mutex_init(&mutex, NULL);
}
//-----------------------------------------------------------------------------
pthread_mutex_init(&mutex, NULL);
}
//-----------------------------------------------------------------------------
@@
-102,14
+101,16
@@
running = false;
printfd(__FILE__, "LISTENER::Stop()\n");
printfd(__FILE__, "LISTENER::Stop()\n");
-usleep(500000);
+struct timespec ts = {0, 500000000};
+nanosleep(&ts, NULL);
if (!processorStopped)
{
//5 seconds to thread stops itself
for (int i = 0; i < 25 && !processorStopped; i++)
{
if (!processorStopped)
{
//5 seconds to thread stops itself
for (int i = 0; i < 25 && !processorStopped; i++)
{
- usleep(200000);
+ struct timespec ts = {0, 200000000};
+ nanosleep(&ts, NULL);
}
//after 5 seconds waiting thread still running. now killing it
}
//after 5 seconds waiting thread still running. now killing it
@@
-130,7
+131,8
@@
if (!receiverStopped)
//5 seconds to thread stops itself
for (int i = 0; i < 25 && !receiverStopped; i++)
{
//5 seconds to thread stops itself
for (int i = 0; i < 25 && !receiverStopped; i++)
{
- usleep(200000);
+ struct timespec ts = {0, 200000000};
+ nanosleep(&ts, NULL);
}
//after 5 seconds waiting thread still running. now killing it
}
//after 5 seconds waiting thread still running. now killing it
@@
-162,6
+164,10
@@
return false;
//-----------------------------------------------------------------------------
void * LISTENER::Run(void * d)
{
//-----------------------------------------------------------------------------
void * LISTENER::Run(void * d)
{
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
LISTENER * listener = static_cast<LISTENER *>(d);
listener->Runner();
LISTENER * listener = static_cast<LISTENER *>(d);
listener->Runner();
@@
-183,6
+189,10
@@
receiverStopped = true;
//-----------------------------------------------------------------------------
void * LISTENER::RunProcessor(void * d)
{
//-----------------------------------------------------------------------------
void * LISTENER::RunProcessor(void * d)
{
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
LISTENER * listener = static_cast<LISTENER *>(d);
listener->ProcessorRunner();
LISTENER * listener = static_cast<LISTENER *>(d);
listener->ProcessorRunner();
@@
-196,7
+206,8
@@
processorStopped = false;
while (running)
{
while (running)
{
- usleep(500000);
+ struct timespec ts = {0, 500000000};
+ nanosleep(&ts, NULL);
if (!pending.empty())
ProcessPending();
ProcessTimeouts();
if (!pending.empty())
ProcessPending();
ProcessTimeouts();
@@
-243,7
+254,7
@@
bool LISTENER::RecvPacket()
struct iovec iov[2];
char buffer[RS_MAX_PACKET_LEN];
struct iovec iov[2];
char buffer[RS_MAX_PACKET_LEN];
-RS
_
PACKET_HEADER packetHead;
+RS
::
PACKET_HEADER packetHead;
iov[0].iov_base = reinterpret_cast<char *>(&packetHead);
iov[0].iov_len = sizeof(packetHead);
iov[0].iov_base = reinterpret_cast<char *>(&packetHead);
iov[0].iov_len = sizeof(packetHead);
@@
-300,7
+311,7
@@
else if (packetHead.packetType == RS_DISCONNECT_PACKET)
}
}
}
}
-STG_LOCKER lock(&mutex
, __FILE__, __LINE__
);
+STG_LOCKER lock(&mutex);
pending.push_back(data);
return false;
pending.push_back(data);
return false;
@@
-308,7
+319,7
@@
return false;
//-----------------------------------------------------------------------------
bool LISTENER::GetParams(char * buffer, UserData & data)
{
//-----------------------------------------------------------------------------
bool LISTENER::GetParams(char * buffer, UserData & data)
{
-RS
_
PACKET_TAIL packetTail;
+RS
::
PACKET_TAIL packetTail;
Decrypt(&ctxS, (char *)&packetTail, buffer, sizeof(packetTail) / 8);
Decrypt(&ctxS, (char *)&packetTail, buffer, sizeof(packetTail) / 8);
@@
-318,7
+329,7
@@
if (strncmp((char *)packetTail.magic, RS_ID, RS_MAGIC_LEN))
return true;
}
return true;
}
-std::stringstream params;
+std::
o
stringstream params;
params << "\"" << data.login << "\" "
<< inet_ntostring(data.ip) << " "
<< data.id << " "
params << "\"" << data.login << "\" "
<< inet_ntostring(data.ip) << " "
<< data.id << " "
@@
-344,40
+355,63
@@
while (it != pending.end() && count < 256)
);
if (it->type == PendingData::CONNECT)
{
);
if (it->type == PendingData::CONNECT)
{
+ printfd(__FILE__, "Connect packet\n");
if (uit == users.end() || uit->login != it->login)
{
if (uit == users.end() || uit->login != it->login)
{
+ printfd(__FILE__, "Connect new user '%s'\n", it->login.c_str());
// Add new user
Connect(*it);
users.insert(uit, AliveData(static_cast<UserData>(*it)));
}
else if (uit->login == it->login)
{
// Add new user
Connect(*it);
users.insert(uit, AliveData(static_cast<UserData>(*it)));
}
else if (uit->login == it->login)
{
+ printfd(__FILE__, "Update existing user '%s'\n", it->login.c_str());
// Update already existing user
time(&uit->lastAlive);
uit->params = it->params;
}
// Update already existing user
time(&uit->lastAlive);
uit->params = it->params;
}
+ else
+ {
+ printfd(__FILE__, "Hmmm... Strange connect for '%s'\n", it->login.c_str());
+ }
}
else if (it->type == PendingData::ALIVE)
{
}
else if (it->type == PendingData::ALIVE)
{
+ printfd(__FILE__, "Alive packet\n");
if (uit != users.end() && uit->login == it->login)
{
if (uit != users.end() && uit->login == it->login)
{
+ printfd(__FILE__, "Alive user '%s'\n", it->login.c_str());
// Update existing user
time(&uit->lastAlive);
}
// Update existing user
time(&uit->lastAlive);
}
+ else
+ {
+ printfd(__FILE__, "Alive user '%s' is not found\n", it->login.c_str());
+ }
}
else if (it->type == PendingData::DISCONNECT)
{
}
else if (it->type == PendingData::DISCONNECT)
{
+ printfd(__FILE__, "Disconnect packet\n");
if (uit != users.end() && uit->login == it->login.c_str())
{
if (uit != users.end() && uit->login == it->login.c_str())
{
+ printfd(__FILE__, "Disconnect user '%s'\n", it->login.c_str());
// Disconnect existing user
Disconnect(*uit);
users.erase(uit);
}
// Disconnect existing user
Disconnect(*uit);
users.erase(uit);
}
+ else
+ {
+ printfd(__FILE__, "Cannot find user '%s' for disconnect\n", it->login.c_str());
+ }
+ }
+ else
+ {
+ printfd(__FILE__, "Unknown packet type\n");
}
++it;
++count;
}
}
++it;
++count;
}
-STG_LOCKER lock(&mutex
, __FILE__, __LINE__
);
+STG_LOCKER lock(&mutex);
pending.erase(pending.begin(), it);
}
//-----------------------------------------------------------------------------
pending.erase(pending.begin(), it);
}
//-----------------------------------------------------------------------------
@@
-443,7
+477,7
@@
else
return false;
}
//-----------------------------------------------------------------------------
return false;
}
//-----------------------------------------------------------------------------
-bool LISTENER::CheckHeader(const RS
_
PACKET_HEADER & header) const
+bool LISTENER::CheckHeader(const RS
::
PACKET_HEADER & header) const
{
if (strncmp((char *)header.magic, RS_ID, RS_MAGIC_LEN))
{
{
if (strncmp((char *)header.magic, RS_ID, RS_MAGIC_LEN))
{