From afe99da316b6f63900df2bd8711ab515f4977f6a Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 15 Jun 2008 16:21:09 +0000 Subject: Base stuff for named pipe IPC git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9910 e03df62e-2008-0410-955e-edbf42e46eb7 --- win/configure.cpp | 5 +-- win/inspircdVC80.vcproj | 8 +++++ win/inspircd_namedpipe.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++ win/inspircd_namedpipe.h | 40 +++++++++++++++++++++++ win/inspircd_win32wrapper.cpp | 23 ++----------- win/inspircd_win32wrapper.h | 11 ------- 6 files changed, 129 insertions(+), 34 deletions(-) create mode 100644 win/inspircd_namedpipe.cpp create mode 100644 win/inspircd_namedpipe.h (limited to 'win') diff --git a/win/configure.cpp b/win/configure.cpp index ce3653318..91c68a227 100644 --- a/win/configure.cpp +++ b/win/configure.cpp @@ -348,8 +348,9 @@ void Run() #endif fprintf(f, "#define MAXBUF 514\n"); - fprintf(f, "\n#include \"inspircd_win32wrapper.h\"\n\n"); - fprintf(f, "#include \"threadengines/threadengine_win32.h\"\n\n"); + fprintf(f, "\n#include \"inspircd_win32wrapper.h\""); + fprintf(f, "\n#include \"inspircd_namedpipe.h\""); + fprintf(f, "\n#include \"threadengines/threadengine_win32.h\"\n\n"); fprintf(f, "#endif\n\n"); fclose(f); diff --git a/win/inspircdVC80.vcproj b/win/inspircdVC80.vcproj index 78126bb27..8506ef722 100644 --- a/win/inspircdVC80.vcproj +++ b/win/inspircdVC80.vcproj @@ -431,6 +431,10 @@ RelativePath="..\src\inspircd.cpp" > + + @@ -633,6 +637,10 @@ RelativePath="..\include\inspircd_config.h" > + + diff --git a/win/inspircd_namedpipe.cpp b/win/inspircd_namedpipe.cpp new file mode 100644 index 000000000..6610d1f5c --- /dev/null +++ b/win/inspircd_namedpipe.cpp @@ -0,0 +1,76 @@ +#include "inspircd.h" +#include "threadengine.h" +#include "inspircd_namedpipe.h" +#include + +void IPCThread::Run() +{ + LPTSTR Pipename = "\\\\.\\pipe\\InspIRCdStatus"; + + 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 + + if (Pipe == INVALID_HANDLE_VALUE) + return; + + while (GetExitFlag() == false) + { + // Trying connectnamedpipe in sample for CreateNamedPipe + // Wait for the client to connect; if it succeeds, + // the function returns a nonzero value. If the function returns + // zero, GetLastError returns ERROR_PIPE_CONNECTED. + + Connected = ConnectNamedPipe(Pipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); + + if (Connected) + { + Success = ReadFile (Pipe, // handle to pipe + Request, // buffer to receive data + MAXBUF, // size of buffer + &BytesRead, // number of bytes read + NULL); // not overlapped I/O + + Request[BytesRead] = '\0'; + //printf("Data Received: %s\n",chRequest); + + if (!Success || !BytesRead) + break; + + FlushFileBuffers(Pipe); + DisconnectNamedPipe(Pipe); + } + else + { + // The client could not connect. + CloseHandle(Pipe); + } + + SleepEx(100, FALSE); + } + CloseHandle(Pipe); +} + +IPC::IPC(InspIRCd* Srv) : ServerInstance(Srv) +{ + /* The IPC pipe is threaded */ + thread = new IPCThread(Srv); + Srv->Threads->Create(thread); +} + +void IPC::Check() +{ +} + +IPC::~IPC() +{ + thread->SetExitFlag(); + delete thread; +} \ No newline at end of file diff --git a/win/inspircd_namedpipe.h b/win/inspircd_namedpipe.h new file mode 100644 index 000000000..4cd69ea0e --- /dev/null +++ b/win/inspircd_namedpipe.h @@ -0,0 +1,40 @@ +#ifndef INSPIRCD_NAMEDPIPE +#define INSPIRCD_NAMEDPIPE + +#include "threadengine.h" +#include + +class InspIRCd; + +class IPCThread : public Thread +{ + BOOL Connected; + CHAR Request[MAXBUF]; + DWORD BytesRead; + BOOL Success; + HANDLE Pipe; + InspIRCd* ServerInstance; + public: + IPCThread(InspIRCd* Instance) : Thread(), ServerInstance(Instance) + { + } + + virtual ~IPCThread() + { + } + + virtual void Run(); +}; + +class IPC +{ + private: + InspIRCd* ServerInstance; + IPCThread* thread; + public: + IPC(InspIRCd* Srv); + void Check(); + ~IPC(); +}; + +#endif \ No newline at end of file diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp index c32d31d5a..75a9eaf4f 100644 --- a/win/inspircd_win32wrapper.cpp +++ b/win/inspircd_win32wrapper.cpp @@ -363,21 +363,7 @@ int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, return 1; } -/* IPC Messages */ -#define IPC_MESSAGE_REHASH 1 -#define IPC_MESSAGE_DIE 2 -#define IPC_MESSAGE_RESTART 3 - -IPC::IPC(InspIRCd* Srv) : Instance(Srv) -{ - static DWORD buflen = 1024; - static const char * pipename = "\\\\.\\mailslot\\Inspircd"; - hIPCPipe = CreateMailslot(pipename, buflen, 0, 0); - if (hIPCPipe == INVALID_HANDLE_VALUE) - printf("IPC Pipe could not be created. Are you sure you didn't start InspIRCd twice?\n"); -} - -void IPC::Check() +/*void IPC::Check() { if (hIPCPipe == INVALID_HANDLE_VALUE) return; @@ -407,12 +393,7 @@ void IPC::Check() Instance->Restart("IPC_MESSAGE_RESTART received by mailslot."); break; } -} - -IPC::~IPC() -{ - CloseHandle(hIPCPipe); -} +}*/ /* These three functions were created from looking at how ares does it diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h index d7b1d9cef..a7a323693 100644 --- a/win/inspircd_win32wrapper.h +++ b/win/inspircd_win32wrapper.h @@ -193,17 +193,6 @@ class InspIRCd; class ValueItem; class ServerConfig; -class IPC -{ - private: - InspIRCd* Instance; - HANDLE hIPCPipe; - public: - IPC(InspIRCd* Srv); - void Check(); - ~IPC(); -}; - /* Look up the nameserver in use from the registry on windows */ std::string FindNameServerWin(); -- cgit v1.2.3