comparison common-channel.c @ 364:90cb290836de channel-fix

Passes most test cases now
author Matt Johnston <matt@ucc.asn.au>
date Mon, 09 Oct 2006 16:31:00 +0000
parents 6ba2894ec8d5
children 49fcc9875045
comparison
equal deleted inserted replaced
363:6ba2894ec8d5 364:90cb290836de
261 TRACE(("writebuf size %d extrabuf ptr 0x%x extrabuf size %d", 261 TRACE(("writebuf size %d extrabuf ptr 0x%x extrabuf size %d",
262 cbuf_getused(channel->writebuf), 262 cbuf_getused(channel->writebuf),
263 channel->writebuf, 263 channel->writebuf,
264 channel->writebuf ? 0 : cbuf_getused(channel->extrabuf))) 264 channel->writebuf ? 0 : cbuf_getused(channel->extrabuf)))
265 265
266 if (!channel->sent_close 266 /* A bit of a hack for closing up server session channels */
267 && channel->writefd == FD_CLOSED 267 if (channel->writefd >= 0
268 && (channel->errfd == FD_CLOSED || channel->extrabuf == NULL)) { 268 && channel->type->check_close
269 send_msg_channel_close(channel); 269 && channel->type->check_close(channel)) {
270 TRACE(("channel->type->check_close got hit"))
271 close_chan_fd(channel, channel->writefd, SHUT_WR);
270 } 272 }
271 273
272 if (channel->recv_close && !write_pending(channel)) { 274 if (channel->recv_close && !write_pending(channel)) {
273 if (! channel->sent_close) { 275 if (! channel->sent_close) {
274 TRACE(("Sending MSG_CHANNEL_CLOSE in response to same.")) 276 TRACE(("Sending MSG_CHANNEL_CLOSE in response to same."))
276 } 278 }
277 remove_channel(channel); 279 remove_channel(channel);
278 return; 280 return;
279 } 281 }
280 282
281 #if 0 283 if (channel->recv_eof && !write_pending(channel)) {
282 // The only use of check_close is "return channel->writefd == -1;" for a server 284 close_chan_fd(channel, channel->writefd, SHUT_WR);
283 // chansession. Should be able to handle that with just the general 285 }
284 // socket close handling...?
285 if (channel->type->check_close) {
286 if (channel->type->check_close(channel)) {
287 close_write_fd(channel);
288 close_read_fd(channel, channel->readfd);
289 close_read_fd(channel, channel->errfd);
290 }
291 }
292 #endif
293 286
294 if (!channel->sent_eof 287 if (!channel->sent_eof
295 && channel->readfd == FD_CLOSED 288 && channel->readfd == FD_CLOSED
296 && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) { 289 && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) {
297 send_msg_channel_eof(channel); 290 send_msg_channel_eof(channel);
298 }
299
300 if (!channel->sent_close
301 && channel->writefd == FD_CLOSED
302 && channel->readfd == FD_CLOSED
303 && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) {
304 send_msg_channel_close(channel);
305 } 291 }
306 } 292 }
307 293
308 294
309 /* Check whether a deferred (EINPROGRESS) connect() was successful, and 295 /* Check whether a deferred (EINPROGRESS) connect() was successful, and
393 } 379 }
394 380
395 cbuf_incrread(cbuf, len); 381 cbuf_incrread(cbuf, len);
396 channel->recvdonelen += len; 382 channel->recvdonelen += len;
397 383
398 /* We're closing out */
399 if (channel->recv_eof && cbuf_getused(cbuf) == 0) {
400 TRACE(("leave writechannel"))
401 close_chan_fd(channel, fd, SHUT_WR);
402 return;
403 }
404
405 /* Window adjust handling */ 384 /* Window adjust handling */
406 if (channel->recvdonelen >= RECV_WINDOWEXTEND) { 385 if (channel->recvdonelen >= RECV_WINDOWEXTEND) {
407 /* Set it back to max window */ 386 /* Set it back to max window */
408 send_msg_channel_window_adjust(channel, channel->recvdonelen); 387 send_msg_channel_window_adjust(channel, channel->recvdonelen);
409 channel->recvwindow += channel->recvdonelen; 388 channel->recvwindow += channel->recvdonelen;