1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Separate backend_send from backend_sendbuffer.

On a similar theme of separating the query operation from the
attempted change, backend_send() now no longer has the side effect of
returning the current size of the send buffer. Instead, you have to
call backend_sendbuffer() every time you want to know that.
This commit is contained in:
Simon Tatham 2021-09-12 09:52:46 +01:00
parent 82177956da
commit c336643576
15 changed files with 44 additions and 49 deletions

View File

@ -207,16 +207,14 @@ static void raw_reconfig(Backend *be, Conf *conf)
/*
* Called to send data down the raw connection.
*/
static size_t raw_send(Backend *be, const char *buf, size_t len)
static void raw_send(Backend *be, const char *buf, size_t len)
{
Raw *raw = container_of(be, Raw, backend);
if (raw->s == NULL)
return 0;
return;
raw->bufsize = sk_write(raw->s, buf, len);
return raw->bufsize;
}
/*

View File

@ -269,13 +269,13 @@ static void rlogin_reconfig(Backend *be, Conf *conf)
/*
* Called to send data down the rlogin connection.
*/
static size_t rlogin_send(Backend *be, const char *buf, size_t len)
static void rlogin_send(Backend *be, const char *buf, size_t len)
{
Rlogin *rlogin = container_of(be, Rlogin, backend);
bufchain bc;
if (rlogin->s == NULL)
return 0;
return;
bufchain_init(&bc);
bufchain_add(&bc, buf, len);
@ -305,8 +305,6 @@ static size_t rlogin_send(Backend *be, const char *buf, size_t len)
}
bufchain_clear(&bc);
return rlogin->bufsize;
}
/*

View File

@ -797,14 +797,14 @@ static void supdup_reconfig(Backend *be, Conf *conf)
/*
* Called to send data down the Supdup connection.
*/
static size_t supdup_send(Backend *be, const char *buf, size_t len)
static void supdup_send(Backend *be, const char *buf, size_t len)
{
Supdup *supdup = container_of(be, Supdup, backend);
char c;
int i;
if (supdup->s == NULL)
return 0;
return;
for (i = 0; i < len; i++) {
if (buf[i] == 034)
@ -814,7 +814,6 @@ static size_t supdup_send(Backend *be, const char *buf, size_t len)
supdup->bufsize = sk_write(supdup->s, &c, 1);
}
}
return supdup->bufsize;
}
/*

View File

@ -813,7 +813,7 @@ static void telnet_reconfig(Backend *be, Conf *conf)
/*
* Called to send data down the Telnet connection.
*/
static size_t telnet_send(Backend *be, const char *buf, size_t len)
static void telnet_send(Backend *be, const char *buf, size_t len)
{
Telnet *telnet = container_of(be, Telnet, backend);
unsigned char *p, *end;
@ -824,7 +824,7 @@ static size_t telnet_send(Backend *be, const char *buf, size_t len)
#endif
if (telnet->s == NULL)
return 0;
return;
p = (unsigned char *)buf;
end = (unsigned char *)(buf + len);
@ -841,8 +841,6 @@ static size_t telnet_send(Backend *be, const char *buf, size_t len)
p++;
}
}
return telnet->bufsize;
}
/*

View File

@ -39,9 +39,10 @@ static char *loop_init(const BackendVtable *, Seat *, Backend **, LogContext *,
static void null_free(Backend *);
static void loop_free(Backend *);
static void null_reconfig(Backend *, Conf *);
static size_t null_send(Backend *, const char *, size_t);
static size_t loop_send(Backend *, const char *, size_t);
static void null_send(Backend *, const char *, size_t);
static void loop_send(Backend *, const char *, size_t);
static size_t null_sendbuffer(Backend *);
static size_t loop_sendbuffer(Backend *);
static void null_size(Backend *, int, int);
static void null_special(Backend *, SessionSpecialCode, int);
static const SessionSpecial *null_get_specials(Backend *);
@ -80,7 +81,7 @@ const BackendVtable loop_backend = {
.free = loop_free,
.reconfig = null_reconfig,
.send = loop_send,
.sendbuffer = null_sendbuffer,
.sendbuffer = loop_sendbuffer,
.size = null_size,
.special = null_special,
.get_specials = null_get_specials,
@ -100,6 +101,7 @@ const BackendVtable loop_backend = {
struct loop_state {
Seat *seat;
Backend backend;
size_t sendbuffer;
};
static char *null_init(const BackendVtable *vt, Seat *seat,
@ -143,15 +145,14 @@ static void null_reconfig(Backend *be, Conf *conf) {
}
static size_t null_send(Backend *be, const char *buf, size_t len) {
static void null_send(Backend *be, const char *buf, size_t len) {
return 0;
}
static size_t loop_send(Backend *be, const char *buf, size_t len) {
static void loop_send(Backend *be, const char *buf, size_t len) {
struct loop_state *st = container_of(be, struct loop_state, backend);
return seat_output(st->seat, 0, buf, len);
st->sendbuffer = seat_output(st->seat, 0, buf, len);
}
static size_t null_sendbuffer(Backend *be) {
@ -159,6 +160,12 @@ static size_t null_sendbuffer(Backend *be) {
return 0;
}
static size_t loop_sendbuffer(Backend *be) {
struct loop_state *st = container_of(be, struct loop_state, backend);
return st->sendbuffer;
}
static void null_size(Backend *be, int width, int height) {
}

3
pscp.c
View File

@ -851,7 +851,8 @@ int scp_send_filedata(char *data, int len)
scp_sftp_fileoffset += len;
return 0;
} else {
int bufsize = backend_send(backend, data, len);
backend_send(backend, data, len);
int bufsize = backend_sendbuffer(backend);
/*
* If the network transfer is backing up - that is, the

View File

@ -636,9 +636,8 @@ struct BackendVtable {
void (*free) (Backend *be);
/* Pass in a replacement configuration. */
void (*reconfig) (Backend *be, Conf *conf);
/* send() returns the current amount of buffered data. */
size_t (*send) (Backend *be, const char *buf, size_t len);
/* sendbuffer() does the same thing but without attempting a send */
void (*send) (Backend *be, const char *buf, size_t len);
/* sendbuffer() returns the current amount of buffered data */
size_t (*sendbuffer) (Backend *be);
void (*size) (Backend *be, int width, int height);
void (*special) (Backend *be, SessionSpecialCode code, int arg);
@ -687,8 +686,8 @@ static inline void backend_free(Backend *be)
{ be->vt->free(be); }
static inline void backend_reconfig(Backend *be, Conf *conf)
{ be->vt->reconfig(be, conf); }
static inline size_t backend_send(Backend *be, const char *buf, size_t len)
{ return be->vt->send(be, buf, len); }
static inline void backend_send(Backend *be, const char *buf, size_t len)
{ be->vt->send(be, buf, len); }
static inline size_t backend_sendbuffer(Backend *be)
{ return be->vt->sendbuffer(be); }
static inline void backend_size(Backend *be, int width, int height)

