wez Fri Dec 24 21:02:55 2004 EDT Modified files: /php-src/ext/standard streamsfuncs.c /php-src/ext/openssl xp_ssl.c Log: When a socket is non-blocking, don't block ssl enabled sockets. Allow for non-blocking negotiation when calling stream_socket_enable_crypto(). That function will return the foolowing values: false - negotiation failed 0 - try again when more data is available (only for non-blocking sockets) true - ssl was enabled http://cvs.php.net/diff.php/php-src/ext/standard/streamsfuncs.c?r1=1.48&r2=1.49&ty=u Index: php-src/ext/standard/streamsfuncs.c diff -u php-src/ext/standard/streamsfuncs.c:1.48 php-src/ext/standard/streamsfuncs.c:1.49 --- php-src/ext/standard/streamsfuncs.c:1.48 Thu Dec 23 14:39:22 2004 +++ php-src/ext/standard/streamsfuncs.c Fri Dec 24 21:02:55 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streamsfuncs.c,v 1.48 2004/12/23 19:39:22 wez Exp $ */ +/* $Id: streamsfuncs.c,v 1.49 2004/12/25 02:02:55 wez Exp $ */ #include "php.h" #include "php_globals.h" @@ -1290,7 +1290,7 @@ } /* }}} */ -/* {{{ proto bool stream_socket_enable_crypto(resource stream, bool enable [, int cryptokind, resource sessionstream]) +/* {{{ proto int stream_socket_enable_crypto(resource stream, bool enable [, int cryptokind, resource sessionstream]) Enable or disable a specific kind of crypto on the stream */ PHP_FUNCTION(stream_socket_enable_crypto) { @@ -1298,6 +1298,7 @@ zval *zstream, *zsessstream = NULL; php_stream *stream, *sessstream = NULL; zend_bool enable; + int ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb|lr", &zstream, &enable, &cryptokind, &zsessstream) == FAILURE) { RETURN_FALSE; @@ -1315,7 +1316,17 @@ } } - RETURN_BOOL(php_stream_xport_crypto_enable(stream, enable TSRMLS_CC) < 0 ? 0 : 1); + ret = php_stream_xport_crypto_enable(stream, enable TSRMLS_CC); + switch (ret) { + case -1: + RETURN_FALSE; + + case 0: + RETURN_LONG(0); + + default: + RETURN_TRUE; + } } /* }}} */ http://cvs.php.net/diff.php/php-src/ext/openssl/xp_ssl.c?r1=1.20&r2=1.21&ty=u Index: php-src/ext/openssl/xp_ssl.c diff -u php-src/ext/openssl/xp_ssl.c:1.20 php-src/ext/openssl/xp_ssl.c:1.21 --- php-src/ext/openssl/xp_ssl.c:1.20 Wed Nov 3 08:12:40 2004 +++ php-src/ext/openssl/xp_ssl.c Fri Dec 24 21:02:55 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: xp_ssl.c,v 1.20 2004/11/03 13:12:40 jorton Exp $ */ +/* $Id: xp_ssl.c,v 1.21 2004/12/25 02:02:55 wez Exp $ */ #include "php.h" #include "ext/standard/file.h" @@ -46,6 +46,8 @@ int is_client; int ssl_active; php_stream_xport_crypt_method_t method; + unsigned state_set:1; + unsigned _spare:31; } php_openssl_netstream_data_t; php_stream_ops php_openssl_socket_ops; @@ -92,6 +94,8 @@ case SSL_ERROR_WANT_WRITE: /* re-negotiation, or perhaps the SSL layer needs more * packets: retry in next iteration */ + errno = EAGAIN; + retry = sslsock->s.is_blocked; break; case SSL_ERROR_SYSCALL: if (ERR_peek_error() == 0) { @@ -159,6 +163,7 @@ } retry = 0; + errno = 0; } return retry; } @@ -210,7 +215,7 @@ if (nr_bytes <= 0) { retry = handle_ssl_error(stream, nr_bytes TSRMLS_CC); - stream->eof = (retry == 0 && !SSL_pending(sslsock->ssl_handle)); + stream->eof = (retry == 0 && errno != EAGAIN && !SSL_pending(sslsock->ssl_handle)); } else { /* we got the data */ @@ -377,10 +382,13 @@ int n, retry = 1; if (cparam->inputs.activate && !sslsock->ssl_active) { - if (sslsock->is_client) { - SSL_set_connect_state(sslsock->ssl_handle); - } else { - SSL_set_accept_state(sslsock->ssl_handle); + if (!sslsock->state_set) { + if (sslsock->is_client) { + SSL_set_connect_state(sslsock->ssl_handle); + } else { + SSL_set_accept_state(sslsock->ssl_handle); + } + sslsock->state_set = 1; } do { @@ -409,6 +417,8 @@ } X509_free(peer_cert); + } else { + n = errno == EAGAIN ? 0 : -1; } return n;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php