mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22: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:
@ -158,7 +158,7 @@ static void fdsocket_error_callback(void *vs)
|
||||
/*
|
||||
* An error has occurred on this socket. Pass it to the plug.
|
||||
*/
|
||||
plug_closing(fds->plug, strerror(fds->pending_error), fds->pending_error);
|
||||
plug_closing_errno(fds->plug, fds->pending_error);
|
||||
}
|
||||
|
||||
static int fdsocket_try_send(FdSocket *fds)
|
||||
@ -270,9 +270,9 @@ static void fdsocket_select_result_input(int fd, int event)
|
||||
fds->infd = -1;
|
||||
|
||||
if (retd < 0) {
|
||||
plug_closing(fds->plug, strerror(errno), errno);
|
||||
plug_closing_errno(fds->plug, errno);
|
||||
} else {
|
||||
plug_closing(fds->plug, NULL, 0);
|
||||
plug_closing_normal(fds->plug);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1084,6 +1084,11 @@ void *sk_getxdmdata(Socket *sock, int *lenp)
|
||||
return buf;
|
||||
}
|
||||
|
||||
void plug_closing_errno(Plug *plug, int error)
|
||||
{
|
||||
plug_closing(plug, strerror(error), error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Deal with socket errors detected in try_send().
|
||||
*/
|
||||
@ -1101,7 +1106,7 @@ static void socket_error_callback(void *vs)
|
||||
/*
|
||||
* An error has occurred on this socket. Pass it to the plug.
|
||||
*/
|
||||
plug_closing(s->plug, strerror(s->pending_error), s->pending_error);
|
||||
plug_closing_errno(s->plug, s->pending_error);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1295,10 +1300,10 @@ static void net_select_result(int fd, int event)
|
||||
*/
|
||||
ret = recv(s->s, buf, sizeof(buf), MSG_OOB);
|
||||
noise_ultralight(NOISE_SOURCE_IOLEN, ret);
|
||||
if (ret <= 0) {
|
||||
plug_closing(s->plug,
|
||||
ret == 0 ? "Internal networking trouble" :
|
||||
strerror(errno), errno);
|
||||
if (ret == 0) {
|
||||
plug_closing_error(s->plug, "Internal networking trouble");
|
||||
} else if (ret < 0) {
|
||||
plug_closing_errno(s->plug, errno);
|
||||
} else {
|
||||
/*
|
||||
* Receiving actual data on a socket means we can
|
||||
@ -1384,11 +1389,11 @@ static void net_select_result(int fd, int event)
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
plug_closing(s->plug, strerror(errno), errno);
|
||||
plug_closing_errno(s->plug, errno);
|
||||
} else if (0 == ret) {
|
||||
s->incomingeof = true; /* stop trying to read now */
|
||||
uxsel_tell(s);
|
||||
plug_closing(s->plug, NULL, 0);
|
||||
plug_closing_normal(s->plug);
|
||||
} else {
|
||||
/*
|
||||
* Receiving actual data on a socket means we can
|
||||
@ -1438,7 +1443,7 @@ static void net_select_result(int fd, int event)
|
||||
err = try_connect(s);
|
||||
}
|
||||
if (err) {
|
||||
plug_closing(s->plug, strerror(err), err);
|
||||
plug_closing_errno(s->plug, err);
|
||||
return; /* socket is now presumably defunct */
|
||||
}
|
||||
if (!s->connected)
|
||||
|
@ -458,4 +458,7 @@ bool cliloop_no_pw_setup(void *ctx, pollwrapper *pw);
|
||||
void cliloop_no_pw_check(void *ctx, pollwrapper *pw);
|
||||
bool cliloop_always_continue(void *ctx, bool, bool);
|
||||
|
||||
/* network.c: network error reporting helper taking an OS error code */
|
||||
void plug_closing_errno(Plug *plug, int error);
|
||||
|
||||
#endif /* PUTTY_UNIX_PLATFORM_H */
|
||||
|
Reference in New Issue
Block a user