summaryrefslogtreecommitdiff
path: root/win/inspircd_namedpipe.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-06-15 16:21:09 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-06-15 16:21:09 +0000
commitafe99da316b6f63900df2bd8711ab515f4977f6a (patch)
tree9ebec758f4498eb6a29131ac48f98ba97c1e8ac5 /win/inspircd_namedpipe.cpp
parentd15b915ef5e5740194716ab3685dfe6c8b5f79f5 (diff)
Base stuff for named pipe IPC
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9910 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'win/inspircd_namedpipe.cpp')
-rw-r--r--win/inspircd_namedpipe.cpp76
1 files changed, 76 insertions, 0 deletions
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