2008-06-15 16:21:09 +00:00
|
|
|
#include "inspircd.h"
|
|
|
|
#include "threadengine.h"
|
|
|
|
#include "inspircd_namedpipe.h"
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
void IPCThread::Run()
|
|
|
|
{
|
2008-06-15 19:26:58 +00:00
|
|
|
|
|
|
|
printf("*** IPCThread::Run() *** \n");
|
2008-06-15 16:21:09 +00:00
|
|
|
LPTSTR Pipename = "\\\\.\\pipe\\InspIRCdStatus";
|
|
|
|
|
2008-06-15 19:26:58 +00:00
|
|
|
while (GetExitFlag() == false)
|
|
|
|
{
|
|
|
|
Pipe = CreateNamedPipe (Pipename,
|
2008-06-15 16:21:09 +00:00
|
|
|
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
|
|
|
|
|
2008-06-15 19:26:58 +00:00
|
|
|
printf("*** After CreateNamedPipe *** \n");
|
|
|
|
|
2008-06-15 16:21:09 +00:00
|
|
|
if (Pipe == INVALID_HANDLE_VALUE)
|
2008-06-15 19:26:58 +00:00
|
|
|
{
|
|
|
|
printf("*** IPC failure creating named pipe: %s\n", dlerror());
|
2008-06-15 16:21:09 +00:00
|
|
|
return;
|
2008-06-15 19:26:58 +00:00
|
|
|
}
|
2008-06-15 16:21:09 +00:00
|
|
|
|
2008-06-15 19:26:58 +00:00
|
|
|
printf("*** After check, exit flag=%d *** \n", GetExitFlag());
|
2008-06-15 16:21:09 +00:00
|
|
|
|
2008-06-15 19:26:58 +00:00
|
|
|
printf("*** Loop *** \n");
|
2008-06-15 16:21:09 +00:00
|
|
|
Connected = ConnectNamedPipe(Pipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
|
|
|
|
|
2008-06-15 19:26:58 +00:00
|
|
|
printf("*** After ConnectNamedPipe *** \n");
|
|
|
|
|
2008-06-15 16:21:09 +00:00
|
|
|
if (Connected)
|
|
|
|
{
|
2008-06-15 19:26:58 +00:00
|
|
|
ServerInstance->Logs->Log("IPC", DEBUG, "About to ReadFile from pipe");
|
|
|
|
|
2008-06-15 16:21:09 +00:00
|
|
|
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';
|
2008-06-15 19:26:58 +00:00
|
|
|
ServerInstance->Logs->Log("IPC", DEBUG, "Received from IPC: %s", Request);
|
2008-06-15 16:21:09 +00:00
|
|
|
//printf("Data Received: %s\n",chRequest);
|
|
|
|
|
|
|
|
if (!Success || !BytesRead)
|
2008-06-15 19:26:58 +00:00
|
|
|
{
|
|
|
|
printf("*** IPC failure reading client named pipe: %s\n", dlerror());
|
|
|
|
continue;
|
|
|
|
}
|
2008-06-15 16:21:09 +00:00
|
|
|
|
|
|
|
FlushFileBuffers(Pipe);
|
|
|
|
DisconnectNamedPipe(Pipe);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The client could not connect.
|
2008-06-15 19:26:58 +00:00
|
|
|
printf("*** IPC failure connecting named pipe: %s\n", dlerror());
|
2008-06-15 16:21:09 +00:00
|
|
|
}
|
|
|
|
|
2008-06-15 19:26:58 +00:00
|
|
|
printf("*** sleep for next client ***\n");
|
|
|
|
printf("*** Closing pipe handle\n");
|
|
|
|
CloseHandle(Pipe);
|
2008-06-15 16:21:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IPC::IPC(InspIRCd* Srv) : ServerInstance(Srv)
|
|
|
|
{
|
|
|
|
/* The IPC pipe is threaded */
|
|
|
|
thread = new IPCThread(Srv);
|
|
|
|
Srv->Threads->Create(thread);
|
2008-06-15 19:26:58 +00:00
|
|
|
printf("*** CREATE IPC THREAD ***\n");
|
2008-06-15 16:21:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IPC::Check()
|
|
|
|
{
|
2008-06-15 19:26:58 +00:00
|
|
|
ServerInstance->Threads->Mutex(true);
|
|
|
|
|
|
|
|
/* Check the state of the thread, safe in here */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ServerInstance->Threads->Mutex(false);
|
2008-06-15 16:21:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IPC::~IPC()
|
|
|
|
{
|
|
|
|
thread->SetExitFlag();
|
|
|
|
delete thread;
|
|
|
|
}
|