X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=win%2Finspircd_namedpipe.cpp;h=632c2cca0084ee836f79e7ea2ae62bd3d2a65cfe;hb=8e662f620239cc42136c7a6526cc94eac3db1f59;hp=f86b70c1e6be27fde9c4a6bcf129eaca80a8aa19;hpb=a5f65582fe5d110f522c3e1ad2ba666eb1791f73;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/win/inspircd_namedpipe.cpp b/win/inspircd_namedpipe.cpp index f86b70c1e..632c2cca0 100644 --- a/win/inspircd_namedpipe.cpp +++ b/win/inspircd_namedpipe.cpp @@ -1,3 +1,22 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2008 Craig Edwards + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + #include "inspircd.h" #include "threadengine.h" #include "inspircd_namedpipe.h" @@ -6,35 +25,37 @@ #include -IPCThread::IPCThread(InspIRCd* Instance) : Thread(), ServerInstance(Instance) +IPCThread::IPCThread() { + if (!initwmi()) + ServerInstance->Logs->Log("IPC", DEBUG, "Could not initialise WMI. CPU percantage reports will not be available."); } IPCThread::~IPCThread() { - + donewmi(); } void IPCThread::Run() { LPTSTR Pipename = "\\\\.\\pipe\\InspIRCdStatus"; - while (GetExitFlag() == false) + while (GetExitFlag() == false) { Pipe = CreateNamedPipe (Pipename, - PIPE_ACCESS_DUPLEX, // read/write access - PIPE_TYPE_MESSAGE | // message type pipe - PIPE_READMODE_MESSAGE | // message-read mode - PIPE_WAIT, // blocking mode - PIPE_UNLIMITED_INSTANCES, // max. instances - MAXBUF, // output buffer size - MAXBUF, // input buffer size - 1000, // client time-out - NULL); // no security attribute + PIPE_ACCESS_DUPLEX, // read/write access + PIPE_TYPE_MESSAGE | // message type pipe + PIPE_READMODE_MESSAGE | // message-read mode + PIPE_WAIT, // blocking mode + PIPE_UNLIMITED_INSTANCES, // max. instances + MAXBUF, // output buffer size + MAXBUF, // input buffer size + 1000, // client time-out + NULL); // no security attribute if (Pipe == INVALID_HANDLE_VALUE) { - SleepEx(500, true); + SleepEx(10, true); continue; } @@ -63,7 +84,6 @@ void IPCThread::Run() std::stringstream stat; DWORD Written = 0; float kbitpersec_in, kbitpersec_out, kbitpersec_total; - char kbitpersec_in_s[30], kbitpersec_out_s[30], kbitpersec_total_s[30]; PROCESS_MEMORY_COUNTERS MemCounters; @@ -81,9 +101,11 @@ void IPCThread::Run() stat << "pid " << GetProcessId(GetCurrentProcess()) << std::endl; stat << "request " << oldrequest << std::endl; stat << "result " << this->GetResult() << std::endl; - stat << "kbitspersectotal " << kbitpersec_total_s << std::endl; - stat << "kbitspersecout " << kbitpersec_out_s << std::endl; - stat << "kbitspersecin " << kbitpersec_in_s << std::endl; + stat << "kbitspersectotal " << kbitpersec_total << std::endl; + stat << "kbitspersecout " << kbitpersec_out << std::endl; + stat << "kbitspersecin " << kbitpersec_in << std::endl; + stat << "uptime " << ServerInstance->Time() - ServerInstance->startup_time << std::endl; + stat << "cpu " << getcpu() << std::endl; if (HaveMemoryStats) { stat << "workingset " << MemCounters.WorkingSetSize << std::endl; @@ -124,45 +146,51 @@ void IPCThread::SetResult(int newresult) } -IPC::IPC(InspIRCd* Srv) : ServerInstance(Srv) -{ - /* The IPC pipe is threaded */ - thread = new IPCThread(Srv); - Srv->Threads->Create(thread); -} - -void IPC::Check() -{ - switch (thread->GetStatus()) - { - case 'N': - /* No-Operation */ - thread->SetResult(0); - thread->ClearStatus(); - break; - case '1': - /* Rehash */ - ServerInstance->Rehash("due to rehash command from GUI"); - thread->SetResult(0); - thread->ClearStatus(); - break; - case '2': - /* Shutdown */ - thread->SetResult(0); - thread->ClearStatus(); - ServerInstance->Exit(EXIT_STATUS_NOERROR); - break; - case '3': - /* Restart */ - thread->SetResult(0); - thread->ClearStatus(); - ServerInstance->Restart("Restarting due to command from GUI"); - break; - } -} - -IPC::~IPC() -{ - thread->SetExitFlag(); - delete thread; -} \ No newline at end of file +IPC::IPC() +{ + /* The IPC pipe is threaded */ + thread = new IPCThread(); + ServerInstance->Threads->Start(thread); +} + +void IPC::Check() +{ + switch (thread->GetStatus()) + { + case 'N': + /* No-Operation */ + thread->SetResult(0); + thread->ClearStatus(); + break; + case '1': + /* Rehash */ + ServerInstance->Rehash("due to rehash command from GUI"); + thread->SetResult(0); + thread->ClearStatus(); + break; + case '2': + /* Shutdown */ + thread->SetResult(0); + thread->ClearStatus(); + ServerInstance->Exit(EXIT_STATUS_NOERROR); + break; + case '3': + /* Restart */ + thread->SetResult(0); + thread->ClearStatus(); + ServerInstance->Restart("Restarting due to command from GUI"); + break; + case '4': + /* Toggle debug */ + thread->SetResult(0); + thread->ClearStatus(); + ServerInstance->Config->cmdline.forcedebug = !ServerInstance->Config->cmdline.forcedebug; + break; + } +} + +IPC::~IPC() +{ + thread->SetExitFlag(); + delete thread; +}