mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32:48 -05:00
New API for plug_closing() with a custom type enum.
Passing an operating-system-specific error code to plug_closing(), such as errno or GetLastError(), was always a bit weird, given that it generally had to be handled by cross-platform receiving code in backends. I had the platform.h implementations #define any error values that the cross-platform code would have to handle specially, but that's still not a great system, because it also doesn't leave freedom to invent error representations of my own that don't correspond to any OS code. (For example, the ones I just removed from proxy.h.) So now, the OS error code is gone from the plug_closing API, and in its place is a custom enumeration of closure types: normal, error, and the special case BROKEN_PIPE which is the only OS error code we have so far needed to handle specially. (All others just mean 'abandon the connection and print the textual message'.) Having already centralised the handling of OS error codes in the previous commit, we've now got a convenient place to add any further type codes for errors needing special handling: each of Unix plug_closing_errno(), Windows plug_closing_system_error(), and Windows plug_closing_winsock_error() can easily grow extra special cases if need be, and each one will only have to live in one place.
This commit is contained in:
@ -181,16 +181,17 @@ static void plug_proxy_log(Plug *plug, PlugLogType type, SockAddr *addr,
|
||||
plug_log(ps->plug, type, addr, port, error_msg, error_code);
|
||||
}
|
||||
|
||||
static void plug_proxy_closing(Plug *p, const char *error_msg, int error_code)
|
||||
static void plug_proxy_closing(Plug *p, PlugCloseType type,
|
||||
const char *error_msg)
|
||||
{
|
||||
ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
|
||||
|
||||
if (ps->state != PROXY_STATE_ACTIVE) {
|
||||
ps->closing_type = type;
|
||||
ps->closing_error_msg = error_msg;
|
||||
ps->closing_error_code = error_code;
|
||||
ps->negotiate(ps, PROXY_CHANGE_CLOSING);
|
||||
} else {
|
||||
plug_closing(ps->plug, error_msg, error_code);
|
||||
plug_closing(ps->plug, type, error_msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -615,7 +616,7 @@ int proxy_http_negotiate (ProxySocket *p, int change)
|
||||
* a socket close, then some error must have occurred. we'll
|
||||
* just pass those errors up to the backend.
|
||||
*/
|
||||
plug_closing(p->plug, p->closing_error_msg, p->closing_error_code);
|
||||
plug_closing(p->plug, p->closing_type, p->closing_error_msg);
|
||||
return 0; /* ignored */
|
||||
}
|
||||
|
||||
@ -803,7 +804,7 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
|
||||
* a socket close, then some error must have occurred. we'll
|
||||
* just pass those errors up to the backend.
|
||||
*/
|
||||
plug_closing(p->plug, p->closing_error_msg, p->closing_error_code);
|
||||
plug_closing(p->plug, p->closing_type, p->closing_error_msg);
|
||||
return 0; /* ignored */
|
||||
}
|
||||
|
||||
@ -945,7 +946,7 @@ int proxy_socks5_negotiate (ProxySocket *p, int change)
|
||||
* a socket close, then some error must have occurred. we'll
|
||||
* just pass those errors up to the backend.
|
||||
*/
|
||||
plug_closing(p->plug, p->closing_error_msg, p->closing_error_code);
|
||||
plug_closing(p->plug, p->closing_type, p->closing_error_msg);
|
||||
return 0; /* ignored */
|
||||
}
|
||||
|
||||
@ -1467,7 +1468,7 @@ int proxy_telnet_negotiate (ProxySocket *p, int change)
|
||||
* a socket close, then some error must have occurred. we'll
|
||||
* just pass those errors up to the backend.
|
||||
*/
|
||||
plug_closing(p->plug, p->closing_error_msg, p->closing_error_code);
|
||||
plug_closing(p->plug, p->closing_type, p->closing_error_msg);
|
||||
return 0; /* ignored */
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,8 @@ struct ProxySocket {
|
||||
*/
|
||||
|
||||
/* closing */
|
||||
PlugCloseType closing_type;
|
||||
const char *closing_error_msg;
|
||||
int closing_error_code;
|
||||
|
||||
/* receive */
|
||||
bool receive_urgent;
|
||||
|
Reference in New Issue
Block a user