SSH: clarify role of constructor / connection timeout

Also, in Net_SSH2::_connect() $host is used in multiple places. Rather than changing all references to {$this->host}:{$this->port} preserve existing $host reference and update it accordingly
This commit is contained in:
terrafrost 2014-04-07 10:26:46 -05:00
parent 24bb941799
commit 677a291cb3
2 changed files with 19 additions and 12 deletions

View File

@ -479,16 +479,19 @@ class Net_SSH1
var $port;
/**
* Timeout for Constructor
* Timeout for initial connection
*
* For historical BC purposes setTimeout() does not effect timeout of constructor
* Set by the constructor call. Calling setTimeout() is optional. If it's not called functions like
* exec() won't timeout unless some PHP setting forces it too. The timeout specified in the constructor,
* however, is non-optional. There will be a timeout, whether or not you set it. If you don't it'll be
* 10 seconds. It is used by fsockopen() in that function.
*
* @see Net_SSH1::Net_SSH1()
* @see Net_SSH1::_connect()
* @var Integer
* @access private
*/
var $constructorTimeout;
var $connectionTimeout;
/**
* Default cipher
@ -550,7 +553,7 @@ class Net_SSH1
$this->host = $host;
$this->port = $port;
$this->constructorTimeout = $timeout;
$this->connectionTimeout = $timeout;
$this->cipher = $cipher;
}
@ -562,9 +565,9 @@ class Net_SSH1
*/
function _connect()
{
$this->fsock = @fsockopen($this->host, $this->port, $errno, $errstr, $this->constructorTimeout);
$this->fsock = @fsockopen($this->host, $this->port, $errno, $errstr, $this->connectionTimeout);
if (!$this->fsock) {
user_error(rtrim("Cannot connect to $this->host:$this->port. Error $errno. $errstr"));
user_error(rtrim("Cannot connect to {$this->host}:{$this->port}. Error $errno. $errstr"));
return false;
}

View File

@ -804,16 +804,19 @@ class Net_SSH2
var $port;
/**
* Timeout for Constructor
* Timeout for initial connection
*
* For historical BC purposes setTimeout() does not effect timeout of constructor
* Set by the constructor call. Calling setTimeout() is optional. If it's not called functions like
* exec() won't timeout unless some PHP setting forces it too. The timeout specified in the constructor,
* however, is non-optional. There will be a timeout, whether or not you set it. If you don't it'll be
* 10 seconds. It is used by fsockopen() and the initial stream_select in that function.
*
* @see Net_SSH2::Net_SSH2()
* @see Net_SSH2::_connect()
* @var Integer
* @access private
*/
var $constructorTimeout;
var $connectionTimeout;
/**
* Default Constructor.
@ -913,7 +916,7 @@ class Net_SSH2
$this->host = $host;
$this->port = $port;
$this->constructorTimeout = $timeout;
$this->connectionTimeout = $timeout;
}
/**
@ -924,14 +927,15 @@ class Net_SSH2
*/
function _connect()
{
$timeout = $this->constructorTimeout;
$timeout = $this->connectionTimeout;
$host = $this->host . ':' . $this->port;
$this->last_packet = strtok(microtime(), ' ') + strtok(''); // == microtime(true) in PHP5
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
$this->fsock = @fsockopen($this->host, $this->port, $errno, $errstr, $timeout);
if (!$this->fsock) {
user_error(rtrim("Cannot connect to $this->host:$this->port. Error $errno. $errstr"));
user_error(rtrim("Cannot connect to $host. Error $errno. $errstr"));
return false;
}
$elapsed = strtok(microtime(), ' ') + strtok('') - $start;