mirror of https://github.com/OpenVPN/openvpn-gui
Update echo-msg window from the thread that owns the window
Change the way echo-msg window is update (thread safety). When new echo-msg content is available for display, update the window from the thread owning it by sending a message to it. A blocking SendMessage (with a timeout) is used, as the window needs access to the config's echo-msg buffer which is cleared on return from this this call. Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/392/head
parent
273322efb0
commit
e4fba0c003
37
echo.c
37
echo.c
|
@ -259,20 +259,12 @@ echo_msg_display(connection_t *c, time_t timestamp, const char *title, int type)
|
|||
}
|
||||
if (type == ECHO_MSG_WINDOW)
|
||||
{
|
||||
|
||||
HWND h = echo_msg_window;
|
||||
if (h)
|
||||
DWORD_PTR res;
|
||||
UINT timeout = 5000; /* msec */
|
||||
if (echo_msg_window
|
||||
&& SendMessageTimeout(echo_msg_window, WM_OVPN_ECHOMSG, 0, (LPARAM) c, SMTO_BLOCK, timeout, &res) == 0)
|
||||
{
|
||||
wchar_t from[256];
|
||||
_sntprintf_0(from, L"From: %s %s", c->config_name, _wctime(×tamp));
|
||||
|
||||
/* strip \n added by _wctime */
|
||||
if (wcslen(from) > 0)
|
||||
from[wcslen(from)-1] = L'\0';
|
||||
|
||||
AddMessageBoxText(h, c->echo_msg.text, c->echo_msg.title, from);
|
||||
SetForegroundWindow(h);
|
||||
ShowWindow(h, SW_SHOW);
|
||||
WriteStatusLog(c, L"GUI> Failed to display echo message: ", c->echo_msg.title, false);
|
||||
}
|
||||
}
|
||||
else /* notify */
|
||||
|
@ -537,6 +529,25 @@ MessageDialogFunc(HWND hwnd, UINT msg, UNUSED WPARAM wParam, LPARAM lParam)
|
|||
}
|
||||
break;
|
||||
|
||||
/* Must be sent with lParam = connection pointer
|
||||
* Adds the current echo message and shows the window.
|
||||
*/
|
||||
case WM_OVPN_ECHOMSG:
|
||||
{
|
||||
connection_t *c = (connection_t *) lParam;
|
||||
wchar_t from[256];
|
||||
_sntprintf_0(from, L"From: %s %s", c->config_name, _wctime(&c->echo_msg.fp.timestamp));
|
||||
|
||||
/* strip \n added by _wctime */
|
||||
if (wcslen(from) > 0)
|
||||
from[wcslen(from)-1] = L'\0';
|
||||
|
||||
AddMessageBoxText(hwnd, c->echo_msg.text, c->echo_msg.title, from);
|
||||
SetForegroundWindow(hwnd);
|
||||
ShowWindow(hwnd, SW_SHOW);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_NOTIFY:
|
||||
nmh = (NMHDR*) lParam;
|
||||
/* We handle only EN_LINK messages */
|
||||
|
|
2
main.c
2
main.c
|
@ -576,7 +576,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
|||
}
|
||||
if (LOWORD(wParam) == IDM_SERVICE_RESTART) MyReStartService();
|
||||
break;
|
||||
|
||||
|
||||
case WM_CLOSE:
|
||||
CloseApplication(hwnd);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue