1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-18 11:31:00 -05:00

Centralise implementations of Windows do_select().

Windows Plink and PSFTP had very similar implementations, and now they
share one that lives in a new file winselcli.c. I've similarly moved
GUI PuTTY's implementation out of window.c into winselgui.c, where
other GUI programs wanting to do networking will be able to access
that too.

In the spirit of centralisation, I've also taken the opportunity to
make both functions use the reasonably complete winsock_error_string()
rather than (for some historical reason) each inlining a minimal
version that reports most errors as 'unknown'.
This commit is contained in:
Simon Tatham
2020-01-01 11:10:22 +00:00
parent ae1148267d
commit b89d17fbca
7 changed files with 147 additions and 99 deletions

View File

@ -38,8 +38,6 @@ StripCtrlChars *stdout_scc, *stderr_scc;
BinarySink *stdout_bs, *stderr_bs;
DWORD orig_console_mode;
WSAEVENT netevent;
static Backend *backend;
Conf *conf;
@ -190,26 +188,6 @@ static void version(void)
exit(0);
}
char *do_select(SOCKET skt, bool enable)
{
int events;
if (enable) {
events = (FD_CONNECT | FD_READ | FD_WRITE |
FD_OOB | FD_CLOSE | FD_ACCEPT);
} else {
events = 0;
}
if (p_WSAEventSelect(skt, netevent, events) == SOCKET_ERROR) {
switch (p_WSAGetLastError()) {
case WSAENETDOWN:
return "Network is down";
default:
return "WSAEventSelect(): unknown error";
}
}
return NULL;
}
size_t stdin_gotdata(struct handle *h, const void *data, size_t len, int err)
{
if (err) {
@ -502,7 +480,7 @@ int main(int argc, char **argv)
/*
* Start up the connection.
*/
netevent = CreateEvent(NULL, false, false, NULL);
winselcli_setup(); /* ensure event object exists */
{
const char *error;
char *realhost;
@ -558,7 +536,7 @@ int main(int argc, char **argv)
handles = handle_get_events(&nhandles);
handles = sresize(handles, nhandles+1, HANDLE);
handles[nhandles] = netevent;
handles[nhandles] = winselcli_event;
n = MsgWaitForMultipleObjects(nhandles+1, handles, false, ticks,
QS_POSTMESSAGE);
if ((unsigned)(n - WAIT_OBJECT_0) < (unsigned)nhandles) {