summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorScott MacVicar <scottmac@php.net>2011-07-23 01:29:44 +0000
committerScott MacVicar <scottmac@php.net>2011-07-23 01:29:44 +0000
commit04c2df66a333bf4442f806d56d7f22a863b8bc33 (patch)
tree194d5219cdc39eaf8bdbc261f729b0736a4167dd /ext/openssl
parentfcb9e4b2b36f7227b437fb7a66d769713c67100f (diff)
downloadphp-git-04c2df66a333bf4442f806d56d7f22a863b8bc33.tar.gz
When we have a blocking SSL socket, respect the timeout option.
reading from SSL sockets could block indefinitely due to the lack of timeout
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/xp_ssl.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c
index 4b4a144691..e0f06a76dc 100644
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@ -204,6 +204,36 @@ static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size
return didwrite;
}
+static void php_openssl_stream_wait_for_data(php_stream *stream, php_netstream_data_t *sock TSRMLS_DC)
+{
+ int retval;
+ struct timeval *ptimeout;
+
+ if (sock->socket == -1) {
+ return;
+ }
+
+ sock->timeout_event = 0;
+
+ if (sock->timeout.tv_sec == -1)
+ ptimeout = NULL;
+ else
+ ptimeout = &sock->timeout;
+
+ while(1) {
+ retval = php_pollfd_for(sock->socket, PHP_POLLREADABLE, ptimeout);
+
+ if (retval == 0)
+ sock->timeout_event = 1;
+
+ if (retval >= 0)
+ break;
+
+ if (php_socket_errno() != EINTR)
+ break;
+ }
+}
+
static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
{
php_openssl_netstream_data_t *sslsock = (php_openssl_netstream_data_t*)stream->abstract;
@@ -213,6 +243,13 @@ static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t coun
int retry = 1;
do {
+ if (sslsock->s.is_blocked) {
+ php_openssl_stream_wait_for_data(stream, &(sslsock->s) TSRMLS_CC);
+ if (sslsock->s.timeout_event) {
+ break;
+ }
+ /* there is no guarantee that there is application data available but something is there */
+ }
nr_bytes = SSL_read(sslsock->ssl_handle, buf, count);
if (nr_bytes <= 0) {