mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
fix test connection button
increase buffer to 512 bytes made it a blocking read because its happening on a bg thread anyways using a cchar bitpattern for each string.utf8 when writing its made no diff yet increased sleep if nothing is returned
This commit is contained in:
@@ -320,8 +320,8 @@ class SSHHandler: ObservableObject {
|
|||||||
guard ssh_channel_is_open(channel) != 0 else { return nil }
|
guard ssh_channel_is_open(channel) != 0 else { return nil }
|
||||||
guard ssh_channel_is_eof(channel) == 0 else { return nil }
|
guard ssh_channel_is_eof(channel) == 0 else { return nil }
|
||||||
|
|
||||||
var buffer: [CChar] = Array(repeating: 0, count: 256)
|
var buffer: [CChar] = Array(repeating: 0, count: 512)
|
||||||
let nbytes = ssh_channel_read_nonblocking(channel, &buffer, UInt32(buffer.count), 0)
|
let nbytes = ssh_channel_read(channel, &buffer, UInt32(buffer.count), 0)
|
||||||
|
|
||||||
guard nbytes > 0 else { return nil }
|
guard nbytes > 0 else { return nil }
|
||||||
|
|
||||||
@@ -345,7 +345,10 @@ class SSHHandler: ObservableObject {
|
|||||||
guard ssh_channel_is_open(channel) != 0 else { return }
|
guard ssh_channel_is_open(channel) != 0 else { return }
|
||||||
guard ssh_channel_is_eof(channel) == 0 else { return }
|
guard ssh_channel_is_eof(channel) == 0 else { return }
|
||||||
|
|
||||||
var buffer: [CChar] = Array(string.utf8CString)
|
var buffer: [CChar] = []
|
||||||
|
for byte in string.utf8 {
|
||||||
|
buffer.append(CChar(bitPattern: byte))
|
||||||
|
}
|
||||||
let nwritten = Int(ssh_channel_write(channel, &buffer, UInt32(buffer.count)))
|
let nwritten = Int(ssh_channel_write(channel, &buffer, UInt32(buffer.count)))
|
||||||
|
|
||||||
if nwritten != buffer.count {
|
if nwritten != buffer.count {
|
||||||
@@ -353,7 +356,7 @@ class SSHHandler: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resizeTTY(toRows: Int, toCols: Int) {
|
func resizePTY(toRows: Int, toCols: Int) {
|
||||||
guard ssh_channel_is_open(channel) != 0 else { return }
|
guard ssh_channel_is_open(channel) != 0 else { return }
|
||||||
guard ssh_channel_is_eof(channel) == 0 else { return }
|
guard ssh_channel_is_eof(channel) == 0 else { return }
|
||||||
|
|
||||||
|
|||||||
@@ -136,6 +136,10 @@ struct ConnectionView: View {
|
|||||||
.disabled(!(handler.connected && handler.authorized))
|
.disabled(!(handler.connected && handler.authorized))
|
||||||
|
|
||||||
Button() {
|
Button() {
|
||||||
|
if handler.authorized && handler.connected {
|
||||||
|
} else {
|
||||||
|
handler.go()
|
||||||
|
}
|
||||||
withAnimation { handler.testExec() }
|
withAnimation { handler.testExec() }
|
||||||
} label: {
|
} label: {
|
||||||
if let testResult = handler.testSuceeded {
|
if let testResult = handler.testSuceeded {
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ class SSHTerminalView: TerminalView, TerminalViewDelegate {
|
|||||||
if let read = handler.readFromChannel() {
|
if let read = handler.readFromChannel() {
|
||||||
DispatchQueue.main.async { self?.feed(text: read) }
|
DispatchQueue.main.async { self?.feed(text: read) }
|
||||||
} else {
|
} else {
|
||||||
usleep(1_000)
|
usleep(1_000_000)
|
||||||
}
|
}
|
||||||
|
// self?.setNeedsDisplay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +51,7 @@ class SSHTerminalView: TerminalView, TerminalViewDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func sizeChanged(source: TerminalView, newCols: Int, newRows: Int) {
|
public func sizeChanged(source: TerminalView, newCols: Int, newRows: Int) {
|
||||||
handler?.resizeTTY(toRows: newRows, toCols: newCols)
|
handler?.resizePTY(toRows: newRows, toCols: newCols)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func send(source: TerminalView, data: ArraySlice<UInt8>) {
|
public func send(source: TerminalView, data: ArraySlice<UInt8>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user