X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/bdd372a64811c52e2924c6d391ce6801aabc8ada..97a198bf64f74f1bacd064026e67d7cb40daffa2:/projects/rscriptd/listener.cpp diff --git a/projects/rscriptd/listener.cpp b/projects/rscriptd/listener.cpp index 39e590b6..2761d7f7 100644 --- a/projects/rscriptd/listener.cpp +++ b/projects/rscriptd/listener.cpp @@ -102,14 +102,16 @@ running = false; 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++) { - usleep(200000); + struct timespec ts = {0, 200000000}; + nanosleep(&ts, NULL); } //after 5 seconds waiting thread still running. now killing it @@ -130,7 +132,8 @@ if (!receiverStopped) //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 @@ -162,6 +165,10 @@ return false; //----------------------------------------------------------------------------- void * LISTENER::Run(void * d) { +sigset_t signalSet; +sigfillset(&signalSet); +pthread_sigmask(SIG_BLOCK, &signalSet, NULL); + LISTENER * listener = static_cast(d); listener->Runner(); @@ -183,6 +190,10 @@ receiverStopped = true; //----------------------------------------------------------------------------- void * LISTENER::RunProcessor(void * d) { +sigset_t signalSet; +sigfillset(&signalSet); +pthread_sigmask(SIG_BLOCK, &signalSet, NULL); + LISTENER * listener = static_cast(d); listener->ProcessorRunner(); @@ -196,7 +207,8 @@ processorStopped = false; while (running) { - usleep(500000); + struct timespec ts = {0, 500000000}; + nanosleep(&ts, NULL); if (!pending.empty()) ProcessPending(); ProcessTimeouts(); @@ -243,7 +255,7 @@ bool LISTENER::RecvPacket() struct iovec iov[2]; char buffer[RS_MAX_PACKET_LEN]; -RS_PACKET_HEADER packetHead; +RS::PACKET_HEADER packetHead; iov[0].iov_base = reinterpret_cast(&packetHead); iov[0].iov_len = sizeof(packetHead); @@ -308,7 +320,7 @@ return false; //----------------------------------------------------------------------------- bool LISTENER::GetParams(char * buffer, UserData & data) { -RS_PACKET_TAIL packetTail; +RS::PACKET_TAIL packetTail; Decrypt(&ctxS, (char *)&packetTail, buffer, sizeof(packetTail) / 8); @@ -318,7 +330,7 @@ if (strncmp((char *)packetTail.magic, RS_ID, RS_MAGIC_LEN)) return true; } -std::stringstream params; +std::ostringstream params; params << "\"" << data.login << "\" " << inet_ntostring(data.ip) << " " << data.id << " " @@ -443,7 +455,7 @@ else 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)) { @@ -456,34 +468,6 @@ if (strncmp((char *)header.protoVer, "02", RS_PROTO_VER_LEN)) return false; } //----------------------------------------------------------------------------- -bool LISTENER::WaitPackets(int sd) const -{ -fd_set rfds; -FD_ZERO(&rfds); -FD_SET(sd, &rfds); - -struct timeval tv; -tv.tv_sec = 0; -tv.tv_usec = 500000; - -int res = select(sd + 1, &rfds, NULL, NULL, &tv); -if (res == -1) // Error - { - if (errno != EINTR) - { - printfd(__FILE__, "Error on select: '%s'\n", strerror(errno)); - } - return false; - } - -if (res == 0) // Timeout - { - return false; - } - -return true; -} -//----------------------------------------------------------------------------- inline void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) {