Mercurial > dropbear
comparison common-channel.c @ 709:abd99ecd7ec2
use an empty writebuf rather than a NULL one
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 20 Mar 2013 22:31:07 +0800 |
parents | 564e7f87ecc3 |
children | 4a274f47eabd |
comparison
equal
deleted
inserted
replaced
708:b207d5183bb7 | 709:abd99ecd7ec2 |
---|---|
93 } | 93 } |
94 | 94 |
95 static void | 95 static void |
96 chan_initwritebuf(struct Channel *channel) | 96 chan_initwritebuf(struct Channel *channel) |
97 { | 97 { |
98 dropbear_assert(channel->writebuf == NULL && channel->recvwindow == 0); | 98 dropbear_assert(channel->writebuf->size == 0 && channel->recvwindow == 0); |
99 cbuf_free(channel->writebuf); | |
99 channel->writebuf = cbuf_new(opts.recv_window); | 100 channel->writebuf = cbuf_new(opts.recv_window); |
100 channel->recvwindow = opts.recv_window; | 101 channel->recvwindow = opts.recv_window; |
101 } | 102 } |
102 | 103 |
103 /* Create a new channel entry, send a reply confirm or failure */ | 104 /* Create a new channel entry, send a reply confirm or failure */ |
157 newchan->errfd = FD_CLOSED; /* this isn't always set to start with */ | 158 newchan->errfd = FD_CLOSED; /* this isn't always set to start with */ |
158 newchan->initconn = 0; | 159 newchan->initconn = 0; |
159 newchan->await_open = 0; | 160 newchan->await_open = 0; |
160 newchan->flushing = 0; | 161 newchan->flushing = 0; |
161 | 162 |
162 newchan->writebuf = NULL; | 163 newchan->writebuf = cbuf_new(0); /* resized later by chan_initwritebuf */ |
163 newchan->recvwindow = 0; | 164 newchan->recvwindow = 0; |
164 | 165 |
165 newchan->extrabuf = NULL; /* The user code can set it up */ | 166 newchan->extrabuf = NULL; /* The user code can set it up */ |
166 newchan->recvdonelen = 0; | 167 newchan->recvdonelen = 0; |
167 newchan->recvmaxpacket = RECV_MAX_PAYLOAD_LEN; | 168 newchan->recvmaxpacket = RECV_MAX_PAYLOAD_LEN; |
231 /* XXX should this go somewhere cleaner? */ | 232 /* XXX should this go somewhere cleaner? */ |
232 check_in_progress(channel); | 233 check_in_progress(channel); |
233 continue; /* Important not to use the channel after | 234 continue; /* Important not to use the channel after |
234 check_in_progress(), as it may be NULL */ | 235 check_in_progress(), as it may be NULL */ |
235 } | 236 } |
236 dropbear_assert(channel->writebuf); | |
237 writechannel(channel, channel->writefd, channel->writebuf); | 237 writechannel(channel, channel->writefd, channel->writebuf); |
238 } | 238 } |
239 | 239 |
240 /* stderr for client mode */ | 240 /* stderr for client mode */ |
241 if (ERRFD_IS_WRITE(channel) | 241 if (ERRFD_IS_WRITE(channel) |
257 | 257 |
258 /* Returns true if there is data remaining to be written to stdin or | 258 /* Returns true if there is data remaining to be written to stdin or |
259 * stderr of a channel's endpoint. */ | 259 * stderr of a channel's endpoint. */ |
260 static unsigned int write_pending(struct Channel * channel) { | 260 static unsigned int write_pending(struct Channel * channel) { |
261 | 261 |
262 if (channel->writefd >= 0 | 262 if (channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0) { |
263 && channel->writebuf | |
264 && cbuf_getused(channel->writebuf) > 0) { | |
265 return 1; | 263 return 1; |
266 } else if (channel->errfd >= 0 && channel->extrabuf && | 264 } else if (channel->errfd >= 0 && channel->extrabuf && |
267 cbuf_getused(channel->extrabuf) > 0) { | 265 cbuf_getused(channel->extrabuf) > 0) { |
268 return 1; | 266 return 1; |
269 } | 267 } |
450 channel->recvwindow += channel->recvdonelen; | 448 channel->recvwindow += channel->recvdonelen; |
451 channel->recvdonelen = 0; | 449 channel->recvdonelen = 0; |
452 } | 450 } |
453 | 451 |
454 dropbear_assert(channel->recvwindow <= opts.recv_window); | 452 dropbear_assert(channel->recvwindow <= opts.recv_window); |
455 dropbear_assert(channel->writebuf == NULL || | 453 dropbear_assert(channel->recvwindow <= cbuf_getavail(channel->writebuf)); |
456 channel->recvwindow <= cbuf_getavail(channel->writebuf)); | |
457 dropbear_assert(channel->extrabuf == NULL || | 454 dropbear_assert(channel->extrabuf == NULL || |
458 channel->recvwindow <= cbuf_getavail(channel->extrabuf)); | 455 channel->recvwindow <= cbuf_getavail(channel->extrabuf)); |
459 | 456 |
460 TRACE(("leave writechannel")) | 457 TRACE(("leave writechannel")) |
461 } | 458 } |
544 static void remove_channel(struct Channel * channel) { | 541 static void remove_channel(struct Channel * channel) { |
545 | 542 |
546 TRACE(("enter remove_channel")) | 543 TRACE(("enter remove_channel")) |
547 TRACE(("channel index is %d", channel->index)) | 544 TRACE(("channel index is %d", channel->index)) |
548 | 545 |
549 if (channel->writebuf) { | 546 cbuf_free(channel->writebuf); |
550 cbuf_free(channel->writebuf); | 547 channel->writebuf = NULL; |
551 channel->writebuf = NULL; | |
552 } | |
553 | 548 |
554 if (channel->extrabuf) { | 549 if (channel->extrabuf) { |
555 cbuf_free(channel->extrabuf); | 550 cbuf_free(channel->extrabuf); |
556 channel->extrabuf = NULL; | 551 channel->extrabuf = NULL; |
557 } | 552 } |