php / pecl-networking-ssh2

Bindings for the libssh2 library
http://pecl.php.net/package/ssh2
Other
51 stars 59 forks source link

Adding support for stream_select to shell streams #38

Closed rposky closed 3 years ago

rposky commented 4 years ago

PHP streams provide access to the select() system call via stream_select() for streams which can be cast as socket and/or file descriptors. This change implements the cast function provided to PHP stream resources representing SSH2 shell sessions, or those obtained via ssh2_shell.

The cast funtion simply yields the socket established during ssh2_connect for the purposes of enabling PHP's stream_select() to indicate read readiness on the SSH2 shell stream. Note that data available on the socket does not necessarily indicate data available on the shell stream's underlying LIBSSH2_CHANNEL object, as protocol data is filtered. Callers must be aware that no data may be available to read on the shell stream despite positive indication from stream_select(). The rate of such false positives is thought to be low.

Presently, attempts to invoke stream_select() on SSH2 shell streams yields the following warnings:

Warning: stream_select(): cannot represent a stream of type SSH2 Channel as a select()able descriptor in /repos/ssh2/tests/ssh2_stream_select.php on line 21

Warning: stream_select(): No stream arrays were passed in /repos/ssh2/tests/ssh2_stream_select.php on line 21

Given the long-deprecated state of libssh2_poll, and the recommendation therein to use poll() or select() system calls instead, this change is thought to be prudent.

References: https://www.libssh2.org/libssh2_poll.html https://bugs.php.net/bug.php?id=58974 https://github.com/php/php-src/blob/master/docs/streams.md#casting-streams

rposky commented 4 years ago

I'm looking into why the build tests have failed and will address it shortly.

rposky commented 4 years ago

Please excuse the back-to-back commits, as I've had to do some reverse engineering on the build and test process for the added test case and its output expectations.

rposky commented 4 years ago

Rebase and force push to tidy up.