Merge pull request #2023 from rposky/ssh-default-socket-timeout

SSH2: Defer to default socket timeout in absence of more specific value
This commit is contained in:
terrafrost 2024-08-05 10:59:09 -05:00 committed by GitHub
commit 47895e2851
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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();