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

Make bufchain_prefix return a ptrlen.

Now that all the call sites are expecting a size_t instead of an int
length field, it's no longer particularly difficult to make it
actually return the pointer,length pair in the form of a ptrlen.

It would be nice to say that simplifies call sites because those
ptrlens can all be passed straight along to other ptrlen-consuming
functions. Actually almost none of the call sites are like that _yet_,
but this makes it possible to move them in that direction in future
(as part of my general aim to migrate ptrlen-wards as much as I can).
But also it's just nicer to keep the pointer and length together in
one variable, and not have to declare them both in advance with two
extra lines of boilerplate.
This commit is contained in:
Simon Tatham 2019-02-06 20:46:45 +00:00
parent 0cda34c6f8
commit 59f7b24b9d
27 changed files with 128 additions and 163 deletions

View File

@ -137,11 +137,9 @@ static void logfopen_callback(void *vctx, int mode)
*/ */
assert(ctx->state != L_OPENING); /* make _sure_ it won't be requeued */ assert(ctx->state != L_OPENING); /* make _sure_ it won't be requeued */
while (bufchain_size(&ctx->queue)) { while (bufchain_size(&ctx->queue)) {
void *data; ptrlen data = bufchain_prefix(&ctx->queue);
size_t len; logwrite(ctx, data.ptr, data.len);
bufchain_prefix(&ctx->queue, &data, &len); bufchain_consume(&ctx->queue, data.len);
logwrite(ctx, data, len);
bufchain_consume(&ctx->queue, len);
} }
logflush(ctx); logflush(ctx);
} }

2
misc.h
View File

@ -105,7 +105,7 @@ void bufchain_init(bufchain *ch);
void bufchain_clear(bufchain *ch); void bufchain_clear(bufchain *ch);
size_t bufchain_size(bufchain *ch); size_t bufchain_size(bufchain *ch);
void bufchain_add(bufchain *ch, const void *data, size_t len); void bufchain_add(bufchain *ch, const void *data, size_t len);
void bufchain_prefix(bufchain *ch, void **data, size_t *len); ptrlen bufchain_prefix(bufchain *ch);
void bufchain_consume(bufchain *ch, size_t len); void bufchain_consume(bufchain *ch, size_t len);
void bufchain_fetch(bufchain *ch, void *data, size_t len); void bufchain_fetch(bufchain *ch, void *data, size_t len);
void bufchain_fetch_consume(bufchain *ch, void *data, size_t len); void bufchain_fetch_consume(bufchain *ch, void *data, size_t len);

View File

@ -16,7 +16,7 @@ printer_job *printer_start_job(char *printer)
return NULL; return NULL;
} }
void printer_job_data(printer_job *pj, void *data, int len) void printer_job_data(printer_job *pj, void *data, size_t len)
{ {
} }

29
proxy.c
View File

