Mercurial > hg > nginx-quic
comparison src/event/ngx_event_openssl.c @ 7353:87d2ea860f38
SSL: restore handlers after blocking.
It is possible that after SSL_read() will return SSL_ERROR_WANT_WRITE,
further calls will return SSL_ERROR_WANT_READ without reading any
application data. We have to call ngx_handle_write_event() and
switch back to normal write handling much like we do if there are some
application data, or the write there will be reported again and again.
Similarly, we have to switch back to normal read handling if there
is saved read handler and SSL_write() returns SSL_ERROR_WANT_WRITE.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 10 Sep 2018 18:57:39 +0300 |
parents | 0de0b16a551c |
children | e3ba4026c02d |
comparison
equal
deleted
inserted
replaced
7352:0de0b16a551c | 7353:87d2ea860f38 |
---|---|
1673 err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0; | 1673 err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0; |
1674 | 1674 |
1675 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr); | 1675 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr); |
1676 | 1676 |
1677 if (sslerr == SSL_ERROR_WANT_READ) { | 1677 if (sslerr == SSL_ERROR_WANT_READ) { |
1678 | |
1679 if (c->ssl->saved_write_handler) { | |
1680 | |
1681 c->write->handler = c->ssl->saved_write_handler; | |
1682 c->ssl->saved_write_handler = NULL; | |
1683 c->write->ready = 1; | |
1684 | |
1685 if (ngx_handle_write_event(c->write, 0) != NGX_OK) { | |
1686 return NGX_ERROR; | |
1687 } | |
1688 | |
1689 ngx_post_event(c->write, &ngx_posted_events); | |
1690 } | |
1691 | |
1678 c->read->ready = 0; | 1692 c->read->ready = 0; |
1679 return NGX_AGAIN; | 1693 return NGX_AGAIN; |
1680 } | 1694 } |
1681 | 1695 |
1682 if (sslerr == SSL_ERROR_WANT_WRITE) { | 1696 if (sslerr == SSL_ERROR_WANT_WRITE) { |
1932 err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0; | 1946 err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0; |
1933 | 1947 |
1934 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr); | 1948 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr); |
1935 | 1949 |
1936 if (sslerr == SSL_ERROR_WANT_WRITE) { | 1950 if (sslerr == SSL_ERROR_WANT_WRITE) { |
1951 | |
1952 if (c->ssl->saved_read_handler) { | |
1953 | |
1954 c->read->handler = c->ssl->saved_read_handler; | |
1955 c->ssl->saved_read_handler = NULL; | |
1956 c->read->ready = 1; | |
1957 | |
1958 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { | |
1959 return NGX_ERROR; | |
1960 } | |
1961 | |
1962 ngx_post_event(c->read, &ngx_posted_events); | |
1963 } | |
1964 | |
1937 c->write->ready = 0; | 1965 c->write->ready = 0; |
1938 return NGX_AGAIN; | 1966 return NGX_AGAIN; |
1939 } | 1967 } |
1940 | 1968 |
1941 if (sslerr == SSL_ERROR_WANT_READ) { | 1969 if (sslerr == SSL_ERROR_WANT_READ) { |