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 std::stringstream status;
\r
62 ServerInstance->Threads->Mutex(true);
\r
64 status << "name " << ServerInstance->Config->ServerName << std::endl;
\r
65 status << "END" << std::endl;
\r
67 ServerInstance->Threads->Mutex(false);
\r
69 /* This is a blocking call and will succeed, so long as the client doesnt disconnect */
\r
70 Success = WriteFile(Pipe, status.str().data(), status.str().length(), &Written, NULL);
\r
72 FlushFileBuffers(Pipe);
\r
73 DisconnectNamedPipe(Pipe);
\r
77 // The client could not connect.
\r
78 printf("*** IPC failure connecting named pipe: %s\n", dlerror());
\r
81 printf("*** sleep for next client ***\n");
\r
82 printf("*** Closing pipe handle\n");
\r
87 IPC::IPC(InspIRCd* Srv) : ServerInstance(Srv)
89 /* The IPC pipe is threaded */
90 thread = new IPCThread(Srv);
91 Srv->Threads->Create(thread);
92 printf("*** CREATE IPC THREAD ***\n");
97 ServerInstance->Threads->Mutex(true);
99 /* Check the state of the thread, safe in here */
103 ServerInstance->Threads->Mutex(false);
108 thread->SetExitFlag();