@@ -477,10 +477,15 @@ let input_msg t msg now =
477
477
let * c = guard_some (Channel. lookup id t.channels) " no such channel" in
478
478
let channels = Channel. remove (Channel. id c) t.channels in
479
479
let msg = " all the channels are closed now, nothing left to do here" in
480
- Ok ({ t with channels },
480
+ let msgs =
481
+ match c.state with
482
+ | Open ->
481
483
[ Msg_channel_close (Channel. id c) ;
482
- Msg_disconnect (DISCONNECT_BY_APPLICATION , msg, " " ) ],
483
- [ `Disconnected ])
484
+ Msg_disconnect (DISCONNECT_BY_APPLICATION , msg, " " ) ]
485
+ | Sent_close ->
486
+ [ Msg_disconnect (DISCONNECT_BY_APPLICATION , msg, " " ) ]
487
+ in
488
+ Ok ({ t with channels }, msgs, [ `Disconnected ])
484
489
| _ , Msg_disconnect (code , msg , lang ) ->
485
490
Log. err (fun m -> m " disconnected: %s %s%s"
486
491
(Ssh. disconnect_code_to_string code)
@@ -541,7 +546,10 @@ let close ?(id = 0l) t =
541
546
let * () = guard (established t) " not yet established" in
542
547
let * c = guard_some (Channel. lookup id t.channels) " no such channel" in
543
548
let msg = Ssh. Msg_channel_close c.them.id in
544
- Ok (output_msg t msg)
549
+ let t, msg = output_msg t msg in
550
+ let c = { c with state = Sent_close } in
551
+ let t = { t with channels = Channel. update c t.channels } in
552
+ Ok (t, msg)
545
553
with
546
554
| Error _ -> t, None
547
555
| Ok (t , msg ) -> t, Some msg
0 commit comments