fix: replace GlobalScope with CoroutineScope+SupervisorJob to fix -Werror build

This commit is contained in:
茂之钳
2026-05-26 09:52:59 +00:00
parent 902a4c5572
commit 4b5ffe9b33
@@ -106,6 +106,7 @@ class SshTerminalManager(
private val jsch = JSch() private val jsch = JSch()
private var session: Session? = null private var session: Session? = null
private val ioScope = kotlinx.coroutines.CoroutineScope(Dispatchers.IO + kotlinx.coroutines.SupervisorJob())
private var channel: ChannelShell? = null private var channel: ChannelShell? = null
private var sftpChannel: ChannelSftp? = null private var sftpChannel: ChannelSftp? = null
private var inputStream: InputStream? = null private var inputStream: InputStream? = null
@@ -165,7 +166,7 @@ class SshTerminalManager(
) )
// Start reading output in a separate coroutine (don't block connect()) // Start reading output in a separate coroutine (don't block connect())
readOutputJob = kotlinx.coroutines.GlobalScope.launch(Dispatchers.IO) { readOutputJob = ioScope.launch(Dispatchers.IO) {
readOutput() readOutput()
} }
@@ -240,7 +241,7 @@ class SshTerminalManager(
authMode = "key" authMode = "key"
) )
readOutputJob = kotlinx.coroutines.GlobalScope.launch(Dispatchers.IO) { readOutputJob = ioScope.launch(Dispatchers.IO) {
readOutput() readOutput()
} }
@@ -416,6 +417,7 @@ class SshTerminalManager(
running.set(false) running.set(false)
readOutputJob?.cancel() readOutputJob?.cancel()
readOutputJob = null readOutputJob = null
ioScope.cancel()
closeSftpChannel() closeSftpChannel()
try { channel?.disconnect() } catch (_: Exception) {} try { channel?.disconnect() } catch (_: Exception) {}
try { session?.disconnect() } catch (_: Exception) {} try { session?.disconnect() } catch (_: Exception) {}