@ -24,8 +24,7 @@
*/ */
void proxy_activate (ProxySocket *p) void proxy_activate (ProxySocket *p)
{ {
void *data; size_t output_before, output_after;
size_t len, output_before, output_after;
p->state = PROXY_STATE_ACTIVE; p->state = PROXY_STATE_ACTIVE;
@ -42,16 +41,16 @@ void proxy_activate (ProxySocket *p)
/* send buffered OOB writes */ /* send buffered OOB writes */
while (bufchain_size(&p->pending_oob_output_data) > 0) { while (bufchain_size(&p->pending_oob_output_data) > 0) {
bufchain_prefix(&p->pending_oob_output_data, &data, &len); ptrlen data = bufchain_prefix(&p->pending_oob_output_data);
output_after += sk_write_oob(p->sub_socket, data, len); output_after += sk_write_oob(p->sub_socket, data.ptr, data.len);
bufchain_consume(&p->pending_oob_output_data, len); bufchain_consume(&p->pending_oob_output_data, data.len);
} }
/* send buffered normal writes */ /* send buffered normal writes */
while (bufchain_size(&p->pending_output_data) > 0) { while (bufchain_size(&p->pending_output_data) > 0) {
bufchain_prefix(&p->pending_output_data, &data, &len); ptrlen data = bufchain_prefix(&p->pending_output_data);
output_after += sk_write(p->sub_socket, data, len); output_after += sk_write(p->sub_socket, data.ptr, data.len);
bufchain_consume(&p->pending_output_data, len); bufchain_consume(&p->pending_output_data, data.len);
} }
/* if we managed to send any data, let the higher levels know. */ /* if we managed to send any data, let the higher levels know. */
@ -159,15 +158,13 @@ static void sk_proxy_set_frozen (Socket *s, bool is_frozen)
* so we have to check each time. * so we have to check each time.
*/ */
while (!ps->freeze && bufchain_size(&ps->pending_input_data) > 0) { while (!ps->freeze && bufchain_size(&ps->pending_input_data) > 0) {
void *data;
char databuf[512]; char databuf[512];
size_t len; ptrlen data = bufchain_prefix(&ps->pending_input_data);
bufchain_prefix(&ps->pending_input_data, &data, &len); if (data.len > lenof(databuf))
if (len > lenof(databuf)) data.len = lenof(databuf);
len = lenof(databuf); memcpy(databuf, data.ptr, data.len);
memcpy(databuf, data, len); bufchain_consume(&ps->pending_input_data, data.len);
bufchain_consume(&ps->pending_input_data, len); plug_receive(ps->plug, 0, databuf, data.len);
plug_receive(ps->plug, 0, databuf, len);
} }
/* if we're still frozen, we'll have to wait for another /* if we're still frozen, we'll have to wait for another

View File

@ -1841,7 +1841,7 @@ printer_enum *printer_start_enum(int *nprinters);
char *printer_get_name(printer_enum *, int); char *printer_get_name(printer_enum *, int);
void printer_finish_enum(printer_enum *); void printer_finish_enum(printer_enum *);
printer_job *printer_start_job(char *printer); printer_job *printer_start_job(char *printer);
void printer_job_data(printer_job *, void *, int); void printer_job_data(printer_job *, const void *, size_t);
void printer_finish_job(printer_job *); void printer_finish_job(printer_job *);
/* /*

View File

@ -287,10 +287,8 @@ static size_t rlogin_send(Backend *be, const char *buf, size_t len)
if (!rlogin->prompt) { if (!rlogin->prompt) {
while (bufchain_size(&bc) > 0) { while (bufchain_size(&bc) > 0) {
void *data; ptrlen data = bufchain_prefix(&bc);
size_t len; rlogin->bufsize = sk_write(rlogin->s, data.ptr, data.len);
bufchain_prefix(&bc, &data, &len);
rlogin->bufsize = sk_write(rlogin->s, data, len);
bufchain_consume(&bc, len); bufchain_consume(&bc, len);
} }
} }

View File

@ -1077,17 +1077,13 @@ static void scp_sink_coroutine(ScpSink *scp)
if (scp->input_eof) if (scp->input_eof)
goto done; goto done;
void *vdata; ptrlen data = bufchain_prefix(&scp->data);
size_t len; const char *cdata = data.ptr;
const char *cdata, *newline; const char *newline = memchr(cdata, '\012', data.len);
bufchain_prefix(&scp->data, &vdata, &len);
cdata = vdata;
newline = memchr(cdata, '\012', len);
if (newline) if (newline)
len = (int)(newline+1 - cdata); data.len = (int)(newline+1 - cdata);
put_data(scp->command, cdata, len); put_data(scp->command, cdata, data.len);
bufchain_consume(&scp->data, len); bufchain_consume(&scp->data, data.len);
if (newline) if (newline)
break; break;
@ -1179,8 +1175,7 @@ static void scp_sink_coroutine(ScpSink *scp)
sshfwd_write(scp->sc, "\0", 1); sshfwd_write(scp->sc, "\0", 1);
scp->file_offset = 0; scp->file_offset = 0;
while (scp->file_offset < scp->file_size) { while (scp->file_offset < scp->file_size) {
void *vdata; ptrlen data;
size_t len;
uint64_t this_len, remaining; uint64_t this_len, remaining;
crMaybeWaitUntilV( crMaybeWaitUntilV(
@ -1191,14 +1186,14 @@ static void scp_sink_coroutine(ScpSink *scp)
goto done; goto done;
} }
bufchain_prefix(&scp->data, &vdata, &len); data = bufchain_prefix(&scp->data);
this_len = len; this_len = data.len;
remaining = scp->file_size - scp->file_offset; remaining = scp->file_size - scp->file_offset;
if (this_len > remaining) if (this_len > remaining)
this_len = remaining; this_len = remaining;
sftpsrv_write(scp->sf, &scp->reply.srb, sftpsrv_write(scp->sf, &scp->reply.srb,
scp->reply.handle, scp->file_offset, scp->reply.handle, scp->file_offset,
make_ptrlen(vdata, this_len)); make_ptrlen(data.ptr, this_len));
if (scp->reply.err) { if (scp->reply.err) {
scp->errmsg = dupprintf( scp->errmsg = dupprintf(
"'%.*s': unable to write to file: %s", "'%.*s': unable to write to file: %s",

11
ssh.c
View File

@ -348,17 +348,16 @@ static void ssh_bpp_output_raw_data_callback(void *vctx)
return; return;
while (bufchain_size(&ssh->out_raw) > 0) { while (bufchain_size(&ssh->out_raw) > 0) {
void *data; size_t backlog;
size_t len, backlog;
bufchain_prefix(&ssh->out_raw, &data, &len); ptrlen data = bufchain_prefix(&ssh->out_raw);
if (ssh->logctx) if (ssh->logctx)
log_packet(ssh->logctx, PKT_OUTGOING, -1, NULL, data, len, log_packet(ssh->logctx, PKT_OUTGOING, -1, NULL, data.ptr, data.len,
0, NULL, NULL, 0, NULL); 0, NULL, NULL, 0, NULL);
backlog = sk_write(ssh->s, data, len); backlog = sk_write(ssh->s, data.ptr, data.len);
bufchain_consume(&ssh->out_raw, len); bufchain_consume(&ssh->out_raw, data.len);
if (backlog > SSH_MAX_BACKLOG) { if (backlog > SSH_MAX_BACKLOG) {
ssh_throttle_all(ssh, true, backlog); ssh_throttle_all(ssh, true, backlog);

View File

@ -780,13 +780,11 @@ static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl)
/* /*
* Add user input to the main channel's buffer. * Add user input to the main channel's buffer.
*/ */
void *data; ptrlen data = bufchain_prefix(s->ppl.user_input);
size_t len; if (data.len > 512)
bufchain_prefix(s->ppl.user_input, &data, &len); data.len = 512;
if (len > 512) sshfwd_write(&s->mainchan_sc, data.ptr, data.len);
len = 512; bufchain_consume(s->ppl.user_input, data.len);
sshfwd_write(&s->mainchan_sc, data, len);
bufchain_consume(s->ppl.user_input, len);
} }
} }

