Use the default socket timeout in absence of more specific user-defined value

This commit is contained in:
Robert 2024-08-01 12:14:33 -04:00
parent 6ad7c53bbf
commit b94d55a734
2 changed files with 5 additions and 4 deletions

View File

@ -2747,7 +2747,7 @@ class SSH2
* Set Timeout
*
* $ssh->exec('ping 127.0.0.1'); on a Linux host will never return and will run indefinitely. setTimeout() makes it so it'll timeout.
* Setting $timeout to false or 0 will mean there is no timeout.
* Setting $timeout to false or 0 will revert to the default socket timeout.
*
* @param mixed $timeout
*/
@ -3462,11 +3462,11 @@ class SSH2
}
/**
* @return int[] second and microsecond stream timeout options based on user-requested timeout and keep-alive, 0 by default
* @return int[] second and microsecond stream timeout options based on user-requested timeout and keep-alive, or the default socket timeout by default, which mirrors PHP socket streams.
*/
private function get_stream_timeout()
{
$sec = 0;
$sec = ini_get('default_socket_timeout');
$usec = 0;
if ($this->curTimeout > 0) {
$sec = (int) floor($this->curTimeout);

View File

@ -228,9 +228,10 @@ class SSH2UnitTest extends PhpseclibTestCase
*/
public function testGetStreamTimeout()
{
$default = ini_get('default_socket_timeout');
// no curTimeout, no keepAlive
$ssh = $this->createSSHMock();
$this->assertEquals([0, 0], self::callFunc($ssh, 'get_stream_timeout'));
$this->assertEquals([$default, 0], self::callFunc($ssh, 'get_stream_timeout'));
// curTimeout, no keepAlive
$ssh = $this->createSSHMock();