1 .TL
   2 OpenSSH Channel Close Protocol 2.0 Implementation
   3 .SH
   4 Channel Input State Diagram
   5 .PS
   6 reset
   7 l=1
   8 s=1.2
   9 ellipsewid=s*ellipsewid
  10 boxwid=s*boxwid
  11 ellipseht=s*ellipseht
  12 S1: ellipse "INPUT" "OPEN"
  13 move right 2*l from last ellipse.e
  14 S3: ellipse invis
  15 move down l from last ellipse.s
  16 S4: ellipse "INPUT" "CLOSED"
  17 move down l from 1st ellipse.s
  18 S2: ellipse "INPUT" "WAIT" "DRAIN"
  19 arrow from S1.e to S4.n
  20 box invis "rcvd CLOSE/" "shutdown_read" with .sw at last arrow.c
  21 arrow "ibuf_empty ||" "rcvd CLOSE/" "send EOF" "" from S2.e to S4.w
  22 arrow from S1.s to S2.n
  23 box invis "read_failed/" "shutdown_read" with .e at last arrow.c
  24 ellipse wid .9*ellipsewid ht .9*ellipseht at S4
  25 arrow "start" "" from S1.w+(-0.5,0) to S1.w
  26 .PE
  27 .SH
  28 Channel Output State Diagram
  29 .PS
  30 S1: ellipse "OUTPUT" "OPEN"
  31 move right 2*l from last ellipse.e
  32 S3: ellipse invis
  33 move down l from last ellipse.s
  34 S4: ellipse "OUTPUT" "CLOSED"
  35 move down l from 1st ellipse.s
  36 S2: ellipse "OUTPUT" "WAIT" "DRAIN"
  37 arrow from S1.e to S4.n
  38 box invis "write_failed/" "shutdown_write" with .sw at last arrow.c
  39 arrow "obuf_empty ||" "write_failed/" "shutdown_write" "" from S2.e to S4.w
  40 arrow from S1.s to S2.n
  41 box invis "rcvd EOF ||" "rcvd CLOSE/" "-" with .e at last arrow.c
  42 ellipse wid .9*ellipsewid ht .9*ellipseht at S4
  43 arrow "start" "" from S1.w+(-0.5,0) to S1.w
  44 .PE
  45 .SH
  46 Notes
  47 .PP
  48 The input buffer is filled with data from the socket
  49 (the socket represents the local consumer/producer of the
  50 forwarded channel).
  51 The data is then sent over the INPUT-end (transmit-end) of the channel to the
  52 remote peer.
  53 Data sent by the peer is received on the OUTPUT-end (receive-end),
  54 saved in the output buffer and written to the socket.
  55 .PP
  56 If the local protocol instance has forwarded all data on the
  57 INPUT-end of the channel, it sends an EOF message to the peer.
  58 .PP
  59 A CLOSE message is sent to the peer if
  60 both the INPUT- and the OUTOUT-half of the local
  61 end of the channel are closed.
  62 .PP
  63 The channel can be deallocated by a protocol instance
  64 if a CLOSE message he been both sent and received.