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:
@ -1086,7 +1086,10 @@ void *sk_getxdmdata(Socket *sock, int *lenp)
|
||||
|
||||
void plug_closing_errno(Plug *plug, int error)
|
||||
{
|
||||
plug_closing(plug, strerror(error), error);
|
||||
PlugCloseType type = PLUGCLOSE_ERROR;
|
||||
if (error == EPIPE)
|
||||
type = PLUGCLOSE_BROKEN_PIPE;
|
||||
plug_closing(plug, type, strerror(error));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -249,7 +249,7 @@ static void x11_log(Plug *p, PlugLogType type, SockAddr *addr, int port,
|
||||
const char *error_msg, int error_code) {}
|
||||
static void x11_receive(Plug *plug, int urgent, const char *data, size_t len) {}
|
||||
static void x11_sent(Plug *plug, size_t bufsize) {}
|
||||
static void x11_closing(Plug *plug, const char *error_msg, int error_code)
|
||||
static void x11_closing(Plug *plug, PlugCloseType type, const char *error_msg)
|
||||
{
|
||||
time_to_die = true;
|
||||
}
|
||||
|
@ -273,9 +273,11 @@ static void server_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
|
||||
log_to_stderr(-1, error_msg);
|
||||
}
|
||||
|
||||
static void server_closing(Plug *plug, const char *error_msg, int error_code)
|
||||
static void server_closing(Plug *plug, PlugCloseType type,
|
||||
const char *error_msg)
|
||||
{
|
||||
log_to_stderr(-1, error_msg);
|
||||
if (type != PLUGCLOSE_NORMAL)
|
||||
log_to_stderr(-1, error_msg);
|
||||
}
|
||||
|
||||
static int server_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
|
||||
|
@ -482,9 +482,11 @@ static void server_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
|
||||
log_to_stderr((unsigned)-1, error_msg);
|
||||
}
|
||||
|
||||
static void server_closing(Plug *plug, const char *error_msg, int error_code)
|
||||
static void server_closing(Plug *plug, PlugCloseType type,
|
||||
const char *error_msg)
|
||||
{
|
||||
log_to_stderr((unsigned)-1, error_msg);
|
||||
if (type != PLUGCLOSE_NORMAL)
|
||||
log_to_stderr((unsigned)-1, error_msg);
|
||||
}
|
||||
|
||||
static int server_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
|
||||
|
Reference in New Issue
Block a user