comparison src/http/ngx_http_request.c @ 438:e56ab5ac8c65

nginx-0.0.12-2004-09-24-20:12:19 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 24 Sep 2004 16:12:19 +0000
parents 470270fa84d2
children 4fe393d82f44
comparison
equal deleted inserted replaced
437:470270fa84d2 438:e56ab5ac8c65
482 482
483 static void ngx_http_process_request_line(ngx_event_t *rev) 483 static void ngx_http_process_request_line(ngx_event_t *rev)
484 { 484 {
485 u_char *p; 485 u_char *p;
486 ssize_t n; 486 ssize_t n;
487 ngx_int_t rc, rv, offset; 487 ngx_int_t rc, rv;
488 ngx_connection_t *c; 488 ngx_connection_t *c;
489 ngx_http_request_t *r; 489 ngx_http_request_t *r;
490 ngx_http_log_ctx_t *ctx; 490 ngx_http_log_ctx_t *ctx;
491 491
492 c = rev->data; 492 c = rev->data;
706 706
707 707
708 static void ngx_http_process_request_headers(ngx_event_t *rev) 708 static void ngx_http_process_request_headers(ngx_event_t *rev)
709 { 709 {
710 ssize_t n; 710 ssize_t n;
711 ngx_int_t rc, rv, i, offset; 711 ngx_int_t rc, rv, i;
712 ngx_table_elt_t *h, **cookie; 712 ngx_table_elt_t *h, **cookie;
713 ngx_connection_t *c; 713 ngx_connection_t *c;
714 ngx_http_request_t *r; 714 ngx_http_request_t *r;
715 715
716 c = rev->data; 716 c = rev->data;
937 937
938 static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, 938 static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r,
939 ngx_uint_t request_line) 939 ngx_uint_t request_line)
940 { 940 {
941 u_char *old, *new; 941 u_char *old, *new;
942 ngx_int_t offset;
943 ngx_buf_t *b; 942 ngx_buf_t *b;
944 ngx_http_connection_t *hc; 943 ngx_http_connection_t *hc;
945 ngx_http_core_srv_conf_t *cscf; 944 ngx_http_core_srv_conf_t *cscf;
946 945
947 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 946 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1543 1542
1544 1543
1545 static void ngx_http_set_keepalive(ngx_http_request_t *r) 1544 static void ngx_http_set_keepalive(ngx_http_request_t *r)
1546 { 1545 {
1547 ngx_int_t i; 1546 ngx_int_t i;
1548 size_t len;
1549 ngx_buf_t *b, *f; 1547 ngx_buf_t *b, *f;
1550 ngx_event_t *rev, *wev; 1548 ngx_event_t *rev, *wev;
1551 ngx_connection_t *c; 1549 ngx_connection_t *c;
1552 ngx_http_connection_t *hc; 1550 ngx_http_connection_t *hc;
1553 ngx_http_log_ctx_t *ctx; 1551 ngx_http_log_ctx_t *ctx;
1569 1567
1570 /* the pipelined request */ 1568 /* the pipelined request */
1571 1569
1572 if (b != c->buffer) { 1570 if (b != c->buffer) {
1573 1571
1574 /* move the large header buffers to the free list */ 1572 /*
1573 * If the large header buffers were allocated while the previous
1574 * request processing then we do not use c->buffer for
1575 * the pipelined request (see ngx_http_init_request()).
1576 *
1577 * Now we would move the large header buffers to the free list.
1578 */
1575 1579
1576 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); 1580 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1577 1581
1578 if (hc->free == NULL) { 1582 if (hc->free == NULL) {
1579 hc->free = ngx_palloc(c->pool, 1583 hc->free = ngx_palloc(c->pool,
1621 return; 1625 return;
1622 } 1626 }
1623 1627
1624 hc->pipeline = 0; 1628 hc->pipeline = 0;
1625 1629
1630
1631 /*
1632 * To keep a memory footprint as small as possible for an idle
1633 * keepalive connection we try to free the ngx_http_request_t and
1634 * c->buffer's memory if they were allocated outside the c->pool.
1635 * The large header buffers are always allocated outside the c->pool and
1636 * are freed too.
1637 */
1638
1626 if (ngx_pfree(c->pool, r) == NGX_OK) { 1639 if (ngx_pfree(c->pool, r) == NGX_OK) {
1627 hc->request = NULL; 1640 hc->request = NULL;
1628 } 1641 }
1629 1642
1630 b = c->buffer; 1643 b = c->buffer;
1631 1644
1632 if (ngx_pfree(c->pool, b->start) == NGX_OK) { 1645 if (ngx_pfree(c->pool, b->start) == NGX_OK) {
1646
1647 /*
1648 * the special note for ngx_http_keepalive_handler() that
1649 * c->buffer's memory was freed
1650 */
1651
1633 b->pos = NULL; 1652 b->pos = NULL;
1634 1653
1635 } else { 1654 } else {
1636 b->pos = b->start; 1655 b->pos = b->start;
1637 b->last = b->start; 1656 b->last = b->start;
1690 } 1709 }
1691 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET; 1710 c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;
1692 } 1711 }
1693 1712
1694 #if 0 1713 #if 0
1695 /* if "keepalive_buffers off" then we need some other place */ 1714 /* if ngx_http_request_t was freed then we need some other place */
1696 r->http_state = NGX_HTTP_KEEPALIVE_STATE; 1715 r->http_state = NGX_HTTP_KEEPALIVE_STATE;
1697 #endif 1716 #endif
1698 1717
1699 if (rev->ready) { 1718 if (rev->ready) {
1700 ngx_http_keepalive_handler(rev); 1719 ngx_http_keepalive_handler(rev);
1739 hc = c->data; 1758 hc = c->data;
1740 b = c->buffer; 1759 b = c->buffer;
1741 size = b->end - b->start; 1760 size = b->end - b->start;
1742 1761
1743 if (b->pos == NULL) { 1762 if (b->pos == NULL) {
1763
1764 /*
1765 * The c->buffer's memory was freed by ngx_http_set_keepalive().
1766 * However, the c->buffer->start and c->buffer->end were not changed
1767 * to keep the buffer size.
1768 */
1769
1744 if (!(b->pos = ngx_palloc(c->pool, size))) { 1770 if (!(b->pos = ngx_palloc(c->pool, size))) {
1745 ngx_http_close_connection(c); 1771 ngx_http_close_connection(c);
1746 return; 1772 return;
1747 } 1773 }
1748 1774