1 #include "inspircd.h"
\r
2 #include "threadengine.h"
\r
3 #include "inspircd_namedpipe.h"
\r
6 void IPCThread::Run()
\r
9 printf("*** IPCThread::Run() *** \n");
\r
10 LPTSTR Pipename = "\\\\.\\pipe\\InspIRCdStatus";
\r
12 while (GetExitFlag() == false)
14 Pipe = CreateNamedPipe (Pipename,
\r
15 PIPE_ACCESS_DUPLEX, // read/write access
\r
16 PIPE_TYPE_MESSAGE | // message type pipe
\r
17 PIPE_READMODE_MESSAGE | // message-read mode
\r
18 PIPE_WAIT, // blocking mode
\r
19 PIPE_UNLIMITED_INSTANCES, // max. instances
\r
20 MAXBUF, // output buffer size
\r
21 MAXBUF, // input buffer size
\r
22 1000, // client time-out
\r
23 NULL); // no security attribute
\r
25 printf("*** After CreateNamedPipe *** \n");
\r
27 if (Pipe == INVALID_HANDLE_VALUE)
\r
29 printf("*** IPC failure creating named pipe: %s\n", dlerror());
\r
33 printf("*** After check, exit flag=%d *** \n", GetExitFlag());
\r
35 printf("*** Loop *** \n");
\r
36 Connected = ConnectNamedPipe(Pipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
\r
38 printf("*** After ConnectNamedPipe *** \n");
\r
42 ServerInstance->Logs->Log("IPC", DEBUG, "About to ReadFile from pipe");
\r
44 Success = ReadFile (Pipe, // handle to pipe
\r
45 Request, // buffer to receive data
\r
46 MAXBUF, // size of buffer
\r
47 &BytesRead, // number of bytes read
\r
48 NULL); // not overlapped I/O
\r
50 Request[BytesRead] = '\0';
\r
51 ServerInstance->Logs->Log("IPC", DEBUG, "Received from IPC: %s", Request);
\r
52 //printf("Data Received: %s\n",chRequest);
\r
54 if (!Success || !BytesRead)
\r
56 printf("*** IPC failure reading client named pipe: %s\n", dlerror());
\r
60 FlushFileBuffers(Pipe);
\r
61 DisconnectNamedPipe(Pipe);
\r
65 // The client could not connect.
\r
66 printf("*** IPC failure connecting named pipe: %s\n", dlerror());
\r
69 printf("*** sleep for next client ***\n");
\r
70 printf("*** Closing pipe handle\n");
\r
75 IPC::IPC(InspIRCd* Srv) : ServerInstance(Srv)
77 /* The IPC pipe is threaded */
78 thread = new IPCThread(Srv);
79 Srv->Threads->Create(thread);
80 printf("*** CREATE IPC THREAD ***\n");
85 ServerInstance->Threads->Mutex(true);
87 /* Check the state of the thread, safe in here */
91 ServerInstance->Threads->Mutex(false);
96 thread->SetExitFlag();