1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-25 09:12:24 +00:00

Revamp Windows's close_session() using toplevel callbacks.

Instead of setting a must_close_session flag and having special code
in the message loop to check it, we'll schedule the call to
close_session using the new top-level callback system.

[originally from svn r10021]
This commit is contained in:
Simon Tatham 2013-08-17 16:06:18 +00:00
parent 7be9af74ec
commit 43c9748ac9

View File

@ -121,7 +121,7 @@ static Backend *back;
static void *backhandle; static void *backhandle;
static struct unicode_data ucsdata; static struct unicode_data ucsdata;
static int must_close_session, session_closed; static int session_closed;
static int reconfiguring = FALSE; static int reconfiguring = FALSE;
static const struct telnet_special *specials = NULL; static const struct telnet_special *specials = NULL;
@ -289,11 +289,10 @@ static void start_backend(void)
DeleteMenu(popup_menus[i].menu, IDM_RESTART, MF_BYCOMMAND); DeleteMenu(popup_menus[i].menu, IDM_RESTART, MF_BYCOMMAND);
} }
must_close_session = FALSE;
session_closed = FALSE; session_closed = FALSE;
} }
static void close_session(void) static void close_session(void *ignored_context)
{ {
char morestuff[100]; char morestuff[100];
int i; int i;
@ -324,15 +323,6 @@ static void close_session(void)
InsertMenu(popup_menus[i].menu, IDM_DUPSESS, MF_BYCOMMAND | MF_ENABLED, InsertMenu(popup_menus[i].menu, IDM_DUPSESS, MF_BYCOMMAND | MF_ENABLED,
IDM_RESTART, "&Restart Session"); IDM_RESTART, "&Restart Session");
} }
/*
* Unset the 'must_close_session' flag, or else we'll come
* straight back here the next time we go round the main message
* loop - which, worse still, will be immediately (without
* blocking) because we've just triggered a WM_SETTEXT by the
* window title change above.
*/
must_close_session = FALSE;
} }
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
@ -864,8 +854,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
if ((unsigned)(n - WAIT_OBJECT_0) < (unsigned)nhandles) { if ((unsigned)(n - WAIT_OBJECT_0) < (unsigned)nhandles) {
handle_got_event(handles[n - WAIT_OBJECT_0]); handle_got_event(handles[n - WAIT_OBJECT_0]);
sfree(handles); sfree(handles);
if (must_close_session)
close_session();
} else } else
sfree(handles); sfree(handles);
@ -878,9 +866,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
if (!(IsWindow(logbox) && IsDialogMessage(logbox, &msg))) if (!(IsWindow(logbox) && IsDialogMessage(logbox, &msg)))
DispatchMessage(&msg); DispatchMessage(&msg);
if (must_close_session)
close_session();
run_toplevel_callbacks(); run_toplevel_callbacks();
} }
@ -1113,7 +1098,7 @@ void connection_fatal(void *frontend, char *fmt, ...)
if (conf_get_int(conf, CONF_close_on_exit) == FORCE_ON) if (conf_get_int(conf, CONF_close_on_exit) == FORCE_ON)
PostQuitMessage(1); PostQuitMessage(1);
else { else {
must_close_session = TRUE; queue_toplevel_callback(close_session, NULL);
} }
} }
@ -2010,7 +1995,7 @@ void notify_remote_exit(void *fe)
(close_on_exit == AUTO && exitcode != INT_MAX)) { (close_on_exit == AUTO && exitcode != INT_MAX)) {
PostQuitMessage(0); PostQuitMessage(0);
} else { } else {
must_close_session = TRUE; queue_toplevel_callback(close_session, NULL);
session_closed = TRUE; session_closed = TRUE;
/* exitcode == INT_MAX indicates that the connection was closed /* exitcode == INT_MAX indicates that the connection was closed
* by a fatal error, so an error box will be coming our way and * by a fatal error, so an error box will be coming our way and