]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - win/inspircd_namedpipe.cpp
5f0c328df03800736987d94d788b3ae9f1e036e6
[user/henk/code/inspircd.git] / win / inspircd_namedpipe.cpp
1 #include "inspircd.h"\r
2 #include "threadengine.h"\r
3 #include "inspircd_namedpipe.h"\r
4 #include <windows.h>\r
5 \r
6 void IPCThread::Run()\r
7 {\r
8 \r
9         printf("*** IPCThread::Run() *** \n");\r
10         LPTSTR Pipename = "\\\\.\\pipe\\InspIRCdStatus";\r
11 \r
12         while (GetExitFlag() == false)
13         {\r
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
24 \r
25         printf("*** After CreateNamedPipe *** \n");\r
26 \r
27         if (Pipe == INVALID_HANDLE_VALUE)\r
28         {\r
29                 printf("*** IPC failure creating named pipe: %s\n", dlerror());\r
30                 return;\r
31         }\r
32 \r
33         printf("*** After check, exit flag=%d *** \n", GetExitFlag());\r
34 \r
35                 printf("*** Loop *** \n");\r
36                 Connected = ConnectNamedPipe(Pipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);\r
37 \r
38                 printf("*** After ConnectNamedPipe *** \n");\r
39 \r
40                 if (Connected)\r
41                 {\r
42                         ServerInstance->Logs->Log("IPC", DEBUG, "About to ReadFile from pipe");\r
43 \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
49 \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
53 \r
54                         if (!Success || !BytesRead)\r
55                         {\r
56                                 printf("*** IPC failure reading client named pipe: %s\n", dlerror());\r
57                                 continue;\r
58                         }\r
59 \r
60                         FlushFileBuffers(Pipe);\r
61                         DisconnectNamedPipe(Pipe);\r
62                 }\r
63                 else\r
64                 {\r
65                         // The client could not connect.\r
66                         printf("*** IPC failure connecting named pipe: %s\n", dlerror());\r
67                 }\r
68 \r
69                 printf("*** sleep for next client ***\n");\r
70                 printf("*** Closing pipe handle\n");\r
71                 CloseHandle(Pipe);\r
72         }\r
73 }\r
74 \r
75 IPC::IPC(InspIRCd* Srv) : ServerInstance(Srv)
76 {
77         /* The IPC pipe is threaded */
78         thread = new IPCThread(Srv);
79         Srv->Threads->Create(thread);
80         printf("*** CREATE IPC THREAD ***\n");
81 }
82
83 void IPC::Check()
84 {
85         ServerInstance->Threads->Mutex(true);
86
87         /* Check the state of the thread, safe in here */
88
89
90
91         ServerInstance->Threads->Mutex(false);
92 }
93
94 IPC::~IPC()
95 {
96         thread->SetExitFlag();
97         delete thread;
98 }