mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32:48 -05:00
Convenience wrappers on plug_closing().
Having a single plug_closing() function covering various kinds of closure is reasonably convenient from the point of view of Plug implementations, but it's annoying for callers, who all have to fill in pointless NULL and 0 parameters in the cases where they're not used. Added some inline helper functions in network.h alongside the main plug_closing() dispatch wrappers, so that each kind of connection closure can present a separate API for the Socket side of the interface, without complicating the vtable for the Plug side. Also, added OS-specific extra helpers in the Unix and Windows directories, which centralise the job of taking an OS error code (of whatever kind) and translating it into its error message. In passing, this removes the horrible ad-hoc made-up error codes in proxy.h, which is OK, because nothing checked for them anyway, and also I'm about to do an API change to plug_closing proper that removes the need for them.
This commit is contained in:
@ -53,10 +53,10 @@ static size_t handle_gotdata(
|
||||
HandleSocket *hs = (HandleSocket *)handle_get_privdata(h);
|
||||
|
||||
if (err) {
|
||||
plug_closing(hs->plug, "Read error from handle", 0);
|
||||
plug_closing_error(hs->plug, "Read error from handle");
|
||||
return 0;
|
||||
} else if (len == 0) {
|
||||
plug_closing(hs->plug, NULL, 0);
|
||||
plug_closing_normal(hs->plug);
|
||||
return 0;
|
||||
} else {
|
||||
assert(hs->frozen != FROZEN && hs->frozen != THAWING);
|
||||
@ -107,7 +107,7 @@ static void handle_sentdata(struct handle *h, size_t new_backlog, int err,
|
||||
}
|
||||
|
||||
if (err) {
|
||||
plug_closing(hs->plug, win_strerror(err), err);
|
||||
plug_closing_system_error(hs->plug, err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1335,6 +1335,16 @@ static void sk_net_close(Socket *sock)
|
||||
sfree(s);
|
||||
}
|
||||
|
||||
void plug_closing_system_error(Plug *plug, DWORD error)
|
||||
{
|
||||
plug_closing(plug, win_strerror(error), error);
|
||||
}
|
||||
|
||||
void plug_closing_winsock_error(Plug *plug, DWORD error)
|
||||
{
|
||||
plug_closing(plug, winsock_error_string(error), error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Deal with socket errors detected in try_send().
|
||||
*/
|
||||
@ -1352,8 +1362,7 @@ static void socket_error_callback(void *vs)
|
||||
/*
|
||||
* An error has occurred on this socket. Pass it to the plug.
|
||||
*/
|
||||
plug_closing(s->plug, winsock_error_string(s->pending_error),
|
||||
s->pending_error);
|
||||
plug_closing_winsock_error(s->plug, s->pending_error);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1528,7 +1537,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
}
|
||||
if (err != 0)
|
||||
plug_closing(s->plug, winsock_error_string(err), err);
|
||||
plug_closing_winsock_error(s->plug, err);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1590,9 +1599,9 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
plug_closing(s->plug, winsock_error_string(err), err);
|
||||
plug_closing_winsock_error(s->plug, err);
|
||||
} else if (0 == ret) {
|
||||
plug_closing(s->plug, NULL, 0);
|
||||
plug_closing_normal(s->plug);
|
||||
} else {
|
||||
plug_receive(s->plug, atmark ? 0 : 1, buf, ret);
|
||||
}
|
||||
@ -1608,7 +1617,7 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
||||
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
|
||||
if (ret <= 0) {
|
||||
int err = p_WSAGetLastError();
|
||||
plug_closing(s->plug, winsock_error_string(err), err);
|
||||
plug_closing_winsock_error(s->plug, err);
|
||||
} else {
|
||||
plug_receive(s->plug, 2, buf, ret);
|
||||
}
|
||||
@ -1631,12 +1640,12 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
||||
err = p_WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK)
|
||||
break;
|
||||
plug_closing(s->plug, winsock_error_string(err), err);
|
||||
plug_closing_winsock_error(s->plug, err);
|
||||
} else {
|
||||
if (ret)
|
||||
plug_receive(s->plug, 0, buf, ret);
|
||||
else
|
||||
plug_closing(s->plug, NULL, 0);
|
||||
plug_closing_normal(s->plug);
|
||||
}
|
||||
} while (ret > 0);
|
||||
return;
|
||||
|
@ -730,4 +730,8 @@ char *handle_restrict_acl_cmdline_prefix(char *cmdline);
|
||||
bool handle_special_sessionname_cmdline(char *cmdline, Conf *conf);
|
||||
bool handle_special_filemapping_cmdline(char *cmdline, Conf *conf);
|
||||
|
||||
/* network.c: network error reporting helpers taking OS error code */
|
||||
void plug_closing_system_error(Plug *plug, DWORD error);
|
||||
void plug_closing_winsock_error(Plug *plug, DWORD error);
|
||||
|
||||
#endif /* PUTTY_WINDOWS_PLATFORM_H */
|
||||
|
Reference in New Issue
Block a user