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;
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) {
}
retry = 0;
+ errno = 0;
}
return retry;
}
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 */
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 {
}
X509_free(peer_cert);
+ } else {
+ n = errno == EAGAIN ? 0 : -1;
}
return n;
}
/* }}} */
-/* {{{ 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)
{
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;
}
}
- 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;
+ }
}
/* }}} */