1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-12 09:09:39 +01:00

Replaced php4 hack for microtime(true) with real microtime(true)

This commit is contained in:
Marc Philip Scholten 2013-12-05 18:46:46 +01:00
parent 03f290b050
commit d6c70a76d9

View File

@ -773,7 +773,7 @@ class Net_SSH2 {
require_once('Crypt/Hash.php'); require_once('Crypt/Hash.php');
} }
$this->last_packet = strtok(microtime(), ' ') + strtok(''); // == microtime(true) in PHP5 $this->last_packet = microtime(true);
$this->message_numbers = array( $this->message_numbers = array(
1 => 'NET_SSH2_MSG_DISCONNECT', 1 => 'NET_SSH2_MSG_DISCONNECT',
2 => 'NET_SSH2_MSG_IGNORE', 2 => 'NET_SSH2_MSG_IGNORE',
@ -844,13 +844,13 @@ class Net_SSH2 {
61 => 'NET_SSH2_MSG_USERAUTH_INFO_RESPONSE') 61 => 'NET_SSH2_MSG_USERAUTH_INFO_RESPONSE')
); );
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838 $start = microtime(true);
$this->fsock = @fsockopen($host, $port, $errno, $errstr, $timeout); $this->fsock = @fsockopen($host, $port, $errno, $errstr, $timeout);
if (!$this->fsock) { if (!$this->fsock) {
user_error(rtrim("Cannot connect to $host. Error $errno. $errstr")); user_error(rtrim("Cannot connect to $host. Error $errno. $errstr"));
return; return;
} }
$elapsed = strtok(microtime(), ' ') + strtok('') - $start; $elapsed = microtime(true) - $start;
$timeout-= $elapsed; $timeout-= $elapsed;
@ -2496,7 +2496,7 @@ class Net_SSH2 {
return false; return false;
} }
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838 $start = microtime(true);
$raw = fread($this->fsock, $this->decrypt_block_size); $raw = fread($this->fsock, $this->decrypt_block_size);
if (!strlen($raw)) { if (!strlen($raw)) {
@ -2529,7 +2529,7 @@ class Net_SSH2 {
$buffer.= $temp; $buffer.= $temp;
$remaining_length-= strlen($temp); $remaining_length-= strlen($temp);
} }
$stop = strtok(microtime(), ' ') + strtok(''); $stop = microtime(true);
if (strlen($buffer)) { if (strlen($buffer)) {
$raw.= $this->decrypt !== false ? $this->decrypt->decrypt($buffer) : $buffer; $raw.= $this->decrypt !== false ? $this->decrypt->decrypt($buffer) : $buffer;
} }
@ -2552,7 +2552,7 @@ class Net_SSH2 {
$this->get_seq_no++; $this->get_seq_no++;
if (defined('NET_SSH2_LOGGING')) { if (defined('NET_SSH2_LOGGING')) {
$current = strtok(microtime(), ' ') + strtok(''); $current = microtime(true);
$message_number = isset($this->message_numbers[ord($payload[0])]) ? $this->message_numbers[ord($payload[0])] : 'UNKNOWN (' . ord($payload[0]) . ')'; $message_number = isset($this->message_numbers[ord($payload[0])]) ? $this->message_numbers[ord($payload[0])] : 'UNKNOWN (' . ord($payload[0]) . ')';
$message_number = '<- ' . $message_number . $message_number = '<- ' . $message_number .
' (since last: ' . round($current - $this->last_packet, 4) . ', network: ' . round($stop - $start, 4) . 's)'; ' (since last: ' . round($current - $this->last_packet, 4) . ', network: ' . round($stop - $start, 4) . 's)';
@ -2723,7 +2723,7 @@ class Net_SSH2 {
$read = array($this->fsock); $read = array($this->fsock);
$write = $except = NULL; $write = $except = NULL;
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838 $start = microtime(true);
$sec = floor($this->curTimeout); $sec = floor($this->curTimeout);
$usec = 1000000 * ($this->curTimeout - $sec); $usec = 1000000 * ($this->curTimeout - $sec);
// on windows this returns a "Warning: Invalid CRT parameters detected" error // on windows this returns a "Warning: Invalid CRT parameters detected" error
@ -2731,7 +2731,7 @@ class Net_SSH2 {
$this->is_timeout = true; $this->is_timeout = true;
return true; return true;
} }
$elapsed = strtok(microtime(), ' ') + strtok('') - $start; $elapsed = microtime(true) - $start;
$this->curTimeout-= $elapsed; $this->curTimeout-= $elapsed;
} }
@ -2938,12 +2938,12 @@ class Net_SSH2 {
$packet.= $hmac; $packet.= $hmac;
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838 $start = microtime(true);
$result = strlen($packet) == fputs($this->fsock, $packet); $result = strlen($packet) == fputs($this->fsock, $packet);
$stop = strtok(microtime(), ' ') + strtok(''); $stop = microtime(true);
if (defined('NET_SSH2_LOGGING')) { if (defined('NET_SSH2_LOGGING')) {
$current = strtok(microtime(), ' ') + strtok(''); $current = microtime(true);
$message_number = isset($this->message_numbers[ord($data[0])]) ? $this->message_numbers[ord($data[0])] : 'UNKNOWN (' . ord($data[0]) . ')'; $message_number = isset($this->message_numbers[ord($data[0])]) ? $this->message_numbers[ord($data[0])] : 'UNKNOWN (' . ord($data[0]) . ')';
$message_number = '-> ' . $message_number . $message_number = '-> ' . $message_number .
' (since last: ' . round($current - $this->last_packet, 4) . ', network: ' . round($stop - $start, 4) . 's)'; ' (since last: ' . round($current - $this->last_packet, 4) . ', network: ' . round($stop - $start, 4) . 's)';