diff --git a/Sources/Shout/SSH.swift b/Sources/Shout/SSH.swift index a0236d9..008e02e 100644 --- a/Sources/Shout/SSH.swift +++ b/Sources/Shout/SSH.swift @@ -49,7 +49,7 @@ public class SSH { /// - Throws: SSHError if the SSH session couldn't be created public init(host: String, port: Int32 = 22, timeout: UInt = 0) throws { self.sock = try Socket.create() - self.session = try Session() + self.session = try Session(timeout: timeout) session.blocking = 1 try sock.connect(to: host, port: port, timeout: timeout) diff --git a/Sources/Shout/Session.swift b/Sources/Shout/Session.swift index 43ccfb7..da202f1 100644 --- a/Sources/Shout/Session.swift +++ b/Sources/Shout/Session.swift @@ -26,7 +26,7 @@ class Session { } } - init() throws { + init(timeout: UInt = 0) throws { guard Session.initResult == 0 else { throw SSHError.genericError("libssh2_init failed") } @@ -36,6 +36,7 @@ class Session { } self.cSession = cSession + libssh2_session_set_timeout(cSession, Int(timeout)) } func handshake(over socket: Socket) throws {