Annotation of src/usr.bin/ssh/nchan.c, Revision 1.1
1.1 ! markus 1: #include "includes.h"
! 2: #include "ssh.h"
! 3:
! 4: #include "buffer.h"
! 5: #include "channels.h"
! 6: #include "packet.h"
! 7: #include "nchan.h"
! 8:
! 9:
! 10: void
! 11: dump_chan(Channel *c){
! 12: debug("chan %d type %d flags 0x%x", c->self, c->type, c->flags);
! 13: }
! 14: void
! 15: chan_rcvd_ieof(Channel *c){
! 16: dump_chan(c);
! 17: if(c->flags & CHAN_IEOF_RCVD){
! 18: debug("chan_rcvd_ieof twice: %d",c->self);
! 19: return;
! 20: }
! 21: debug("rcvd_CHAN_IEOF %d",c->self);
! 22: c->flags |= CHAN_IEOF_RCVD;
! 23: /* cannot clear input buffer. remaining data has to be sent to client */
! 24: chan_del_if_dead(c);
! 25: }
! 26: void
! 27: chan_rcvd_oclose(Channel *c){
! 28: dump_chan(c);
! 29: if(c->flags & CHAN_OCLOSE_RCVD){
! 30: debug("chan_rcvd_oclose twice: %d",c->self);
! 31: return;
! 32: }
! 33: debug("rcvd_CHAN_OCLOSE %d",c->self);
! 34: c->flags |= CHAN_OCLOSE_RCVD;
! 35: /* our peer can no longer consume, so there is not need to read */
! 36: chan_shutdown_read(c);
! 37: buffer_consume(&c->output, buffer_len(&c->output));
! 38: /* Note: for type==OPEN IEOF is sent by channel_output_poll() */
! 39: chan_del_if_dead(c);
! 40: }
! 41: void
! 42: chan_send_ieof(Channel *c){
! 43: if(c->flags & CHAN_IEOF_SENT){
! 44: debug("send_chan_ieof twice %d", c->self);
! 45: return;
! 46: }
! 47: debug("send_CHAN_IEOF %d", c->self);
! 48: packet_start(CHAN_IEOF);
! 49: packet_put_int(c->remote_id);
! 50: packet_send();
! 51: c->flags |= CHAN_IEOF_SENT;
! 52: dump_chan(c);
! 53: }
! 54: void
! 55: chan_send_oclose(Channel *c){
! 56: if(c->flags & CHAN_OCLOSE_SENT){
! 57: debug("send_chan_oclose twice %d", c->self);
! 58: return;
! 59: }
! 60: debug("send_CHAN_OCLOSE %d", c->self);
! 61: packet_start(CHAN_OCLOSE);
! 62: packet_put_int(c->remote_id);
! 63: packet_send();
! 64: c->flags |= CHAN_OCLOSE_SENT;
! 65: dump_chan(c);
! 66: }
! 67: void
! 68: chan_shutdown_write(Channel *c){
! 69: if(c->flags & CHAN_SHUT_WR){
! 70: debug("chan_shutdown_write twice %d",c->self);
! 71: return;
! 72: }
! 73: debug("chan_shutdown_write %d", c->self);
! 74: if(shutdown(c->sock, SHUT_WR)<0)
! 75: error("chan_shutdown_write failed %.100s", strerror(errno));
! 76: c->flags |= CHAN_SHUT_WR;
! 77: /* clear output buffer, since there is noone going to read the data
! 78: we just closed the output-socket */
! 79: // buffer_consume(&c->output, buffer_len(&c->output));
! 80: }
! 81: void
! 82: chan_shutdown_read(Channel *c){
! 83: if(c->flags & CHAN_SHUT_RD){
! 84: debug("chan_shutdown_read twice %d",c->self);
! 85: return;
! 86: }
! 87: debug("chan_shutdown_read %d", c->self);
! 88: if(shutdown(c->sock, SHUT_RD)<0)
! 89: error("chan_shutdown_read failed %.100s", strerror(errno));
! 90: c->flags |= CHAN_SHUT_RD;
! 91: }
! 92: void
! 93: chan_del_if_dead(Channel *c){
! 94: if(c->flags == CHAN_CLOSED){
! 95: debug("channel %d closing",c->self);
! 96: channel_free(c->self);
! 97: }
! 98: }