2020-01-01 11:10:22 +00:00
|
|
|
/*
|
2022-01-22 15:38:53 +00:00
|
|
|
* Implementation of do_select() for network.c to use, that uses
|
2020-01-01 11:10:22 +00:00
|
|
|
* WSAAsyncSelect to convert network activity into window messages,
|
|
|
|
* for integration into a GUI event loop.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
|
|
|
static HWND winsel_hwnd = NULL;
|
|
|
|
|
|
|
|
void winselgui_set_hwnd(HWND hwnd)
|
|
|
|
{
|
|
|
|
winsel_hwnd = hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void winselgui_clear_hwnd(void)
|
|
|
|
{
|
|
|
|
winsel_hwnd = NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-01 15:46:59 +00:00
|
|
|
const char *do_select(SOCKET skt, bool enable)
|
2020-01-01 11:10:22 +00:00
|
|
|
{
|
|
|
|
int msg, events;
|
|
|
|
if (enable) {
|
|
|
|
msg = WM_NETEVENT;
|
|
|
|
events = (FD_CONNECT | FD_READ | FD_WRITE |
|
|
|
|
FD_OOB | FD_CLOSE | FD_ACCEPT);
|
|
|
|
} else {
|
|
|
|
msg = events = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(winsel_hwnd);
|
|
|
|
|
|
|
|
if (p_WSAAsyncSelect(skt, winsel_hwnd, msg, events) == SOCKET_ERROR)
|
|
|
|
return winsock_error_string(p_WSAGetLastError());
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2022-01-29 16:49:44 +00:00
|
|
|
|
|
|
|
struct wm_netevent_params {
|
|
|
|
/* Used to pass data to wm_netevent_callback */
|
|
|
|
WPARAM wParam;
|
|
|
|
LPARAM lParam;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void wm_netevent_callback(void *vctx)
|
|
|
|
{
|
|
|
|
struct wm_netevent_params *params = (struct wm_netevent_params *)vctx;
|
|
|
|
select_result(params->wParam, params->lParam);
|
|
|
|
sfree(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
void winselgui_response(WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* To protect against re-entrancy when Windows's recv()
|
|
|
|
* immediately triggers a new WSAAsyncSelect window message, we
|
|
|
|
* don't call select_result directly from this handler but instead
|
|
|
|
* wait until we're back out at the top level of the message loop.
|
|
|
|
*/
|
|
|
|
struct wm_netevent_params *params = snew(struct wm_netevent_params);
|
|
|
|
params->wParam = wParam;
|
|
|
|
params->lParam = lParam;
|
|
|
|
queue_toplevel_callback(wm_netevent_callback, params);
|
|
|
|
}
|