Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ssh2.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,14 @@ PHP_FUNCTION(ssh2_poll)

pollfds[i].events = Z_LVAL_P(tmpzval);
hash_key_zstring = zend_string_init("resource", sizeof("resource") - 1, 0);
if ((tmpzval = zend_hash_find(Z_ARRVAL_P(subarray), hash_key_zstring)) == NULL || Z_TYPE_P(tmpzval) != IS_REFERENCE
|| (tmpzval = Z_REFVAL_P(tmpzval)) == NULL || Z_TYPE_P(tmpzval) != IS_RESOURCE) {
if ((tmpzval = zend_hash_find(Z_ARRVAL_P(subarray), hash_key_zstring)) == NULL) {
php_error_docref(NULL, E_WARNING, "Invalid data in subarray, no resource element, or not of type resource");
numfds--;
zend_string_release(hash_key_zstring);
continue;
}
ZVAL_DEREF(tmpzval);
if (Z_TYPE_P(tmpzval) != IS_RESOURCE) {
php_error_docref(NULL, E_WARNING, "Invalid data in subarray, no resource element, or not of type resource");
numfds--;
zend_string_release(hash_key_zstring);
Expand Down
34 changes: 34 additions & 0 deletions tests/ssh2_poll.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
ssh2_poll() - Tests polling a channel for events
--SKIPIF--
<?php require('ssh2_skip.inc'); ssh2t_needs_auth(); ?>
--FILE--
<?php require('ssh2_test.inc');

$ssh = ssh2_connect(TEST_SSH2_HOSTNAME, TEST_SSH2_PORT);
ssh2t_auth($ssh);

$stream = ssh2_exec($ssh, 'echo "poll test"');
stream_set_blocking($stream, false);

echo "**Poll with direct resource\n";
$polldesc = array(
array(
'resource' => $stream,
'events' => SSH2_POLLIN,
),
);
$ready = ssh2_poll($polldesc, 5);
var_dump(is_int($ready));
var_dump($ready >= 0);

echo "**Poll result has revents\n";
var_dump(array_key_exists('revents', $polldesc[0]));

fclose($stream);
--EXPECT--
**Poll with direct resource
bool(true)
bool(true)
**Poll result has revents
bool(true)
Loading