From 62588bee99b0dd163604f900e2b6efc3af7b4aaf Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 16 Dec 2012 03:15:56 +0100 Subject: [PATCH] Don't try to connect again if a previous connection attempt failed. --- frontend/classes/class.sshconnector.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/classes/class.sshconnector.php b/frontend/classes/class.sshconnector.php index e382fe7..5bc93ad 100644 --- a/frontend/classes/class.sshconnector.php +++ b/frontend/classes/class.sshconnector.php @@ -18,6 +18,7 @@ class SshConnector extends CPHPBaseClass public $connected = false; public $authenticated = false; public $connection = null; + public $failed = false; public $host = "localhost"; public $port = 22; @@ -34,11 +35,14 @@ class SshConnector extends CPHPBaseClass { try { - if($this->connected == false || $this->authenticated == false) + if($this->failed == false && ($this->connected == false || $this->authenticated == false)) { - /* TODO: Don't attempt to connect again if it failed the first time. */ $this->Connect(); } + elseif($this->failed == true) + { + throw new SshConnectException("Previous connection attempt failed."); + } return $this->DoCommand($command, $throw_exception); } @@ -46,12 +50,14 @@ class SshConnector extends CPHPBaseClass { $error = $e->getMessage(); $command = implode(" ", $command); + $this->failed = true; throw new SshConnectException("Could not run command {$command}: Failed to connect: {$error}"); } catch (SshAuthException $e) { $error = $e->getMessage(); $command = implode(" ", $command); + $this->failed = true; throw new SshConnectException("Could not run command {$command}: Failed to authenticate: {$error}"); } }