Skip to content

Commit 8c1d84c

Browse files
committed
Expose libssh2_session_set_timeout()
1 parent 520e1f0 commit 8c1d84c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

ssh2.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,29 @@ PHP_FUNCTION(ssh2_disconnect)
452452
}
453453
/* }}} */
454454

455+
/* {{{ proto void ssh2_session_set_timeout(resource session, long milliseconds)
456+
* Set the timeout in milliseconds for how long a blocking the libssh2 function calls may wait until they consider the situation an error and return LIBSSH2_ERROR_TIMEOUT.
457+
*
458+
* By default or if you set the timeout to zero, libssh2 has no timeout for blocking functions.
459+
*/
460+
PHP_FUNCTION(ssh2_session_set_timeout)
461+
{
462+
LIBSSH2_SESSION *session;
463+
zval *zsession;
464+
zend_long timeout;
465+
466+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &zsession, &timeout) == FAILURE) {
467+
return;
468+
}
469+
470+
if ((session = (LIBSSH2_SESSION *)zend_fetch_resource(Z_RES_P(zsession), PHP_SSH2_SESSION_RES_NAME, le_ssh2_session)) == NULL) {
471+
return;
472+
}
473+
474+
libssh2_session_set_timeout(session, timeout);
475+
}
476+
/* }}} */
477+
455478
/* {{{ proto array ssh2_methods_negotiated(resource session)
456479
* Return list of negotiaed methods
457480
*/
@@ -1401,6 +1424,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_ssh2_disconnect, 1)
14011424
ZEND_ARG_INFO(0, session)
14021425
ZEND_END_ARG_INFO()
14031426

1427+
ZEND_BEGIN_ARG_INFO(arginfo_ssh2_session_set_timeout, 2)
1428+
ZEND_ARG_INFO(0, session)
1429+
ZEND_ARG_INFO(1, timeout)
1430+
ZEND_END_ARG_INFO()
1431+
14041432
ZEND_BEGIN_ARG_INFO(arginfo_ssh2_methods_negotiated, 1)
14051433
ZEND_ARG_INFO(0, session)
14061434
ZEND_END_ARG_INFO()
@@ -1610,6 +1638,7 @@ ZEND_END_ARG_INFO()
16101638
zend_function_entry ssh2_functions[] = {
16111639
PHP_FE(ssh2_connect, arginfo_ssh2_connect)
16121640
PHP_FE(ssh2_disconnect, arginfo_ssh2_disconnect)
1641+
PHP_FE(ssh2_session_set_timeout, arginfo_ssh2_session_set_timeout)
16131642
PHP_FE(ssh2_methods_negotiated, arginfo_ssh2_methods_negotiated)
16141643
PHP_FE(ssh2_fingerprint, arginfo_ssh2_fingerprint)
16151644

0 commit comments

Comments
 (0)