create ssl buffer on demand and free it before keep-alive

This commit is contained in:
Igor Sysoev 2007-12-26 21:07:30 +00:00
parent efcf5c7468
commit 93d1079897
3 changed files with 38 additions and 9 deletions

View file

@ -344,14 +344,7 @@ ngx_ssl_create_connection(ngx_ssl_t *ssl, ngx_connection_t *c, ngx_uint_t flags)
return NGX_ERROR;
}
if (flags & NGX_SSL_BUFFER) {
sc->buffer = 1;
sc->buf = ngx_create_temp_buf(c->pool, NGX_SSL_BUFSIZE);
if (sc->buf == NULL) {
return NGX_ERROR;
}
}
sc->buffer = ((flags & NGX_SSL_BUFFER) != 0);
sc->connection = SSL_new(ssl->ctx);
@ -804,8 +797,28 @@ ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
limit = NGX_MAX_UINT32_VALUE - ngx_pagesize;
}
buf = c->ssl->buf;
if (buf == NULL) {
buf = ngx_create_temp_buf(c->pool, NGX_SSL_BUFSIZE);
if (buf == NULL) {
return NGX_CHAIN_ERROR;
}
c->ssl->buf = buf;
}
if (buf->start == NULL) {
buf->start = ngx_palloc(c->pool, NGX_SSL_BUFSIZE);
if (buf->start == NULL) {
return NGX_CHAIN_ERROR;
}
buf->pos = buf->start;
buf->last = buf->start;
buf->end = buf->start + NGX_SSL_BUFSIZE;
}
send = 0;
flush = (in == NULL) ? 1 : 0;
@ -980,6 +993,15 @@ ngx_ssl_read_handler(ngx_event_t *rev)
}
void
ngx_ssl_free_buffer(ngx_connection_t *c)
{
if (ngx_pfree(c->pool, c->ssl->buf->start) == NGX_OK) {
c->ssl->buf->start = NULL;
}
}
ngx_int_t
ngx_ssl_shutdown(ngx_connection_t *c)
{

View file

@ -132,6 +132,7 @@ ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size);
ssize_t ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl);
ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
off_t limit);
void ngx_ssl_free_buffer(ngx_connection_t *c);
ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c);
void ngx_cdecl ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
char *fmt, ...);

View file

@ -2112,6 +2112,12 @@ ngx_http_set_keepalive(ngx_http_request_t *r)
hc->nbusy = 0;
}
#if (NGX_HTTP_SSL)
if (c->ssl) {
ngx_ssl_free_buffer(c);
}
#endif
rev->handler = ngx_http_keepalive_handler;
if (wev->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) {