summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/openssl/xp_ssl.c15
-rw-r--r--main/php_streams.h3
-rw-r--r--main/streams/streams.c2
3 files changed, 18 insertions, 2 deletions
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c
index 9de0dcbef2..0bb22a678c 100644
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@ -2498,7 +2498,20 @@ static int php_openssl_sockop_cast(php_stream *stream, int castas, void **ret)
case PHP_STREAM_AS_FD_FOR_SELECT:
if (ret) {
- *(php_socket_t *)ret = sslsock->s.socket;
+ if (sslsock->ssl_active) {
+ /* OpenSSL has an internal buffer which select() cannot see. If we don't
+ fetch it into the stream's buffer, no activity will be reported on the
+ stream even though there is data waiting to be read - but we only fetch
+ the number of bytes OpenSSL has ready to give us since we weren't asked
+ for any data at this stage. This is only likely to cause issues with
+ non-blocking streams, but it's harmless to always do it. */
+ int bytes;
+ while ((bytes = SSL_pending(sslsock->ssl_handle)) > 0) {
+ php_stream_fill_read_buffer(stream, (size_t)bytes);
+ }
+ }
+
+ *(int *)ret = sslsock->s.socket;
}
return SUCCESS;
diff --git a/main/php_streams.h b/main/php_streams.h
index 3035bd560b..a21d442095 100644
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -307,6 +307,9 @@ PHPAPI size_t _php_stream_write(php_stream *stream, const char *buf, size_t coun
#define php_stream_write_string(stream, str) _php_stream_write(stream, str, strlen(str))
#define php_stream_write(stream, buf, count) _php_stream_write(stream, (buf), (count))
+PHPAPI void _php_stream_fill_read_buffer(php_stream *stream, size_t size);
+#define php_stream_fill_read_buffer(stream, size) _php_stream_fill_read_buffer((stream), (size))
+
#ifdef ZTS
PHPAPI size_t _php_stream_printf(php_stream *stream, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
#else
diff --git a/main/streams/streams.c b/main/streams/streams.c
index c47fe0d940..64b5470738 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -565,7 +565,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
/* {{{ generic stream operations */
-static void php_stream_fill_read_buffer(php_stream *stream, size_t size)
+PHPAPI void _php_stream_fill_read_buffer(php_stream *stream, size_t size)
{
/* allocate/fill the buffer */