I am using the code in the example NIOSSHClient in my app, to issue commands to some servers. I am intending for the application to run on macOS as well as iOS. So far so good except for one small thing.
My app works fine on macOS but on iOS, every command sent via SSH returns an exit code of 1 and essentially doesn't work. I found that if I put a small sleep in the code then it works fine. I am running the iOS variant on the iPad simulator.
The code code below is from ExecHandler.swift in the channelActive() function. It is essentially unchanged from the sample app except for dup()ing the file handles and adding the aforementioned sleep() call.
}.takingOwnershipOfDescriptors(input: dup(0), output: dup(1)).whenComplete { result in
switch result {
case .success:
// We need to exec a thing.
let execRequest = SSHChannelRequestEvent.ExecRequest(command: self.command, wantReply: false)
context.triggerUserOutboundEvent(execRequest).whenFailure { _ in
context.close(promise: nil)
}
Thread.sleep(forTimeInterval: 0.1) // Hmm, without this the command fails if run from iOS.
case .failure(let error):
context.fireErrorCaught(error)
}
Does anyone have any ideas on this?