View File

@ -270,7 +270,8 @@ static size_t sesschan_send(Channel *chan, bool is_stderr,
if (!sess->backend || sess->ignoring_input)
return 0;
return backend_send(sess->backend, data, length);
backend_send(sess->backend, data, length);
return backend_sendbuffer(sess->backend);
}
static void sesschan_send_eof(Channel *chan)

View File

@ -1003,18 +1003,16 @@ static void ssh_reconfig(Backend *be, Conf *conf)
/*
* Called to send data down the SSH connection.
*/
static size_t ssh_send(Backend *be, const char *buf, size_t len)
static void ssh_send(Backend *be, const char *buf, size_t len)
{
Ssh *ssh = container_of(be, Ssh, backend);
if (ssh == NULL || ssh->s == NULL)
return 0;
return;
bufchain_add(&ssh->user_input, buf, len);
if (ssh->base_layer)
ssh_ppl_got_user_input(ssh->base_layer);
return backend_sendbuffer(&ssh->backend);
}
/*

View File

@ -106,7 +106,8 @@ static size_t sshproxy_write(Socket *s, const void *data, size_t len)
SshProxy *sp = container_of(s, SshProxy, sock);
if (!sp->backend)
return 0;
return backend_send(sp->backend, data, len);
backend_send(sp->backend, data, len);
return backend_sendbuffer(sp->backend);
}
static size_t sshproxy_write_oob(Socket *s, const void *data, size_t len)

View File

@ -1367,17 +1367,15 @@ static void pty_try_write(Pty *pty)
/*
* Called to send data down the pty.
*/
static size_t pty_send(Backend *be, const char *buf, size_t len)
static void pty_send(Backend *be, const char *buf, size_t len)
{
Pty *pty = container_of(be, Pty, backend);
if (pty->master_i < 0 || pty->pending_eof)
return 0; /* ignore all writes if fd closed */
return; /* ignore all writes if fd closed */
bufchain_add(&pty->output_data, buf, len);
pty_try_write(pty);
return bufchain_size(&pty->output_data);
}
static void pty_close(Pty *pty)

View File

@ -461,17 +461,15 @@ static void serial_try_write(Serial *serial)
/*
* Called to send data down the serial connection.
*/
static size_t serial_send(Backend *be, const char *buf, size_t len)
static void serial_send(Backend *be, const char *buf, size_t len)
{
Serial *serial = container_of(be, Serial, backend);
if (serial->fd < 0)
return 0;
return;
bufchain_add(&serial->output_data, buf, len);
serial_try_write(serial);
return bufchain_size(&serial->output_data);
}
/*

View File

@ -287,15 +287,14 @@ static void conpty_reconfig(Backend *be, Conf *conf)
{
}
static size_t conpty_send(Backend *be, const char *buf, size_t len)
static void conpty_send(Backend *be, const char *buf, size_t len)
{
ConPTY *conpty = container_of(be, ConPTY, backend);
if (conpty->out == NULL)
return 0;
return;
conpty->bufsize = handle_write(conpty->out, buf, len);
return conpty->bufsize;
}
static size_t conpty_sendbuffer(Backend *be)

View File

@ -204,7 +204,8 @@ size_t stdin_gotdata(struct handle *h, const void *data, size_t len, int err)
noise_ultralight(NOISE_SOURCE_IOLEN, len);
if (backend_connected(backend)) {
if (len > 0) {
return backend_send(backend, data, len);
backend_send(backend, data, len);
return backend_sendbuffer(backend);
} else {
backend_special(backend, SS_EOF, 0);
return 0;

View File

@ -306,15 +306,14 @@ static void serial_reconfig(Backend *be, Conf *conf)
/*
* Called to send data down the serial connection.
*/
static size_t serial_send(Backend *be, const char *buf, size_t len)
static void serial_send(Backend *be, const char *buf, size_t len)
{
Serial *serial = container_of(be, Serial, backend);
if (serial->out == NULL)
return 0;
return;
serial->bufsize = handle_write(serial->out, buf, len);
return serial->bufsize;
}
/*