Author: rhuijben Date: Wed Nov 4 00:28:12 2015 New Revision: 1712447 URL: http://svn.apache.org/viewvc?rev=1712447&view=rev Log: Apply a simple hack to the MockHTTP server to make sure the SSL_read and SSL_write calls follow the documentation:
[From man SSL_read()] WARNING When an SSL_read() operation has to be repeated because of SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE, it must be repeated with the same arguments. [From man SSL_write()] WARNING When an SSL_write() operation has to be repeated because of SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE, it must be repeated with the same arguments. When calling SSL_write() with num=0 bytes to be sent the behaviour is undefined. On Debian Jessy (which I installed after philipm noted problems there) I see far more SSL_ERROR_WANT_READ and SSL_ERROR_WANT_WRITE cases than on my system and a bit of test code showed that we don't follow these rules, when playing with buffer offsets and readlines, etc. * test/MockHTTPinC/MockHTTP_server.c (sslCtx_t): Create some buffers. (sslSocketWrite): Ensure that all writes on a socket use the same address. (sslSocketRead): Ensure that all reads on a socket use the same address. Modified: serf/trunk/test/MockHTTPinC/MockHTTP_server.c Modified: serf/trunk/test/MockHTTPinC/MockHTTP_server.c URL: http://svn.apache.org/viewvc/serf/trunk/test/MockHTTPinC/MockHTTP_server.c?rev=1712447&r1=1712446&r2=1712447&view=diff ============================================================================== --- serf/trunk/test/MockHTTPinC/MockHTTP_server.c (original) +++ serf/trunk/test/MockHTTPinC/MockHTTP_server.c Wed Nov 4 00:28:12 2015 @@ -2230,6 +2230,8 @@ struct sslCtx_t { SSL* ssl; BIO *bio; + char read_buffer[8192]; + char write_buffer[8192]; }; static int init_done = 0; @@ -2718,8 +2720,15 @@ sslSocketWrite(_mhClientCtx_t *cctx, con sslCtx_t *ssl_ctx = cctx->ssl_ctx; int result, ssl_err; + if (*len > sizeof(ssl_ctx->write_buffer)) + *len = sizeof(ssl_ctx->write_buffer); + memcpy(ssl_ctx->write_buffer, data, *len); + + if (*len == 0) + return APR_SUCCESS; + ssl_ctx->bio_status = APR_SUCCESS; - result = SSL_write(ssl_ctx->ssl, data, *len); + result = SSL_write(ssl_ctx->ssl, ssl_ctx->write_buffer, *len); if (result > 0) { *len = result; return APR_SUCCESS; @@ -2773,10 +2782,14 @@ sslSocketRead(apr_socket_t *skt, void *b sslCtx_t *ssl_ctx = baton; int result; + if (*len > sizeof(ssl_ctx->read_buffer)) + *len = sizeof(ssl_ctx->read_buffer); + ssl_ctx->bio_status = APR_SUCCESS; - result = SSL_read(ssl_ctx->ssl, data, *len); + result = SSL_read(ssl_ctx->ssl, ssl_ctx->read_buffer, *len); if (result > 0) { *len = result; + memcpy(data, ssl_ctx->read_buffer, *len); return APR_SUCCESS; } else { int ssl_err;