View File

@ -1064,16 +1064,14 @@ static size_t ssh2_try_send(struct ssh2_channel *c)
while (c->remwindow > 0 && while (c->remwindow > 0 &&
(bufchain_size(&c->outbuffer) > 0 || (bufchain_size(&c->outbuffer) > 0 ||
bufchain_size(&c->errbuffer) > 0)) { bufchain_size(&c->errbuffer) > 0)) {
size_t len;
void *data;
bufchain *buf = (bufchain_size(&c->errbuffer) > 0 ? bufchain *buf = (bufchain_size(&c->errbuffer) > 0 ?
&c->errbuffer : &c->outbuffer); &c->errbuffer : &c->outbuffer);
bufchain_prefix(buf, &data, &len); ptrlen data = bufchain_prefix(buf);
if (len > c->remwindow) if (data.len > c->remwindow)
len = c->remwindow; data.len = c->remwindow;
if (len > c->remmaxpkt) if (data.len > c->remmaxpkt)
len = c->remmaxpkt; data.len = c->remmaxpkt;
if (buf == &c->errbuffer) { if (buf == &c->errbuffer) {
pktout = ssh_bpp_new_pktout( pktout = ssh_bpp_new_pktout(
s->ppl.bpp, SSH2_MSG_CHANNEL_EXTENDED_DATA); s->ppl.bpp, SSH2_MSG_CHANNEL_EXTENDED_DATA);
@ -1083,10 +1081,10 @@ static size_t ssh2_try_send(struct ssh2_channel *c)
pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_DATA); pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_DATA);
put_uint32(pktout, c->remoteid); put_uint32(pktout, c->remoteid);
} }
put_string(pktout, data, len); put_stringpl(pktout, data);
pq_push(s->ppl.out_pq, pktout); pq_push(s->ppl.out_pq, pktout);
bufchain_consume(buf, len); bufchain_consume(buf, data.len);
c->remwindow -= len; c->remwindow -= data.len;
} }
/* /*
@ -1670,11 +1668,9 @@ static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl)
/* /*
* Add user input to the main channel's buffer. * Add user input to the main channel's buffer.
*/ */
void *data; ptrlen data = bufchain_prefix(s->ppl.user_input);
size_t len; sshfwd_write(s->mainchan_sc, data.ptr, data.len);
bufchain_prefix(s->ppl.user_input, &data, &len); bufchain_consume(s->ppl.user_input, data.len);
sshfwd_write(s->mainchan_sc, data, len);
bufchain_consume(s->ppl.user_input, len);
} }
} }

