Patch for test reading function
Maxim Dounin
mdounin at mdounin.ru
Sat Oct 1 11:10:52 UTC 2011
Hello!
On Sat, Oct 01, 2011 at 12:52:37AM -0300, Wandenberg Peixoto wrote:
> Hi,
>
> I would like to suggest a small patch for function ngx_http_test_reading to
> properly works under https connections.
> Using SSL_peek function to detect when request is ended by the client.
>
> I hope you accept it.
>
> Regards,
> Wandenberg
> --- src/http/ngx_http_request.c 2011-10-01 00:27:17.895845001 -0300
> +++ src/http/ngx_http_request.c 2011-10-01 00:15:46.055845002 -0300
> @@ -2353,7 +2353,15 @@
>
> #endif
>
> +#if (NGX_HTTP_SSL)
> + if (c->ssl != NULL) {
> + n = SSL_peek(c->ssl->connection, buf, 1);
> + } else {
> + n = recv(c->fd, buf, 1, MSG_PEEK);
> + }
> +#else
> n = recv(c->fd, buf, 1, MSG_PEEK);
> +#endif
>
> if (n == 0) {
> rev->eof = 1;
> @@ -2363,9 +2371,19 @@
> goto closed;
>
> } else if (n == -1) {
> - err = ngx_socket_errno;
> +#if (NGX_HTTP_SSL)
> + if (c->ssl != NULL) {
> + err = SSL_get_error(c->ssl->connection, n);
> + } else {
> + err = ngx_socket_errno;
> + }
> +
> + if ((err != NGX_EAGAIN) && (err != SSL_ERROR_WANT_READ) && (err != SSL_ERROR_WANT_WRITE)) {
> +#else
> + err = ngx_socket_errno;
>
> - if (err != NGX_EAGAIN) {
> + if (err != NGX_EAGAIN) {
> +#endif
> rev->eof = 1;
> c->error = 1;
>
(Just a side note: there are multiple style issues in the patch.)
I would like to see this abstracted in connection API, with
something like c->peek() (handled by ssl events code for ssl
connections, much like it's currently done for c->recv()).
Maxim Dounin
More information about the nginx-devel
mailing list