1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22: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:
Simon Tatham
2021-11-06 13:28:32 +00:00
parent 364e1aa3f3
commit 0fe41294e6
22 changed files with 107 additions and 82 deletions

View File

@ -65,11 +65,11 @@ static void raw_check_close(Raw *raw)
}
}
static void raw_closing(Plug *plug, const char *error_msg, int error_code)
static void raw_closing(Plug *plug, PlugCloseType type, const char *error_msg)
{
Raw *raw = container_of(plug, Raw, plug);
if (error_msg) {
if (type != PLUGCLOSE_NORMAL) {
/* A socket error has occurred. */
if (raw->s) {
sk_close(raw->s);

View File

@ -85,7 +85,8 @@ static void rlogin_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
}
}
static void rlogin_closing(Plug *plug, const char *error_msg, int error_code)
static void rlogin_closing(Plug *plug, PlugCloseType type,
const char *error_msg)
{
Rlogin *rlogin = container_of(plug, Rlogin, plug);
@ -103,11 +104,12 @@ static void rlogin_closing(Plug *plug, const char *error_msg, int error_code)
seat_notify_remote_exit(rlogin->seat);
seat_notify_remote_disconnect(rlogin->seat);
}
if (error_msg) {
if (type != PLUGCLOSE_NORMAL) {
/* A socket error has occurred. */
logevent(rlogin->logctx, error_msg);
seat_connection_fatal(rlogin->seat, "%s", error_msg);
} /* Otherwise, the remote side closed the connection normally. */
}
/* Otherwise, the remote side closed the connection normally. */
}
static void rlogin_receive(

View File

@ -573,7 +573,8 @@ static void supdup_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
}
}
static void supdup_closing(Plug *plug, const char *error_msg, int error_code)
static void supdup_closing(Plug *plug, PlugCloseType type,
const char *error_msg)
{
Supdup *supdup = container_of(plug, Supdup, plug);
@ -591,7 +592,7 @@ static void supdup_closing(Plug *plug, const char *error_msg, int error_code)
seat_notify_remote_exit(supdup->seat);
seat_notify_remote_disconnect(supdup->seat);
}
if (error_msg) {
if (type != PLUGCLOSE_NORMAL) {
logevent(supdup->logctx, error_msg);
seat_connection_fatal(supdup->seat, "%s", error_msg);
}

View File

@ -635,7 +635,8 @@ static void telnet_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
}
}
static void telnet_closing(Plug *plug, const char *error_msg, int error_code)
static void telnet_closing(Plug *plug, PlugCloseType type,
const char *error_msg)
{
Telnet *telnet = container_of(plug, Telnet, plug);
@ -653,7 +654,7 @@ static void telnet_closing(Plug *plug, const char *error_msg, int error_code)
seat_notify_remote_exit(telnet->seat);
seat_notify_remote_disconnect(telnet->seat);
}
if (error_msg) {
if (type != PLUGCLOSE_NORMAL) {
logevent(telnet->logctx, error_msg);
seat_connection_fatal(telnet->seat, "%s", error_msg);
}