Write a CHANNEL_EOF message over SSH when closing SSH.

master
Robinson 2021-04-11 19:23:06 +02:00
parent 0d5b094615
commit 4b429c8c3b
1 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright 2020 dorkbox, llc
* Copyright 2021 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.executor
import net.schmizz.sshj.SSHClient
import net.schmizz.sshj.common.Message
import net.schmizz.sshj.common.SSHPacket
import net.schmizz.sshj.connection.channel.direct.Session
import java.io.IOException
import java.io.InputStream
@ -62,6 +63,13 @@ class SshProcess(private val ssh: SSHClient,
}
override fun destroy() {
try {
// https://github.com/hierynomus/sshj/issues/143
// send EOF when the channel is closed.
ssh.transport.write(SSHPacket(Message.CHANNEL_EOF).putUInt32(session.recipient.toLong()));
} catch (ignored: IOException) {
}
try {
session.close()
} catch (ignored: IOException) {