From 7d6ad7d42f99bbaace3eff6c5dbdeb58333773d5 Mon Sep 17 00:00:00 2001 From: bruceauyeung Date: Tue, 14 Mar 2017 09:51:12 +0800 Subject: [PATCH] add timeout for establishing tcp connection --- easyssh.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/easyssh.go b/easyssh.go index c530eea..a722550 100644 --- a/easyssh.go +++ b/easyssh.go @@ -32,6 +32,9 @@ type MakeConfig struct { Key string Port string Password string + // Timeout is the maximum amount of time for the TCP connection to establish. + // A Timeout of zero means no timeout. + Timeout time.Duration } // returns ssh.Signer from user you running app home path + cutted key path. @@ -76,8 +79,9 @@ func (ssh_conf *MakeConfig) connect() (*ssh.Session, error) { } config := &ssh.ClientConfig{ - User: ssh_conf.User, - Auth: auths, + User: ssh_conf.User, + Auth: auths, + Timeout: ssh_conf.Timeout, } client, err := ssh.Dial("tcp", ssh_conf.Server+":"+ssh_conf.Port, config)