mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
trying runloop with dispatchqueue
This commit is contained in:
@@ -107,8 +107,8 @@
|
||||
A92538912DEE06DC007E0A18 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A95FAA582DF4B71F00DE2F5A /* ci_scripts */,
|
||||
A95FAA462DF3884B00DE2F5A /* Config.xcconfig */,
|
||||
A95FAA582DF4B71F00DE2F5A /* ci_scripts */,
|
||||
A92538C72DEE0742007E0A18 /* ShhShell */,
|
||||
A92538D42DEE0756007E0A18 /* Resources */,
|
||||
A92538CC2DEE0744007E0A18 /* ShhShellTests */,
|
||||
|
||||
@@ -261,9 +261,9 @@ class SSHHandler: ObservableObject {
|
||||
|
||||
interactiveShellSession(channel: channel)
|
||||
|
||||
ssh_channel_close(channel)
|
||||
ssh_channel_send_eof(channel)
|
||||
ssh_channel_free(channel)
|
||||
// ssh_channel_close(channel)
|
||||
// ssh_channel_send_eof(channel)
|
||||
// ssh_channel_free(channel)
|
||||
}
|
||||
|
||||
private func interactiveShellSession(channel: ssh_channel) {
|
||||
@@ -271,6 +271,8 @@ class SSHHandler: ObservableObject {
|
||||
var buffer: [CChar] = Array(repeating: 0, count: 256)
|
||||
var nbytes: CInt = 0
|
||||
|
||||
let timer: Timer?
|
||||
|
||||
status = ssh_channel_request_pty(channel)
|
||||
guard status == SSH_OK else { return }
|
||||
|
||||
@@ -280,19 +282,29 @@ class SSHHandler: ObservableObject {
|
||||
status = ssh_channel_request_shell(channel)
|
||||
guard status == SSH_OK else { return }
|
||||
|
||||
// Task {
|
||||
while (ssh_channel_is_open(channel) != 0) && (ssh_channel_is_eof(channel) == 0) {
|
||||
nbytes = ssh_channel_read(channel, &buffer, UInt32(MemoryLayout.size(ofValue: buffer)), 0)
|
||||
if nbytes < 0 {
|
||||
return
|
||||
}
|
||||
timer = Timer(timeInterval: 0.01, repeats: true) { _ in
|
||||
// guard let self = self else {
|
||||
// timer?.invalidate()
|
||||
// return
|
||||
// }
|
||||
guard ssh_channel_is_open(channel) != 0 else { return }
|
||||
guard ssh_channel_is_eof(channel) == 0 else { return }
|
||||
|
||||
nbytes = ssh_channel_read(channel, &buffer, UInt32(buffer.count), 0)
|
||||
guard nbytes > 0 else { return }
|
||||
|
||||
if nbytes > 0 {
|
||||
write(1, buffer, Int(nbytes))
|
||||
}
|
||||
sleep(1)
|
||||
print(String(cString: buffer))
|
||||
}
|
||||
// }
|
||||
print(String(utf8String: buffer))
|
||||
|
||||
DispatchQueue.global().async {
|
||||
RunLoop.current.add(timer!, forMode: .common)
|
||||
}
|
||||
|
||||
// ssh_channel_close(channel)
|
||||
// ssh_channel_free(channel)
|
||||
}
|
||||
|
||||
private func logSshGetError() {
|
||||
|
||||
@@ -71,10 +71,10 @@ struct ContentView: View {
|
||||
}
|
||||
}
|
||||
.disabled(!(connected && handler.authorized))
|
||||
//
|
||||
// Button("request a shell") {
|
||||
// handler.openShell()
|
||||
// }
|
||||
|
||||
Button("request a shell") {
|
||||
handler.openShell()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user