diff options
-rw-r--r-- | win/configure.cpp | 5 | ||||
-rw-r--r-- | win/inspircdVC80.vcproj | 8 | ||||
-rw-r--r-- | win/inspircd_namedpipe.cpp | 76 | ||||
-rw-r--r-- | win/inspircd_namedpipe.h | 40 | ||||
-rw-r--r-- | win/inspircd_win32wrapper.cpp | 23 | ||||
-rw-r--r-- | win/inspircd_win32wrapper.h | 11 |
6 files changed, 129 insertions, 34 deletions
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 @@ -432,6 +432,10 @@ >
</File>
<File
+ RelativePath=".\inspircd_namedpipe.cpp"
+ >
+ </File>
+ <File
RelativePath="..\src\inspsocket.cpp"
>
</File>
@@ -634,6 +638,10 @@ >
</File>
<File
+ RelativePath=".\inspircd_namedpipe.h"
+ >
+ </File>
+ <File
RelativePath="..\include\inspsocket.h"
>
</File>
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 <windows.h>
+
+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 <windows.h>
+
+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(); |