• R/O
  • HTTP
  • SSH
  • HTTPS

xkeymacs: Commit


Commit MetaInfo

Revision676a11a6e3ad1ecccde323060ecddbaf89cd5b29 (tree)
Time2012-08-23 23:15:30
AuthorKazuhiro Fujieda <fujieda@user...>
CommiterKazuhiro Fujieda

Log Message

Allow output of debug logs on failures of IPC functions

Change Summary

Incremental Difference

--- a/xkeymacs/mainfrm.cpp
+++ b/xkeymacs/mainfrm.cpp
@@ -5,6 +5,7 @@
55 #include "xkeymacs.h"
66 #include "profile.h"
77 #include "../xkeymacsdll/xkeymacsdll.h"
8+#include "../xkeymacsdll/Utils.h"
89
910 #ifdef _DEBUG
1011 #define new DEBUG_NEW
@@ -171,23 +172,52 @@ void CMainFrame::TerminatePollThread()
171172 bool SendAck(HANDLE pipe)
172173 {
173174 DWORD written, ack = 0;
174- return WriteFile(pipe, &ack, sizeof(DWORD), &written, NULL) && written == sizeof(DWORD) &&
175- FlushFileBuffers(pipe) && DisconnectNamedPipe(pipe);
175+ if (!WriteFile(pipe, &ack, sizeof(DWORD), &written, NULL) && written != sizeof(DWORD)) {
176+#ifdef DEBUG_IPC
177+ CUtils::Log(_T("SendAck: WriteFile failed. (%d)"), GetLastError());
178+#endif
179+ return false;
180+ }
181+ if (!FlushFileBuffers(pipe)) {
182+#ifdef DEBUG_IPC
183+ CUtils::Log(_T("SendAck: FlushFileBuffers failed. (%d)"), GetLastError());
184+#endif
185+ return false;
186+ }
187+ if (!DisconnectNamedPipe(pipe)) {
188+#ifdef DEBUG_IPC
189+ CUtils::Log(_T("SendAck: DisconnectNamedPipe failed. (%d)"), GetLastError());
190+#endif
191+ return false;
192+ }
193+ return true;
176194 }
177195
178196 DWORD WINAPI CMainFrame::PollMessage(LPVOID)
179197 {
180198 HANDLE pipe = CreateNamedPipe(XKEYMACS32_PIPE, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, 1,
181199 sizeof(DWORD), sizeof(IPC32Message), 0, NULL);
182- if (pipe == INVALID_HANDLE_VALUE)
200+ if (pipe == INVALID_HANDLE_VALUE) {
201+#ifdef DEBUG_IPC
202+ CUtils::Log(_T("PollMessage: CreateNamedPipe failed. (%d)"), GetLastError());
203+#endif
183204 return 1;
205+ }
184206 for (; ;) {
185- if (ConnectNamedPipe(pipe, NULL) ? FALSE : (GetLastError() != ERROR_PIPE_CONNECTED))
207+ if (ConnectNamedPipe(pipe, NULL) ? FALSE : (GetLastError() != ERROR_PIPE_CONNECTED)) {
208+#ifdef DEBUG_IPC
209+ CUtils::Log(_T("PollMessage: ConnectNamedPipe failed. (%d)"), GetLastError());
210+#endif
186211 break;
212+ }
187213 IPC32Message msg;
188214 DWORD read;
189- if (!ReadFile(pipe, &msg, sizeof(msg), &read, NULL))
215+ if (!ReadFile(pipe, &msg, sizeof(msg), &read, NULL)) {
216+#ifdef DEBUG_IPC
217+ CUtils::Log(_T("PollMessage: ReadFile failed. (%d)"), GetLastError());
218+#endif
190219 break;
220+ }
191221 switch (msg.Type) {
192222 case IPC32_TERMINATE:
193223 SendAck(pipe);
--- a/xkeymacs/xkeymacs.cpp
+++ b/xkeymacs/xkeymacs.cpp
@@ -4,6 +4,7 @@
44 #include "xkeymacs.h"
55 #include "mainfrm.h"
66 #include "profile.h"
7+#include "../xkeymacsdll/Utils.h"
78
89 #ifdef _DEBUG
910 #define new DEBUG_NEW
@@ -121,7 +122,11 @@ void CXkeymacsApp::SendIPC64Message(DWORD msg)
121122 DWORD ack, read;
122123 for (int i = 0; i < 10; Sleep(100), ++i)
123124 if (CallNamedPipe(XKEYMACS64_PIPE, &msg, sizeof(msg), &ack, sizeof(DWORD), &read, NMPWAIT_WAIT_FOREVER))
124- return;;
125+ return;
126+#ifdef DEBUG_IPC
127+ else
128+ CUtils::Log(_T("SendIPC64Message: CallNamedPipe failed. (%d)"), GetLastError());
129+#endif
125130 }
126131
127132 int CXkeymacsApp::ExitInstance()
--- a/xkeymacs/xkeymacs64.cpp
+++ b/xkeymacs/xkeymacs64.cpp
@@ -1,6 +1,7 @@
11 #include "xkeymacs64.h"
22 #include "mainfrm64.h"
33 #include "../xkeymacsdll/xkeymacsdll.h"
4+#include "../xkeymacsdll/Utils.h"
45
56 CXkeymacsApp::CXkeymacsApp()
67 {
@@ -37,18 +38,54 @@ BOOL CXkeymacsApp::InitInstance()
3738 return TRUE;
3839 }
3940
41+bool SendAck(HANDLE pipe)
42+{
43+ DWORD written, ack = 0;
44+ if (!WriteFile(pipe, &ack, sizeof(DWORD), &written, NULL) && written != sizeof(DWORD)) {
45+#ifdef DEBUG_IPC
46+ CUtils::Log(_T("SendAck: WriteFile failed. (%d)"), GetLastError());
47+#endif
48+ return false;
49+ }
50+ if (!FlushFileBuffers(pipe)) {
51+#ifdef DEBUG_IPC
52+ CUtils::Log(_T("SendAck: FlushFileBuffers failed. (%d)"), GetLastError());
53+#endif
54+ return false;
55+ }
56+ if (!DisconnectNamedPipe(pipe)) {
57+#ifdef DEBUG_IPC
58+ CUtils::Log(_T("SendAck: DisconnectNamedPipe failed. (%d)"), GetLastError());
59+#endif
60+ return false;
61+ }
62+ return true;
63+}
64+
4065 UINT PollIPCMessage(LPVOID param)
4166 {
4267 HANDLE hPipe = CreateNamedPipe(XKEYMACS64_PIPE, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, 1, 512, 512, 0, NULL);
43- if (hPipe == INVALID_HANDLE_VALUE)
68+ if (hPipe == INVALID_HANDLE_VALUE) {
69+#ifdef DEBUG_IPC
70+ CUtils::Log(_T("PollIPCMessage: CreateNamedPipe failed. (%d)"), GetLastError());
71+#endif
4472 return 1;
73+ }
4574 for (; ;) {
46- if (ConnectNamedPipe(hPipe, NULL) ? FALSE : (GetLastError() != ERROR_PIPE_CONNECTED))
75+ if (ConnectNamedPipe(hPipe, NULL) ? FALSE : (GetLastError() != ERROR_PIPE_CONNECTED)) {
76+#ifdef DEBUG_IPC
77+ CUtils::Log(_T("PollIPCMessage: ConnectNamedPipe failed. (%d)"), GetLastError());
78+#endif
4779 break;
80+ }
4881 DWORD msg;
4982 DWORD read;
50- if (!ReadFile(hPipe, &msg, sizeof(msg), &read, NULL) || read != sizeof(msg))
83+ if (!ReadFile(hPipe, &msg, sizeof(msg), &read, NULL) || read != sizeof(msg)) {
84+#ifdef DEBUG_IPC
85+ CUtils::Log(_T("PollIPCMessage: ReadFile failed. (%d)"), GetLastError());
86+#endif
5187 break;
88+ }
5289 switch (msg)
5390 {
5491 case IPC64_EXIT:
@@ -67,10 +104,7 @@ UINT PollIPCMessage(LPVOID param)
67104 CXkeymacsDll::SetHookStateDirect(true);
68105 break;
69106 }
70- DWORD written, ack = 0;
71- if (!WriteFile(hPipe, &ack, sizeof(DWORD), &written, NULL) || written != sizeof(DWORD)
72- || !FlushFileBuffers(hPipe) || !DisconnectNamedPipe(hPipe))
73- break;
107+ SendAck(hPipe);
74108 }
75109 exit:
76110 CloseHandle(hPipe);
--- a/xkeymacsdll/xkeymacsdll.cpp
+++ b/xkeymacsdll/xkeymacsdll.cpp
@@ -222,7 +222,8 @@ void CXkeymacsDll::SetHookState(bool enable)
222222 IPC32Message msg;
223223 msg.Type = IPC32_HOOKSTATE;
224224 msg.Enable = enable;
225- CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, Enable) + sizeof(bool), &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT);
225+ if (!CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, Enable) + sizeof(bool), &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT))
226+ CUtils::Log(_T("SetHookState: CallNamedPipe failed. (%d)"), GetLastError());
226227
227228 ShowHookState();
228229 }
@@ -776,7 +777,11 @@ void CXkeymacsDll::SendIconMessage(IconState *state, int num)
776777 IPC32Message msg;
777778 msg.Type = IPC32_ICON;
778779 memcpy(msg.IconState, state, num * sizeof(IconState));
779- CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, IconState) + sizeof(IconState) * num, &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT);
780+ if (!CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, IconState) + sizeof(IconState) * num, &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT)) {
781+#ifdef DEBUG_IPC
782+ CUtils::Log(_T("SendIconMessage: CallNamedPipe failed. (%d)"), GetLastError());
783+#endif
784+ }
780785 }
781786
782787 void CXkeymacsDll::Kdu(BYTE bVk, DWORD n, BOOL bOriginal)
Show on old repository browser