From: simon Date: Sun, 27 Aug 2006 08:03:19 +0000 (+0000) Subject: The `socket' function in the backends is only ever checked to see if X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/commitdiff_plain/6226c9390d23d6868edde63b9568891cd88631cc The `socket' function in the backends is only ever checked to see if it's NULL. Since we already have one back end (uxpty) which doesn't in fact talk to a network socket, and may well have more soon, I'm replacing this TCP/IP-centric function with a nice neutral `connected' function returning a boolean. Nothing else about its semantics has currently changed. git-svn-id: svn://svn.tartarus.org/sgt/putty@6810 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/pscp.c b/pscp.c index 5f22828a..8e082e73 100644 --- a/pscp.c +++ b/pscp.c @@ -292,7 +292,7 @@ static void bump(char *fmt, ...) sfree(str2); errs++; - if (back != NULL && back->socket(backhandle) != NULL) { + if (back != NULL && back->connected(backhandle)) { char ch; back->special(backhandle, TS_EOF); ssh_scp_recv((unsigned char *) &ch, 1); @@ -2285,7 +2285,7 @@ int psftp_main(int argc, char *argv[]) tolocal(argc, argv); } - if (back != NULL && back->socket(backhandle) != NULL) { + if (back != NULL && back->connected(backhandle)) { char ch; back->special(backhandle, TS_EOF); ssh_scp_recv((unsigned char *) &ch, 1); diff --git a/psftp.c b/psftp.c index db3ae7f5..d07ee8b0 100644 --- a/psftp.c +++ b/psftp.c @@ -952,7 +952,7 @@ int sftp_cmd_close(struct sftp_command *cmd) return 0; } - if (back != NULL && back->socket(backhandle) != NULL) { + if (back != NULL && back->connected(backhandle)) { char ch; back->special(backhandle, TS_EOF); sftp_recvdata(&ch, 1); @@ -2909,7 +2909,7 @@ int psftp_main(int argc, char *argv[]) do_sftp(mode, modeflags, batchfile); - if (back != NULL && back->socket(backhandle) != NULL) { + if (back != NULL && back->connected(backhandle)) { char ch; back->special(backhandle, TS_EOF); sftp_recvdata(&ch, 1); diff --git a/putty.h b/putty.h index 239df42d..8277bbc2 100644 --- a/putty.h +++ b/putty.h @@ -357,7 +357,7 @@ struct backend_tag { void (*size) (void *handle, int width, int height); void (*special) (void *handle, Telnet_Special code); const struct telnet_special *(*get_specials) (void *handle); - Socket(*socket) (void *handle); + int (*connected) (void *handle); int (*exitcode) (void *handle); /* If back->sendok() returns FALSE, data sent to it from the frontend * may be lost. */ diff --git a/raw.c b/raw.c index 28da09f7..d64b6d7f 100644 --- a/raw.c +++ b/raw.c @@ -209,10 +209,10 @@ static const struct telnet_special *raw_get_specials(void *handle) return NULL; } -static Socket raw_socket(void *handle) +static int raw_connected(void *handle) { Raw raw = (Raw) handle; - return raw->s; + return raw->s != NULL; } static int raw_sendok(void *handle) @@ -270,7 +270,7 @@ Backend raw_backend = { raw_size, raw_special, raw_get_specials, - raw_socket, + raw_connected, raw_exitcode, raw_sendok, raw_ldisc, diff --git a/rlogin.c b/rlogin.c index 1b9a8069..833d4ea4 100644 --- a/rlogin.c +++ b/rlogin.c @@ -280,10 +280,10 @@ static const struct telnet_special *rlogin_get_specials(void *handle) return NULL; } -static Socket rlogin_socket(void *handle) +static int rlogin_connected(void *handle) { Rlogin rlogin = (Rlogin) handle; - return rlogin->s; + return rlogin->s != NULL; } static int rlogin_sendok(void *handle) @@ -341,7 +341,7 @@ Backend rlogin_backend = { rlogin_size, rlogin_special, rlogin_get_specials, - rlogin_socket, + rlogin_connected, rlogin_exitcode, rlogin_sendok, rlogin_ldisc, diff --git a/ssh.c b/ssh.c index 969ffbc0..7c5c7bce 100644 --- a/ssh.c +++ b/ssh.c @@ -8725,10 +8725,10 @@ void ssh_send_port_open(void *channel, char *hostname, int port, char *org) } } -static Socket ssh_socket(void *handle) +static int ssh_connected(void *handle) { Ssh ssh = (Ssh) handle; - return ssh->s; + return ssh->s != NULL; } static int ssh_sendok(void *handle) @@ -8798,7 +8798,7 @@ Backend ssh_backend = { ssh_size, ssh_special, ssh_get_specials, - ssh_socket, + ssh_connected, ssh_return_exitcode, ssh_sendok, ssh_ldisc, diff --git a/telnet.c b/telnet.c index 50388337..0d32f8c2 100644 --- a/telnet.c +++ b/telnet.c @@ -1019,10 +1019,10 @@ static const struct telnet_special *telnet_get_specials(void *handle) return specials; } -static Socket telnet_socket(void *handle) +static int telnet_connected(void *handle) { Telnet telnet = (Telnet) handle; - return telnet->s; + return telnet->s != NULL; } static int telnet_sendok(void *handle) @@ -1085,7 +1085,7 @@ Backend telnet_backend = { telnet_size, telnet_special, telnet_get_specials, - telnet_socket, + telnet_connected, telnet_exitcode, telnet_sendok, telnet_ldisc, diff --git a/unix/uxplink.c b/unix/uxplink.c index 735d297b..1daafe4b 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -899,7 +899,7 @@ int main(int argc, char **argv) FD_SET_MAX(signalpipe[0], maxfd, rset); if (connopen && !sending && - back->socket(backhandle) != NULL && + back->connected(backhandle) && back->sendok(backhandle) && back->sendbuffer(backhandle) < MAX_STDIN_BACKLOG) { /* If we're OK to send, then try to read from stdin. */ @@ -1014,7 +1014,7 @@ int main(int argc, char **argv) char buf[4096]; int ret; - if (connopen && back->socket(backhandle) != NULL) { + if (connopen && back->connected(backhandle)) { ret = read(0, buf, sizeof(buf)); if (ret < 0) { perror("stdin: read"); @@ -1039,7 +1039,7 @@ int main(int argc, char **argv) try_output(1); } - if ((!connopen || back->socket(backhandle) == NULL) && + if ((!connopen || !back->connected(backhandle)) && bufchain_size(&stdout_data) == 0 && bufchain_size(&stderr_data) == 0) break; /* we closed the connection */ diff --git a/unix/uxpty.c b/unix/uxpty.c index 637eaa1a..50e53714 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -1008,10 +1008,10 @@ static const struct telnet_special *pty_get_specials(void *handle) return NULL; } -static Socket pty_socket(void *handle) +static int pty_connected(void *handle) { /* Pty pty = (Pty)handle; */ - return NULL; /* shouldn't ever be needed */ + return TRUE; } static int pty_sendok(void *handle) @@ -1068,7 +1068,7 @@ Backend pty_backend = { pty_size, pty_special, pty_get_specials, - pty_socket, + pty_connected, pty_exitcode, pty_sendok, pty_ldisc, diff --git a/windows/winplink.c b/windows/winplink.c index c784a5dc..16351ae9 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -218,7 +218,7 @@ int stdin_gotdata(struct handle *h, void *data, int len) cleanup_exit(0); } noise_ultralight(len); - if (connopen && back->socket(backhandle) != NULL) { + if (connopen && back->connected(backhandle)) { if (len > 0) { return back->send(backhandle, data, len); } else { @@ -239,7 +239,7 @@ void stdouterr_sent(struct handle *h, int new_backlog) (h == stdout_handle ? "output" : "error")); cleanup_exit(0); } - if (connopen && back->socket(backhandle) != NULL) { + if (connopen && back->connected(backhandle)) { back->unthrottle(backhandle, (handle_backlog(stdout_handle) + handle_backlog(stderr_handle))); } @@ -694,7 +694,7 @@ int main(int argc, char **argv) if (sending) handle_unthrottle(stdin_handle, back->sendbuffer(backhandle)); - if ((!connopen || back->socket(backhandle) == NULL) && + if ((!connopen || !back->connected(backhandle)) && handle_backlog(stdout_handle) + handle_backlog(stderr_handle) == 0) break; /* we closed the connection */ }