Skip to content

Commit 040bcc3

Browse files
committed
Added a timeout to the SSH init method
1 parent 65bf1d1 commit 040bcc3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/Shout/SSH.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ public class SSH {
4545
/// - Parameters:
4646
/// - host: the host to connect to
4747
/// - port: the port to connect to; default 22
48+
/// - timeout: timeout to use (in msec); default 5000 (5 seconds)
4849
/// - Throws: SSHError if the SSH session couldn't be created
49-
public init(host: String, port: Int32 = 22) throws {
50+
public init(host: String, port: Int32 = 22, timeout: UInt = 5000) throws {
5051
self.sock = try Socket.create()
5152
self.session = try Session()
5253

5354
session.blocking = 1
54-
try sock.connect(to: host, port: port)
55+
try sock.connect(to: host, port: port, timeout: timeout)
5556
try session.handshake(over: sock)
5657
}
5758

0 commit comments

Comments
 (0)