зеркало из https://github.com/github/putty.git
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:
Родитель
0cda34c6f8
Коммит
59f7b24b9d
|
@ -137,11 +137,9 @@ static void logfopen_callback(void *vctx, int mode)
|
|||
*/
|
||||
assert(ctx->state != L_OPENING); /* make _sure_ it won't be requeued */
|
||||
while (bufchain_size(&ctx->queue)) {
|
||||
void *data;
|
||||
size_t len;
|
||||
bufchain_prefix(&ctx->queue, &data, &len);
|
||||
logwrite(ctx, data, len);
|
||||
bufchain_consume(&ctx->queue, len);
|
||||
ptrlen data = bufchain_prefix(&ctx->queue);
|
||||
logwrite(ctx, data.ptr, data.len);
|
||||
bufchain_consume(&ctx->queue, data.len);
|
||||
}
|
||||
logflush(ctx);
|
||||
}
|
||||
|
|
2
misc.h
2
misc.h
|
@ -105,7 +105,7 @@ void bufchain_init(bufchain *ch);
|
|||
void bufchain_clear(bufchain *ch);
|
||||
size_t bufchain_size(bufchain *ch);
|
||||
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_fetch(bufchain *ch, void *data, size_t len);
|
||||
void bufchain_fetch_consume(bufchain *ch, void *data, size_t len);
|
||||
|
|
|
@ -16,7 +16,7 @@ printer_job *printer_start_job(char *printer)
|
|||
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
29
proxy.c
|
@ -24,8 +24,7 @@
|
|||
*/
|
||||
void proxy_activate (ProxySocket *p)
|
||||
{
|
||||
void *data;
|
||||
size_t len, output_before, output_after;
|
||||
size_t output_before, output_after;
|
||||
|
||||
p->state = PROXY_STATE_ACTIVE;
|
||||
|
||||
|
@ -42,16 +41,16 @@ void proxy_activate (ProxySocket *p)
|
|||
|
||||
/* send buffered OOB writes */
|
||||
while (bufchain_size(&p->pending_oob_output_data) > 0) {
|
||||
bufchain_prefix(&p->pending_oob_output_data, &data, &len);
|
||||
output_after += sk_write_oob(p->sub_socket, data, len);
|
||||
bufchain_consume(&p->pending_oob_output_data, len);
|
||||
ptrlen data = bufchain_prefix(&p->pending_oob_output_data);
|
||||
output_after += sk_write_oob(p->sub_socket, data.ptr, data.len);
|
||||
bufchain_consume(&p->pending_oob_output_data, data.len);
|
||||
}
|
||||
|
||||
/* send buffered normal writes */
|
||||
while (bufchain_size(&p->pending_output_data) > 0) {
|
||||
bufchain_prefix(&p->pending_output_data, &data, &len);
|
||||
output_after += sk_write(p->sub_socket, data, len);
|
||||
bufchain_consume(&p->pending_output_data, len);
|
||||
ptrlen data = bufchain_prefix(&p->pending_output_data);
|
||||
output_after += sk_write(p->sub_socket, data.ptr, data.len);
|
||||
bufchain_consume(&p->pending_output_data, data.len);
|
||||
}
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
while (!ps->freeze && bufchain_size(&ps->pending_input_data) > 0) {
|
||||
void *data;
|
||||
char databuf[512];
|
||||
size_t len;
|
||||
bufchain_prefix(&ps->pending_input_data, &data, &len);
|
||||
if (len > lenof(databuf))
|
||||
len = lenof(databuf);
|
||||
memcpy(databuf, data, len);
|
||||
bufchain_consume(&ps->pending_input_data, len);
|
||||
plug_receive(ps->plug, 0, databuf, len);
|
||||
ptrlen data = bufchain_prefix(&ps->pending_input_data);
|
||||
if (data.len > lenof(databuf))
|
||||
data.len = lenof(databuf);
|
||||
memcpy(databuf, data.ptr, data.len);
|
||||
bufchain_consume(&ps->pending_input_data, data.len);
|
||||
plug_receive(ps->plug, 0, databuf, data.len);
|
||||
}
|
||||
|
||||
/* if we're still frozen, we'll have to wait for another
|
||||
|
|
2
putty.h
2
putty.h
|
@ -1841,7 +1841,7 @@ printer_enum *printer_start_enum(int *nprinters);
|
|||
char *printer_get_name(printer_enum *, int);
|
||||
void printer_finish_enum(printer_enum *);
|
||||
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 *);
|
||||
|
||||
/*
|
||||
|
|
6
rlogin.c
6
rlogin.c
|
@ -287,10 +287,8 @@ static size_t rlogin_send(Backend *be, const char *buf, size_t len)
|
|||
|
||||
if (!rlogin->prompt) {
|
||||
while (bufchain_size(&bc) > 0) {
|
||||
void *data;
|
||||
size_t len;
|
||||
bufchain_prefix(&bc, &data, &len);
|
||||
rlogin->bufsize = sk_write(rlogin->s, data, len);
|
||||
ptrlen data = bufchain_prefix(&bc);
|
||||
rlogin->bufsize = sk_write(rlogin->s, data.ptr, data.len);
|
||||
bufchain_consume(&bc, len);
|
||||
}
|
||||
}
|
||||
|
|
25
scpserver.c
25
scpserver.c
|
@ -1077,17 +1077,13 @@ static void scp_sink_coroutine(ScpSink *scp)
|
|||
if (scp->input_eof)
|
||||
goto done;
|
||||
|
||||
void *vdata;
|
||||
size_t len;
|
||||
const char *cdata, *newline;
|
||||
|
||||
bufchain_prefix(&scp->data, &vdata, &len);
|
||||
cdata = vdata;
|
||||
newline = memchr(cdata, '\012', len);
|
||||
ptrlen data = bufchain_prefix(&scp->data);
|
||||
const char *cdata = data.ptr;
|
||||
const char *newline = memchr(cdata, '\012', data.len);
|
||||
if (newline)
|
||||
len = (int)(newline+1 - cdata);
|
||||
put_data(scp->command, cdata, len);
|
||||
bufchain_consume(&scp->data, len);
|
||||
data.len = (int)(newline+1 - cdata);
|
||||
put_data(scp->command, cdata, data.len);
|
||||
bufchain_consume(&scp->data, data.len);
|
||||
|
||||
if (newline)
|
||||
break;
|
||||
|
@ -1179,8 +1175,7 @@ static void scp_sink_coroutine(ScpSink *scp)
|
|||
sshfwd_write(scp->sc, "\0", 1);
|
||||
scp->file_offset = 0;
|
||||
while (scp->file_offset < scp->file_size) {
|
||||
void *vdata;
|
||||
size_t len;
|
||||
ptrlen data;
|
||||
uint64_t this_len, remaining;
|
||||
|
||||
crMaybeWaitUntilV(
|
||||
|
@ -1191,14 +1186,14 @@ static void scp_sink_coroutine(ScpSink *scp)
|
|||
goto done;
|
||||
}
|
||||
|
||||
bufchain_prefix(&scp->data, &vdata, &len);
|
||||
this_len = len;
|
||||
data = bufchain_prefix(&scp->data);
|
||||
this_len = data.len;
|
||||
remaining = scp->file_size - scp->file_offset;
|
||||
if (this_len > remaining)
|
||||
this_len = remaining;
|
||||
sftpsrv_write(scp->sf, &scp->reply.srb,
|
||||
scp->reply.handle, scp->file_offset,
|
||||
make_ptrlen(vdata, this_len));
|
||||
make_ptrlen(data.ptr, this_len));
|
||||
if (scp->reply.err) {
|
||||
scp->errmsg = dupprintf(
|
||||
"'%.*s': unable to write to file: %s",
|
||||
|
|
11
ssh.c
11
ssh.c
|
@ -348,17 +348,16 @@ static void ssh_bpp_output_raw_data_callback(void *vctx)
|
|||
return;
|
||||
|
||||
while (bufchain_size(&ssh->out_raw) > 0) {
|
||||
void *data;
|
||||
size_t len, backlog;
|
||||
size_t backlog;
|
||||
|
||||
bufchain_prefix(&ssh->out_raw, &data, &len);
|
||||
ptrlen data = bufchain_prefix(&ssh->out_raw);
|
||||
|
||||
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);
|
||||
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) {
|
||||
ssh_throttle_all(ssh, true, backlog);
|
||||
|
|
|
@ -780,13 +780,11 @@ static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl)
|
|||
/*
|
||||
* Add user input to the main channel's buffer.
|
||||
*/
|
||||
void *data;
|
||||
size_t len;
|
||||
bufchain_prefix(s->ppl.user_input, &data, &len);
|
||||
if (len > 512)
|
||||
len = 512;
|
||||
sshfwd_write(&s->mainchan_sc, data, len);
|
||||
bufchain_consume(s->ppl.user_input, len);
|
||||
ptrlen data = bufchain_prefix(s->ppl.user_input);
|
||||
if (data.len > 512)
|
||||
data.len = 512;
|
||||
sshfwd_write(&s->mainchan_sc, data.ptr, data.len);
|
||||
bufchain_consume(s->ppl.user_input, data.len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1064,16 +1064,14 @@ static size_t ssh2_try_send(struct ssh2_channel *c)
|
|||
while (c->remwindow > 0 &&
|
||||
(bufchain_size(&c->outbuffer) > 0 ||
|
||||
bufchain_size(&c->errbuffer) > 0)) {
|
||||
size_t len;
|
||||
void *data;
|
||||
bufchain *buf = (bufchain_size(&c->errbuffer) > 0 ?
|
||||
&c->errbuffer : &c->outbuffer);
|
||||
|
||||
bufchain_prefix(buf, &data, &len);
|
||||
if (len > c->remwindow)
|
||||
len = c->remwindow;
|
||||
if (len > c->remmaxpkt)
|
||||
len = c->remmaxpkt;
|
||||
ptrlen data = bufchain_prefix(buf);
|
||||
if (data.len > c->remwindow)
|
||||
data.len = c->remwindow;
|
||||
if (data.len > c->remmaxpkt)
|
||||
data.len = c->remmaxpkt;
|
||||
if (buf == &c->errbuffer) {
|
||||
pktout = ssh_bpp_new_pktout(
|
||||
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);
|
||||
put_uint32(pktout, c->remoteid);
|
||||
}
|
||||
put_string(pktout, data, len);
|
||||
put_stringpl(pktout, data);
|
||||
pq_push(s->ppl.out_pq, pktout);
|
||||
bufchain_consume(buf, len);
|
||||
c->remwindow -= len;
|
||||
bufchain_consume(buf, data.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.
|
||||
*/
|
||||
void *data;
|
||||
size_t len;
|
||||
bufchain_prefix(s->ppl.user_input, &data, &len);
|
||||
sshfwd_write(s->mainchan_sc, data, len);
|
||||
bufchain_consume(s->ppl.user_input, len);
|
||||
ptrlen data = bufchain_prefix(s->ppl.user_input);
|
||||
sshfwd_write(s->mainchan_sc, data.ptr, data.len);
|
||||
bufchain_consume(s->ppl.user_input, data.len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -465,11 +465,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
|||
if (bufchain_size(&s->banner) &&
|
||||
(flags & (FLAG_VERBOSE | FLAG_INTERACTIVE))) {
|
||||
while (bufchain_size(&s->banner) > 0) {
|
||||
void *data;
|
||||
size_t len;
|
||||
bufchain_prefix(&s->banner, &data, &len);
|
||||
seat_stderr(s->ppl.seat, data, len);
|
||||
bufchain_consume(&s->banner, len);
|
||||
ptrlen data = bufchain_prefix(&s->banner);
|
||||
seat_stderr(s->ppl.seat, data.ptr, data.len);
|
||||
bufchain_consume(&s->banner, data.len);
|
||||
}
|
||||
}
|
||||
bufchain_clear(&s->banner);
|
||||
|
|
11
sshserver.c
11
sshserver.c
|
@ -333,17 +333,16 @@ static void server_bpp_output_raw_data_callback(void *vctx)
|
|||
return;
|
||||
|
||||
while (bufchain_size(&srv->out_raw) > 0) {
|
||||
void *data;
|
||||
size_t len, backlog;
|
||||
size_t backlog;
|
||||
|
||||
bufchain_prefix(&srv->out_raw, &data, &len);
|
||||
ptrlen data = bufchain_prefix(&srv->out_raw);
|
||||
|
||||
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);
|
||||
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) {
|
||||
#ifdef FIXME
|
||||
|
|
|
@ -249,19 +249,18 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
|
|||
* If we didn't find it, consume data until we see a newline.
|
||||
*/
|
||||
while (1) {
|
||||
size_t len;
|
||||
void *data;
|
||||
ptrlen data;
|
||||
char *nl;
|
||||
|
||||
/* Wait to receive at least 1 byte, but then consume more
|
||||
* than that if it's there. */
|
||||
BPP_WAITFOR(1);
|
||||
bufchain_prefix(s->bpp.in_raw, &data, &len);
|
||||
if ((nl = memchr(data, '\012', len)) != NULL) {
|
||||
bufchain_consume(s->bpp.in_raw, nl - (char *)data + 1);
|
||||
data = bufchain_prefix(s->bpp.in_raw);
|
||||
if ((nl = memchr(data.ptr, '\012', data.len)) != NULL) {
|
||||
bufchain_consume(s->bpp.in_raw, nl - (char *)data.ptr + 1);
|
||||
break;
|
||||
} 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;
|
||||
do {
|
||||
size_t len;
|
||||
void *data;
|
||||
ptrlen data;
|
||||
char *nl;
|
||||
|
||||
BPP_WAITFOR(1);
|
||||
bufchain_prefix(s->bpp.in_raw, &data, &len);
|
||||
if ((nl = memchr(data, '\012', len)) != NULL) {
|
||||
len = nl - (char *)data + 1;
|
||||
data = bufchain_prefix(s->bpp.in_raw);
|
||||
if ((nl = memchr(data.ptr, '\012', data.len)) != NULL) {
|
||||
data.len = nl - (char *)data.ptr + 1;
|
||||
}
|
||||
|
||||
if (s->vslen >= s->vstrsize - 1 || len >= s->vstrsize - 1 - s->vslen) {
|
||||
s->vstrsize = (s->vslen + len) * 5 / 4 + 32;
|
||||
if (s->vslen >= s->vstrsize - 1 ||
|
||||
data.len >= s->vstrsize - 1 - s->vslen) {
|
||||
s->vstrsize = (s->vslen + data.len) * 5 / 4 + 32;
|
||||
s->vstring = sresize(s->vstring, s->vstrsize, char);
|
||||
}
|
||||
|
||||
memcpy(s->vstring + s->vslen, data, len);
|
||||
s->vslen += len;
|
||||
bufchain_consume(s->bpp.in_raw, len);
|
||||
memcpy(s->vstring + s->vslen, data.ptr, data.len);
|
||||
s->vslen += data.len;
|
||||
bufchain_consume(s->bpp.in_raw, data.len);
|
||||
|
||||
} while (s->vstring[s->vslen-1] != '\012');
|
||||
|
||||
|
|
33
terminal.c
33
terminal.c
|
@ -2691,20 +2691,18 @@ static void term_print_setup(Terminal *term, char *printer)
|
|||
}
|
||||
static void term_print_flush(Terminal *term)
|
||||
{
|
||||
void *data;
|
||||
size_t len, size;
|
||||
size_t size;
|
||||
while ((size = bufchain_size(&term->printer_buf)) > 5) {
|
||||
bufchain_prefix(&term->printer_buf, &data, &len);
|
||||
if (len > size-5)
|
||||
len = size-5;
|
||||
printer_job_data(term->print_job, data, len);
|
||||
bufchain_consume(&term->printer_buf, len);
|
||||
ptrlen data = bufchain_prefix(&term->printer_buf);
|
||||
if (data.len > size-5)
|
||||
data.len = size-5;
|
||||
printer_job_data(term->print_job, data.ptr, data.len);
|
||||
bufchain_consume(&term->printer_buf, data.len);
|
||||
}
|
||||
}
|
||||
static void term_print_finish(Terminal *term)
|
||||
{
|
||||
void *data;
|
||||
size_t len, size;
|
||||
size_t size;
|
||||
char c;
|
||||
|
||||
if (!term->printing && !term->only_printing)
|
||||
|
@ -2712,8 +2710,8 @@ static void term_print_finish(Terminal *term)
|
|||
|
||||
term_print_flush(term);
|
||||
while ((size = bufchain_size(&term->printer_buf)) > 0) {
|
||||
bufchain_prefix(&term->printer_buf, &data, &len);
|
||||
c = *(char *)data;
|
||||
ptrlen data = bufchain_prefix(&term->printer_buf);
|
||||
c = *(char *)data.ptr;
|
||||
if (c == '\033' || c == '\233') {
|
||||
bufchain_consume(&term->printer_buf, size);
|
||||
break;
|
||||
|
@ -2882,14 +2880,15 @@ static void term_out(Terminal *term)
|
|||
while (nchars > 0 || unget != -1 || bufchain_size(&term->inbuf) > 0) {
|
||||
if (unget == -1) {
|
||||
if (nchars == 0) {
|
||||
void *ret;
|
||||
bufchain_prefix(&term->inbuf, &ret, &nchars);
|
||||
if (nchars > sizeof(localbuf))
|
||||
nchars = sizeof(localbuf);
|
||||
memcpy(localbuf, ret, nchars);
|
||||
bufchain_consume(&term->inbuf, nchars);
|
||||
ptrlen data = bufchain_prefix(&term->inbuf);
|
||||
if (data.len > sizeof(localbuf))
|
||||
data.len = sizeof(localbuf);
|
||||
memcpy(localbuf, data.ptr, data.len);
|
||||
bufchain_consume(&term->inbuf, data.len);
|
||||
nchars = data.len;
|
||||
chars = localbuf;
|
||||
assert(chars != NULL);
|
||||
assert(nchars > 0);
|
||||
}
|
||||
c = *chars++;
|
||||
nchars--;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
bufchain sanitised;
|
||||
void *vdata;
|
||||
|
||||
bufchain_init(&sanitised);
|
||||
sanitise_term_data(&sanitised, data, len);
|
||||
while (bufchain_size(&sanitised) > 0) {
|
||||
bufchain_prefix(&sanitised, &vdata, &len);
|
||||
fwrite(vdata, 1, len, outfp);
|
||||
bufchain_consume(&sanitised, len);
|
||||
ptrlen sdata = bufchain_prefix(&sanitised);
|
||||
fwrite(sdata.ptr, 1, sdata.len, outfp);
|
||||
bufchain_consume(&sanitised, sdata.len);
|
||||
}
|
||||
fflush(outfp);
|
||||
}
|
||||
|
|
|
@ -162,12 +162,10 @@ static int fdsocket_try_send(FdSocket *fds)
|
|||
int sent = 0;
|
||||
|
||||
while (bufchain_size(&fds->pending_output_data) > 0) {
|
||||
void *data;
|
||||
size_t len;
|
||||
ssize_t ret;
|
||||
|
||||
bufchain_prefix(&fds->pending_output_data, &data, &len);
|
||||
ret = write(fds->outfd, data, len);
|
||||
ptrlen data = bufchain_prefix(&fds->pending_output_data);
|
||||
ret = write(fds->outfd, data.ptr, data.len);
|
||||
noise_ultralight(NOISE_SOURCE_IOID, ret);
|
||||
if (ret < 0 && errno != EWOULDBLOCK) {
|
||||
if (!fds->pending_error) {
|
||||
|
|
|
@ -1111,7 +1111,7 @@ void try_send(NetSocket *s)
|
|||
while (s->sending_oob || bufchain_size(&s->output_data) > 0) {
|
||||
int nsent;
|
||||
int err;
|
||||
void *data;
|
||||
const void *data;
|
||||
size_t len;
|
||||
int urgentflag;
|
||||
|
||||
|
@ -1121,7 +1121,9 @@ void try_send(NetSocket *s)
|
|||
data = &s->oobdata;
|
||||
} else {
|
||||
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);
|
||||
noise_ultralight(NOISE_SOURCE_IOLEN, nsent);
|
||||
|
|
|
@ -329,18 +329,17 @@ size_t try_output(bool is_stderr)
|
|||
{
|
||||
bufchain *chain = (is_stderr ? &stderr_data : &stdout_data);
|
||||
int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO);
|
||||
void *senddata;
|
||||
size_t sendlen;
|
||||
ssize_t ret;
|
||||
|
||||
if (bufchain_size(chain) > 0) {
|
||||
bool prev_nonblock = nonblock(fd);
|
||||
ptrlen senddata;
|
||||
do {
|
||||
bufchain_prefix(chain, &senddata, &sendlen);
|
||||
ret = write(fd, senddata, sendlen);
|
||||
senddata = bufchain_prefix(chain);
|
||||
ret = write(fd, senddata.ptr, senddata.len);
|
||||
if (ret > 0)
|
||||
bufchain_consume(chain, ret);
|
||||
} while (ret == sendlen && bufchain_size(chain) != 0);
|
||||
} while (ret == senddata.len && bufchain_size(chain) != 0);
|
||||
if (!prev_nonblock)
|
||||
no_nonblock(fd);
|
||||
if (ret < 0 && errno != EAGAIN) {
|
||||
|
|
|
@ -25,7 +25,7 @@ printer_job *printer_start_job(char *printer)
|
|||
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)
|
||||
return;
|
||||
|
|
|
@ -1309,15 +1309,13 @@ static void pty_free(Backend *be)
|
|||
|
||||
static void pty_try_write(Pty *pty)
|
||||
{
|
||||
void *data;
|
||||
size_t len;
|
||||
ssize_t ret;
|
||||
|
||||
assert(pty->master_i >= 0);
|
||||
|
||||
while (bufchain_size(&pty->output_data) > 0) {
|
||||
bufchain_prefix(&pty->output_data, &data, &len);
|
||||
ret = write(pty->master_i, data, len);
|
||||
ptrlen data = bufchain_prefix(&pty->output_data);
|
||||
ret = write(pty->master_i, data.ptr, data.len);
|
||||
|
||||
if (ret < 0 && (errno == EWOULDBLOCK)) {
|
||||
/*
|
||||
|
|
|
@ -422,15 +422,13 @@ static void serial_uxsel_setup(Serial *serial)
|
|||
|
||||
static void serial_try_write(Serial *serial)
|
||||
{
|
||||
void *data;
|
||||
size_t len;
|
||||
ssize_t ret;
|
||||
|
||||
assert(serial->fd >= 0);
|
||||
|
||||
while (bufchain_size(&serial->output_data) > 0) {
|
||||
bufchain_prefix(&serial->output_data, &data, &len);
|
||||
ret = write(serial->fd, data, len);
|
||||
ptrlen data = bufchain_prefix(&serial->output_data);
|
||||
ret = write(serial->fd, data.ptr, data.len);
|
||||
|
||||
if (ret < 0 && (errno == EWOULDBLOCK)) {
|
||||
/*
|
||||
|
|
5
utils.c
5
utils.c
|
@ -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;
|
||||
*data = ch->head->bufpos;
|
||||
return make_ptrlen(ch->head->bufpos, ch->head->bufend - ch->head->bufpos);
|
||||
}
|
||||
|
||||
void bufchain_fetch(bufchain *ch, void *data, size_t len)
|
||||
|
|
|
@ -392,14 +392,13 @@ static void console_data_untrusted(HANDLE hout, const char *data, size_t len)
|
|||
{
|
||||
DWORD dummy;
|
||||
bufchain sanitised;
|
||||
void *vdata;
|
||||
|
||||
bufchain_init(&sanitised);
|
||||
sanitise_term_data(&sanitised, data, len);
|
||||
while (bufchain_size(&sanitised) > 0) {
|
||||
bufchain_prefix(&sanitised, &vdata, &len);
|
||||
WriteFile(hout, vdata, len, &dummy, NULL);
|
||||
bufchain_consume(&sanitised, len);
|
||||
ptrlen sdata = bufchain_prefix(&sanitised);
|
||||
WriteFile(hout, sdata.ptr, sdata.len, &dummy, NULL);
|
||||
bufchain_consume(&sanitised, sdata.len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ struct handle_output {
|
|||
* Data set by the main thread before signalling ev_from_main,
|
||||
* 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 */
|
||||
|
||||
/*
|
||||
|
@ -347,13 +347,10 @@ static DWORD WINAPI handle_output_threadfunc(void *param)
|
|||
|
||||
static void handle_try_output(struct handle_output *ctx)
|
||||
{
|
||||
void *senddata;
|
||||
size_t sendlen;
|
||||
|
||||
if (!ctx->busy && bufchain_size(&ctx->queued_data)) {
|
||||
bufchain_prefix(&ctx->queued_data, &senddata, &sendlen);
|
||||
ctx->buffer = senddata;
|
||||
ctx->len = min(sendlen, ~(DWORD)0);
|
||||
ptrlen data = bufchain_prefix(&ctx->queued_data);
|
||||
ctx->buffer = data.ptr;
|
||||
ctx->len = min(data.len, ~(DWORD)0);
|
||||
SetEvent(ctx->ev_from_main);
|
||||
ctx->busy = true;
|
||||
} else if (!ctx->busy && bufchain_size(&ctx->queued_data) == 0 &&
|
||||
|
|
|
@ -164,8 +164,6 @@ static void sk_handle_flush(Socket *s)
|
|||
static void handle_socket_unfreeze(void *hsv)
|
||||
{
|
||||
HandleSocket *hs = (HandleSocket *)hsv;
|
||||
void *data;
|
||||
size_t len;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
bufchain_prefix(&hs->inputdata, &data, &len);
|
||||
assert(len > 0);
|
||||
ptrlen data = bufchain_prefix(&hs->inputdata);
|
||||
assert(data.len > 0);
|
||||
|
||||
/*
|
||||
* Hand it off to the plug. Be careful of re-entrance - that might
|
||||
* have the effect of trying to close this socket.
|
||||
*/
|
||||
hs->defer_close = true;
|
||||
plug_receive(hs->plug, 0, data, len);
|
||||
bufchain_consume(&hs->inputdata, len);
|
||||
plug_receive(hs->plug, 0, data.ptr, data.len);
|
||||
bufchain_consume(&hs->inputdata, data.len);
|
||||
hs->defer_close = false;
|
||||
if (hs->deferred_close) {
|
||||
sk_handle_close(&hs->sock);
|
||||
|
|
|
@ -1377,7 +1377,7 @@ void try_send(NetSocket *s)
|
|||
while (s->sending_oob || bufchain_size(&s->output_data) > 0) {
|
||||
int nsent;
|
||||
DWORD err;
|
||||
void *data;
|
||||
const void *data;
|
||||
size_t len;
|
||||
int urgentflag;
|
||||
|
||||
|
@ -1387,7 +1387,9 @@ void try_send(NetSocket *s)
|
|||
data = &s->oobdata;
|
||||
} else {
|
||||
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 */
|
||||
nsent = p_send(s->s, data, len, urgentflag);
|
||||
|
|
|
@ -202,14 +202,14 @@ printer_job *printer_start_job(char *printer)
|
|||
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;
|
||||
|
||||
if (!pj)
|
||||
return;
|
||||
|
||||
p_WritePrinter(pj->hprinter, data, len, &written);
|
||||
p_WritePrinter(pj->hprinter, (void *)data, len, &written);
|
||||
}
|
||||
|
||||
void printer_finish_job(printer_job *pj)
|
||||
|
|
Загрузка…
Ссылка в новой задаче