[PECL-CVS] [pecl-networking-ssh2] feature/keepalive-support: address reviews

[email protected] (Rasmus Lerdorf) Sat, 4 Apr 2026 11:23:50 +0000
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Rasmus Lerdorf (rlerdorf)
Date: 2026-04-04T07:23:41-04:00

Commit: https://github.com/php/pecl-networking-ssh2/commit/f5aff86b3cac4e54a11c758d9aae8f7f0b7849f9
Raw diff: https://github.com/php/pecl-networking-ssh2/commit/f5aff86b3cac4e54a11c758d9aae8f7f0b7849f9.diff

address reviews

Changed paths:
  M  ssh2.c
  M  tests/ssh2_keepalive.phpt


Diff:

diff --git a/ssh2.c b/ssh2.c
index 7ff1335..953e0a5 100644
--- a/ssh2.c
+++ b/ssh2.c
@@ -475,6 +475,7 @@ PHP_FUNCTION(ssh2_set_timeout)
 }
 /* }}} */
 
+#ifdef PHP_SSH2_KEEPALIVE
 /* {{{ proto void ssh2_keepalive_config(resource session, bool want_reply, int interval)
  * Set how often keepalive messages should be sent. interval is the number
  * of seconds that can pass without any I/O; use 0 (the default) to disable
@@ -492,11 +493,16 @@ PHP_FUNCTION(ssh2_keepalive_config)
 		return;
 	}
 
+	if (interval < 0) {
+		php_error_docref(NULL, E_WARNING, "Argument #3 ($interval) must be greater than or equal to 0");
+		return;
+	}
+
 	if ((session = (LIBSSH2_SESSION *)zend_fetch_resource(Z_RES_P(zsession), PHP_SSH2_SESSION_RES_NAME, le_ssh2_session)) == NULL) {
 		return;
 	}
 
-	libssh2_keepalive_config(session, want_reply, interval);
+	libssh2_keepalive_config(session, want_reply, (unsigned int)interval);
 }
 /* }}} */
 
@@ -525,6 +531,7 @@ PHP_FUNCTION(ssh2_keepalive_send)
 	RETURN_LONG(seconds_to_next);
 }
 /* }}} */
+#endif
 
 /* {{{ proto array ssh2_methods_negotiated(resource session)
  * Return list of negotiaed methods
@@ -1701,8 +1708,10 @@ zend_function_entry ssh2_functions[] = {
 	PHP_FE(ssh2_connect,						arginfo_ssh2_connect)
 	PHP_FE(ssh2_disconnect,						arginfo_ssh2_disconnect)
 	PHP_FE(ssh2_set_timeout,					arginfo_ssh2_set_timeout)
+#ifdef PHP_SSH2_KEEPALIVE
 	PHP_FE(ssh2_keepalive_config,				arginfo_ssh2_keepalive_config)
 	PHP_FE(ssh2_keepalive_send,					arginfo_ssh2_keepalive_send)
+#endif
 	PHP_FE(ssh2_methods_negotiated,				arginfo_ssh2_methods_negotiated)
 	PHP_FE(ssh2_fingerprint,					arginfo_ssh2_fingerprint)
 
diff --git a/tests/ssh2_keepalive.phpt b/tests/ssh2_keepalive.phpt
index 878fd71..72596e4 100644
--- a/tests/ssh2_keepalive.phpt
+++ b/tests/ssh2_keepalive.phpt
@@ -1,7 +1,12 @@
 --TEST--
 ssh2_keepalive_config() and ssh2_keepalive_send() basic functionality
 --SKIPIF--
-<?php require('ssh2_skip.inc'); ?>
+<?php
+require('ssh2_skip.inc');
+if (!function_exists('ssh2_keepalive_config') || !function_exists('ssh2_keepalive_send')) {
+    die("skip keepalive support not available");
+}
+?>
 --FILE--
 <?php require('ssh2_test.inc');