View File

@ -465,11 +465,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
if (bufchain_size(&s->banner) && if (bufchain_size(&s->banner) &&
(flags & (FLAG_VERBOSE | FLAG_INTERACTIVE))) { (flags & (FLAG_VERBOSE | FLAG_INTERACTIVE))) {
while (bufchain_size(&s->banner) > 0) { while (bufchain_size(&s->banner) > 0) {
void *data; ptrlen data = bufchain_prefix(&s->banner);
size_t len; seat_stderr(s->ppl.seat, data.ptr, data.len);
bufchain_prefix(&s->banner, &data, &len); bufchain_consume(&s->banner, data.len);
seat_stderr(s->ppl.seat, data, len);
bufchain_consume(&s->banner, len);
} }
} }
bufchain_clear(&s->banner); bufchain_clear(&s->banner);

View File

@ -333,17 +333,16 @@ static void server_bpp_output_raw_data_callback(void *vctx)
return; return;
while (bufchain_size(&srv->out_raw) > 0) { while (bufchain_size(&srv->out_raw) > 0) {
void *data; size_t backlog;
size_t len, backlog;
bufchain_prefix(&srv->out_raw, &data, &len); ptrlen data = bufchain_prefix(&srv->out_raw);
if (srv->logctx) if (srv->logctx)
log_packet(srv->logctx, PKT_OUTGOING, -1, NULL, data, len, log_packet(srv->logctx, PKT_OUTGOING, -1, NULL, data.ptr, data.len,
0, NULL, NULL, 0, NULL); 0, NULL, NULL, 0, NULL);
backlog = sk_write(srv->socket, data, len); backlog = sk_write(srv->socket, data.ptr, data.len);
bufchain_consume(&srv->out_raw, len); bufchain_consume(&srv->out_raw, data.len);
if (backlog > SSH_MAX_BACKLOG) { if (backlog > SSH_MAX_BACKLOG) {
#ifdef FIXME #ifdef FIXME

View File

@ -249,19 +249,18 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
* If we didn't find it, consume data until we see a newline. * If we didn't find it, consume data until we see a newline.
*/ */
while (1) { while (1) {
size_t len; ptrlen data;
void *data;
char *nl; char *nl;
/* Wait to receive at least 1 byte, but then consume more /* Wait to receive at least 1 byte, but then consume more
* than that if it's there. */ * than that if it's there. */
BPP_WAITFOR(1); BPP_WAITFOR(1);
bufchain_prefix(s->bpp.in_raw, &data, &len); data = bufchain_prefix(s->bpp.in_raw);
if ((nl = memchr(data, '\012', len)) != NULL) { if ((nl = memchr(data.ptr, '\012', data.len)) != NULL) {
bufchain_consume(s->bpp.in_raw, nl - (char *)data + 1); bufchain_consume(s->bpp.in_raw, nl - (char *)data.ptr + 1);
break; break;
} else { } else {
bufchain_consume(s->bpp.in_raw, len); bufchain_consume(s->bpp.in_raw, data.len);
} }
} }
} }
@ -281,24 +280,24 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
*/ */
s->i = 0; s->i = 0;
do { do {
size_t len; ptrlen data;
void *data;
char *nl; char *nl;
BPP_WAITFOR(1); BPP_WAITFOR(1);
bufchain_prefix(s->bpp.in_raw, &data, &len); data = bufchain_prefix(s->bpp.in_raw);
if ((nl = memchr(data, '\012', len)) != NULL) { if ((nl = memchr(data.ptr, '\012', data.len)) != NULL) {
len = nl - (char *)data + 1; data.len = nl - (char *)data.ptr + 1;
} }
if (s->vslen >= s->vstrsize - 1 || len >= s->vstrsize - 1 - s->vslen) { if (s->vslen >= s->vstrsize - 1 ||
s->vstrsize = (s->vslen + len) * 5 / 4 + 32; data.len >= s->vstrsize - 1 - s->vslen) {
s->vstrsize = (s->vslen + data.len) * 5 / 4 + 32;
s->vstring = sresize(s->vstring, s->vstrsize, char); s->vstring = sresize(s->vstring, s->vstrsize, char);
} }
memcpy(s->vstring + s->vslen, data, len); memcpy(s->vstring + s->vslen, data.ptr, data.len);
s->vslen += len; s->vslen += data.len;
bufchain_consume(s->bpp.in_raw, len); bufchain_consume(s->bpp.in_raw, data.len);
} while (s->vstring[s->vslen-1] != '\012'); } while (s->vstring[s->vslen-1] != '\012');

View File

@ -2691,20 +2691,18 @@ static void term_print_setup(Terminal *term, char *printer)
} }
static void term_print_flush(Terminal *term) static void term_print_flush(Terminal *term)
{ {
void *data; size_t size;
size_t len, size;
while ((size = bufchain_size(&term->printer_buf)) > 5) { while ((size = bufchain_size(&term->printer_buf)) > 5) {
bufchain_prefix(&term->printer_buf, &data, &len); ptrlen data = bufchain_prefix(&term->printer_buf);
if (len > size-5) if (data.len > size-5)
len = size-5; data.len = size-5;
printer_job_data(term->print_job, data, len); printer_job_data(term->print_job, data.ptr, data.len);
bufchain_consume(&term->printer_buf, len); bufchain_consume(&term->printer_buf, data.len);
} }
} }
static void term_print_finish(Terminal *term) static void term_print_finish(Terminal *term)
{ {
void *data; size_t size;
size_t len, size;
char c; char c;
if (!term->printing && !term->only_printing) if (!term->printing && !term->only_printing)
@ -2712,8 +2710,8 @@ static void term_print_finish(Terminal *term)
term_print_flush(term); term_print_flush(term);
while ((size = bufchain_size(&term->printer_buf)) > 0) { while ((size = bufchain_size(&term->printer_buf)) > 0) {
bufchain_prefix(&term->printer_buf, &data, &len); ptrlen data = bufchain_prefix(&term->printer_buf);
c = *(char *)data; c = *(char *)data.ptr;
if (c == '\033' || c == '\233') { if (c == '\033' || c == '\233') {
bufchain_consume(&term->printer_buf, size); bufchain_consume(&term->printer_buf, size);
break; break;
@ -2882,14 +2880,15 @@ static void term_out(Terminal *term)
while (nchars > 0 || unget != -1 || bufchain_size(&term->inbuf) > 0) { while (nchars > 0 || unget != -1 || bufchain_size(&term->inbuf) > 0) {
if (unget == -1) { if (unget == -1) {
if (nchars == 0) { if (nchars == 0) {
void *ret; ptrlen data = bufchain_prefix(&term->inbuf);
bufchain_prefix(&term->inbuf, &ret, &nchars); if (data.len > sizeof(localbuf))
if (nchars > sizeof(localbuf)) data.len = sizeof(localbuf);
nchars = sizeof(localbuf); memcpy(localbuf, data.ptr, data.len);
memcpy(localbuf, ret, nchars); bufchain_consume(&term->inbuf, data.len);
bufchain_consume(&term->inbuf, nchars); nchars = data.len;
chars = localbuf; chars = localbuf;
assert(chars != NULL); assert(chars != NULL);
assert(nchars > 0);
} }
c = *chars++; c = *chars++;
nchars--; nchars--;

View File

@ -493,14 +493,13 @@ static void console_close(FILE *outfp, int infd)
static void console_prompt_text(FILE *outfp, const char *data, size_t len) static void console_prompt_text(FILE *outfp, const char *data, size_t len)
{ {
bufchain sanitised; bufchain sanitised;
void *vdata;
bufchain_init(&sanitised); bufchain_init(&sanitised);
sanitise_term_data(&sanitised, data, len); sanitise_term_data(&sanitised, data, len);
while (bufchain_size(&sanitised) > 0) { while (bufchain_size(&sanitised) > 0) {
bufchain_prefix(&sanitised, &vdata, &len); ptrlen sdata = bufchain_prefix(&sanitised);
fwrite(vdata, 1, len, outfp); fwrite(sdata.ptr, 1, sdata.len, outfp);
bufchain_consume(&sanitised, len); bufchain_consume(&sanitised, sdata.len);
} }
fflush(outfp); fflush(outfp);
} }

View File

@ -162,12 +162,10 @@ static int fdsocket_try_send(FdSocket *fds)
int sent = 0; int sent = 0;
while (bufchain_size(&fds->pending_output_data) > 0) { while (bufchain_size(&fds->pending_output_data) > 0) {
void *data;
size_t len;
ssize_t ret; ssize_t ret;
bufchain_prefix(&fds->pending_output_data, &data, &len); ptrlen data = bufchain_prefix(&fds->pending_output_data);
ret = write(fds->outfd, data, len); ret = write(fds->outfd, data.ptr, data.len);
noise_ultralight(NOISE_SOURCE_IOID, ret); noise_ultralight(NOISE_SOURCE_IOID, ret);
if (ret < 0 && errno != EWOULDBLOCK) { if (ret < 0 && errno != EWOULDBLOCK) {
if (!fds->pending_error) { if (!fds->pending_error) {

View File

@ -1111,7 +1111,7 @@ void try_send(NetSocket *s)
while (s->sending_oob || bufchain_size(&s->output_data) > 0) { while (s->sending_oob || bufchain_size(&s->output_data) > 0) {
int nsent; int nsent;
int err; int err;
void *data; const void *data;
size_t len; size_t len;
int urgentflag; int urgentflag;
@ -1121,7 +1121,9 @@ void try_send(NetSocket *s)
data = &s->oobdata; data = &s->oobdata;
} else { } else {
urgentflag = 0; urgentflag = 0;
bufchain_prefix(&s->output_data, &data, &len); ptrlen bufdata = bufchain_prefix(&s->output_data);
data = bufdata.ptr;
len = bufdata.len;
} }
nsent = send(s->s, data, len, urgentflag); nsent = send(s->s, data, len, urgentflag);
noise_ultralight(NOISE_SOURCE_IOLEN, nsent); noise_ultralight(NOISE_SOURCE_IOLEN, nsent);

View File

@ -329,18 +329,17 @@ size_t try_output(bool is_stderr)
{ {
bufchain *chain = (is_stderr ? &stderr_data : &stdout_data); bufchain *chain = (is_stderr ? &stderr_data : &stdout_data);
int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO); int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO);
void *senddata;
size_t sendlen;
ssize_t ret; ssize_t ret;
if (bufchain_size(chain) > 0) { if (bufchain_size(chain) > 0) {
bool prev_nonblock = nonblock(fd); bool prev_nonblock = nonblock(fd);
ptrlen senddata;
do { do {
bufchain_prefix(chain, &senddata, &sendlen); senddata = bufchain_prefix(chain);
ret = write(fd, senddata, sendlen); ret = write(fd, senddata.ptr, senddata.len);
if (ret > 0) if (ret > 0)
bufchain_consume(chain, ret); bufchain_consume(chain, ret);
} while (ret == sendlen && bufchain_size(chain) != 0); } while (ret == senddata.len && bufchain_size(chain) != 0);
if (!prev_nonblock) if (!prev_nonblock)
no_nonblock(fd); no_nonblock(fd);
if (ret < 0 && errno != EAGAIN) { if (ret < 0 && errno != EAGAIN) {

View File

@ -25,7 +25,7 @@ printer_job *printer_start_job(char *printer)
return ret; return ret;
} }
void printer_job_data(printer_job *pj, void *data, int len) void printer_job_data(printer_job *pj, const void *data, size_t len)
{ {
if (!pj) if (!pj)
return; return;

View File

@ -1309,15 +1309,13 @@ static void pty_free(Backend *be)
static void pty_try_write(Pty *pty) static void pty_try_write(Pty *pty)
{ {
void *data;
size_t len;
ssize_t ret; ssize_t ret;
assert(pty->master_i >= 0); assert(pty->master_i >= 0);
while (bufchain_size(&pty->output_data) > 0) { while (bufchain_size(&pty->output_data) > 0) {
bufchain_prefix(&pty->output_data, &data, &len); ptrlen data = bufchain_prefix(&pty->output_data);
ret = write(pty->master_i, data, len); ret = write(pty->master_i, data.ptr, data.len);
if (ret < 0 && (errno == EWOULDBLOCK)) { if (ret < 0 && (errno == EWOULDBLOCK)) {
/* /*

View File

@ -422,15 +422,13 @@ static void serial_uxsel_setup(Serial *serial)
static void serial_try_write(Serial *serial) static void serial_try_write(Serial *serial)
{ {
void *data;
size_t len;
ssize_t ret; ssize_t ret;
assert(serial->fd >= 0); assert(serial->fd >= 0);
while (bufchain_size(&serial->output_data) > 0) { while (bufchain_size(&serial->output_data) > 0) {
bufchain_prefix(&serial->output_data, &data, &len); ptrlen data = bufchain_prefix(&serial->output_data);
ret = write(serial->fd, data, len); ret = write(serial->fd, data.ptr, data.len);
if (ret < 0 && (errno == EWOULDBLOCK)) { if (ret < 0 && (errno == EWOULDBLOCK)) {
/* /*

View File

@ -714,10 +714,9 @@ void bufchain_consume(bufchain *ch, size_t len)
} }
} }
void bufchain_prefix(bufchain *ch, void **data, size_t *len) ptrlen bufchain_prefix(bufchain *ch)
{ {
*len = ch->head->bufend - ch->head->bufpos; return make_ptrlen(ch->head->bufpos, ch->head->bufend - ch->head->bufpos);
*data = ch->head->bufpos;
} }
void bufchain_fetch(bufchain *ch, void *data, size_t len) void bufchain_fetch(bufchain *ch, void *data, size_t len)

View File

@ -392,14 +392,13 @@ static void console_data_untrusted(HANDLE hout, const char *data, size_t len)
{ {
DWORD dummy; DWORD dummy;
bufchain sanitised; bufchain sanitised;
void *vdata;
bufchain_init(&sanitised); bufchain_init(&sanitised);
sanitise_term_data(&sanitised, data, len); sanitise_term_data(&sanitised, data, len);
while (bufchain_size(&sanitised) > 0) { while (bufchain_size(&sanitised) > 0) {
bufchain_prefix(&sanitised, &vdata, &len); ptrlen sdata = bufchain_prefix(&sanitised);
WriteFile(hout, vdata, len, &dummy, NULL); WriteFile(hout, sdata.ptr, sdata.len, &dummy, NULL);
bufchain_consume(&sanitised, len); bufchain_consume(&sanitised, sdata.len);
} }
} }

View File

@ -257,7 +257,7 @@ struct handle_output {
* Data set by the main thread before signalling ev_from_main, * Data set by the main thread before signalling ev_from_main,
* and read by the input thread after receiving that signal. * and read by the input thread after receiving that signal.
*/ */
char *buffer; /* the data to write */ const char *buffer; /* the data to write */
DWORD len; /* how much data there is */ DWORD len; /* how much data there is */
/* /*
@ -347,13 +347,10 @@ static DWORD WINAPI handle_output_threadfunc(void *param)
static void handle_try_output(struct handle_output *ctx) static void handle_try_output(struct handle_output *ctx)
{ {
void *senddata;
size_t sendlen;
if (!ctx->busy && bufchain_size(&ctx->queued_data)) { if (!ctx->busy && bufchain_size(&ctx->queued_data)) {
bufchain_prefix(&ctx->queued_data, &senddata, &sendlen); ptrlen data = bufchain_prefix(&ctx->queued_data);
ctx->buffer = senddata; ctx->buffer = data.ptr;
ctx->len = min(sendlen, ~(DWORD)0); ctx->len = min(data.len, ~(DWORD)0);
SetEvent(ctx->ev_from_main); SetEvent(ctx->ev_from_main);
ctx->busy = true; ctx->busy = true;
} else if (!ctx->busy && bufchain_size(&ctx->queued_data) == 0 && } else if (!ctx->busy && bufchain_size(&ctx->queued_data) == 0 &&

View File

@ -164,8 +164,6 @@ static void sk_handle_flush(Socket *s)
static void handle_socket_unfreeze(void *hsv) static void handle_socket_unfreeze(void *hsv)
{ {
HandleSocket *hs = (HandleSocket *)hsv; HandleSocket *hs = (HandleSocket *)hsv;
void *data;
size_t len;
/* /*
* If we've been put into a state other than THAWING since the * If we've been put into a state other than THAWING since the
@ -177,16 +175,16 @@ static void handle_socket_unfreeze(void *hsv)
/* /*
* Get some of the data we've buffered. * Get some of the data we've buffered.
*/ */
bufchain_prefix(&hs->inputdata, &data, &len); ptrlen data = bufchain_prefix(&hs->inputdata);
assert(len > 0); assert(data.len > 0);
/* /*
* Hand it off to the plug. Be careful of re-entrance - that might * Hand it off to the plug. Be careful of re-entrance - that might
* have the effect of trying to close this socket. * have the effect of trying to close this socket.
*/ */
hs->defer_close = true; hs->defer_close = true;
plug_receive(hs->plug, 0, data, len); plug_receive(hs->plug, 0, data.ptr, data.len);
bufchain_consume(&hs->inputdata, len); bufchain_consume(&hs->inputdata, data.len);
hs->defer_close = false; hs->defer_close = false;
if (hs->deferred_close) { if (hs->deferred_close) {
sk_handle_close(&hs->sock); sk_handle_close(&hs->sock);

View File

@ -1377,7 +1377,7 @@ void try_send(NetSocket *s)
while (s->sending_oob || bufchain_size(&s->output_data) > 0) { while (s->sending_oob || bufchain_size(&s->output_data) > 0) {
int nsent; int nsent;
DWORD err; DWORD err;
void *data; const void *data;
size_t len; size_t len;
int urgentflag; int urgentflag;
@ -1387,7 +1387,9 @@ void try_send(NetSocket *s)
data = &s->oobdata; data = &s->oobdata;
} else { } else {
urgentflag = 0; urgentflag = 0;
bufchain_prefix(&s->output_data, &data, &len); ptrlen bufdata = bufchain_prefix(&s->output_data);
data = bufdata.ptr;
len = bufdata.len;
} }
len = min(len, INT_MAX); /* WinSock send() takes an int */ len = min(len, INT_MAX); /* WinSock send() takes an int */
nsent = p_send(s->s, data, len, urgentflag); nsent = p_send(s->s, data, len, urgentflag);

View File

@ -202,14 +202,14 @@ printer_job *printer_start_job(char *printer)
return NULL; return NULL;
} }
void printer_job_data(printer_job *pj, void *data, int len) void printer_job_data(printer_job *pj, const void *data, size_t len)
{ {
DWORD written; DWORD written;
if (!pj) if (!pj)
return; return;
p_WritePrinter(pj->hprinter, data, len, &written); p_WritePrinter(pj->hprinter, (void *)data, len, &written);
} }
void printer_finish_job(printer_job *pj) void printer_finish_job(printer_job *pj)