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 = {
|
A92538912DEE06DC007E0A18 = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
A95FAA582DF4B71F00DE2F5A /* ci_scripts */,
|
|
||||||
A95FAA462DF3884B00DE2F5A /* Config.xcconfig */,
|
A95FAA462DF3884B00DE2F5A /* Config.xcconfig */,
|
||||||
|
A95FAA582DF4B71F00DE2F5A /* ci_scripts */,
|
||||||
A92538C72DEE0742007E0A18 /* ShhShell */,
|
A92538C72DEE0742007E0A18 /* ShhShell */,
|
||||||
A92538D42DEE0756007E0A18 /* Resources */,
|
A92538D42DEE0756007E0A18 /* Resources */,
|
||||||
A92538CC2DEE0744007E0A18 /* ShhShellTests */,
|
A92538CC2DEE0744007E0A18 /* ShhShellTests */,
|
||||||
|
|||||||
@@ -261,9 +261,9 @@ class SSHHandler: ObservableObject {
|
|||||||
|
|
||||||
interactiveShellSession(channel: channel)
|
interactiveShellSession(channel: channel)
|
||||||
|
|
||||||
ssh_channel_close(channel)
|
// ssh_channel_close(channel)
|
||||||
ssh_channel_send_eof(channel)
|
// ssh_channel_send_eof(channel)
|
||||||
ssh_channel_free(channel)
|
// ssh_channel_free(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func interactiveShellSession(channel: ssh_channel) {
|
private func interactiveShellSession(channel: ssh_channel) {
|
||||||
@@ -271,6 +271,8 @@ class SSHHandler: ObservableObject {
|
|||||||
var buffer: [CChar] = Array(repeating: 0, count: 256)
|
var buffer: [CChar] = Array(repeating: 0, count: 256)
|
||||||
var nbytes: CInt = 0
|
var nbytes: CInt = 0
|
||||||
|
|
||||||
|
let timer: Timer?
|
||||||
|
|
||||||
status = ssh_channel_request_pty(channel)
|
status = ssh_channel_request_pty(channel)
|
||||||
guard status == SSH_OK else { return }
|
guard status == SSH_OK else { return }
|
||||||
|
|
||||||
@@ -280,19 +282,29 @@ class SSHHandler: ObservableObject {
|
|||||||
status = ssh_channel_request_shell(channel)
|
status = ssh_channel_request_shell(channel)
|
||||||
guard status == SSH_OK else { return }
|
guard status == SSH_OK else { return }
|
||||||
|
|
||||||
// Task {
|
timer = Timer(timeInterval: 0.01, repeats: true) { _ in
|
||||||
while (ssh_channel_is_open(channel) != 0) && (ssh_channel_is_eof(channel) == 0) {
|
// guard let self = self else {
|
||||||
nbytes = ssh_channel_read(channel, &buffer, UInt32(MemoryLayout.size(ofValue: buffer)), 0)
|
// timer?.invalidate()
|
||||||
if nbytes < 0 {
|
// return
|
||||||
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 {
|
if nbytes > 0 {
|
||||||
write(1, buffer, Int(nbytes))
|
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() {
|
private func logSshGetError() {
|
||||||
|
|||||||
@@ -71,10 +71,10 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.disabled(!(connected && handler.authorized))
|
.disabled(!(connected && handler.authorized))
|
||||||
//
|
|
||||||
// Button("request a shell") {
|
Button("request a shell") {
|
||||||
// handler.openShell()
|
handler.openShell()
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user