Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 143:5526213be452
nginx-0.0.1-2003-10-10-19:10:50 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 10 Oct 2003 15:10:50 +0000 |
parents | cb77c084acdb |
children | ef8c87afcfc5 |
comparison
equal
deleted
inserted
replaced
142:cb77c084acdb | 143:5526213be452 |
---|---|
8 static void ngx_http_init_request(ngx_event_t *ev); | 8 static void ngx_http_init_request(ngx_event_t *ev); |
9 static void ngx_http_process_request_line(ngx_event_t *rev); | 9 static void ngx_http_process_request_line(ngx_event_t *rev); |
10 static void ngx_http_process_request_headers(ngx_event_t *rev); | 10 static void ngx_http_process_request_headers(ngx_event_t *rev); |
11 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); | 11 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); |
12 | 12 |
13 static void ngx_http_writer(ngx_event_t *ev); | 13 static void ngx_http_set_write_handler(ngx_http_request_t *r); |
14 | 14 |
15 static void ngx_http_block_read(ngx_event_t *ev); | 15 static void ngx_http_block_read(ngx_event_t *ev); |
16 static void ngx_http_read_discarded_body_event(ngx_event_t *rev); | 16 static void ngx_http_read_discarded_body_event(ngx_event_t *rev); |
17 static int ngx_http_read_discarded_body(ngx_http_request_t *r); | 17 static int ngx_http_read_discarded_body(ngx_http_request_t *r); |
18 | 18 |
110 /* aio, iocp, epoll */ | 110 /* aio, iocp, epoll */ |
111 ngx_http_init_request(rev); | 111 ngx_http_init_request(rev); |
112 return; | 112 return; |
113 } | 113 } |
114 | 114 |
115 if (ngx_handle_read_event(rev) == NGX_ERROR) { | |
116 ngx_http_close_connection(c); | |
117 return; | |
118 } | |
119 | |
120 #if 0 | |
121 | |
115 if (ngx_event_flags & NGX_HAVE_CLEAR_EVENT) { | 122 if (ngx_event_flags & NGX_HAVE_CLEAR_EVENT) { |
116 /* kqueue */ | 123 /* kqueue */ |
117 event = NGX_CLEAR_EVENT; | 124 event = NGX_CLEAR_EVENT; |
118 | 125 |
119 } else { | 126 } else { |
122 } | 129 } |
123 | 130 |
124 if (ngx_add_event(rev, NGX_READ_EVENT, event) == NGX_ERROR) { | 131 if (ngx_add_event(rev, NGX_READ_EVENT, event) == NGX_ERROR) { |
125 ngx_http_close_connection(c); | 132 ngx_http_close_connection(c); |
126 } | 133 } |
134 | |
135 #endif | |
136 | |
137 return; | |
127 } | 138 } |
128 | 139 |
129 | 140 |
130 static void ngx_http_init_request(ngx_event_t *rev) | 141 static void ngx_http_init_request(ngx_event_t *rev) |
131 { | 142 { |
658 return; | 669 return; |
659 } | 670 } |
660 } | 671 } |
661 | 672 |
662 rev->event_handler = ngx_http_block_read; | 673 rev->event_handler = ngx_http_block_read; |
674 c->write->event_handler = ngx_http_writer; | |
663 ngx_http_handler(r); | 675 ngx_http_handler(r); |
664 return; | 676 return; |
665 | 677 |
666 } else if (rc != NGX_AGAIN) { | 678 } else if (rc != NGX_AGAIN) { |
667 | 679 |
741 | 753 |
742 ngx_add_timer(rev, cscf->client_header_timeout); | 754 ngx_add_timer(rev, cscf->client_header_timeout); |
743 r->header_timeout_set = 1; | 755 r->header_timeout_set = 1; |
744 } | 756 } |
745 | 757 |
758 if (ngx_handle_read_event(rev) == NGX_ERROR) { | |
759 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
760 ngx_http_close_connection(r->connection); | |
761 return NGX_ERROR; | |
762 } | |
763 | |
764 #if 0 | |
746 if (!rev->active) { | 765 if (!rev->active) { |
747 if (ngx_event_flags & NGX_HAVE_CLEAR_EVENT) { | 766 if (ngx_event_flags & NGX_HAVE_CLEAR_EVENT) { |
748 /* kqueue */ | 767 /* kqueue */ |
749 event = NGX_CLEAR_EVENT; | 768 event = NGX_CLEAR_EVENT; |
750 | 769 |
757 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 776 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
758 ngx_http_close_connection(r->connection); | 777 ngx_http_close_connection(r->connection); |
759 return NGX_ERROR; | 778 return NGX_ERROR; |
760 } | 779 } |
761 } | 780 } |
781 #endif | |
762 | 782 |
763 return NGX_AGAIN; | 783 return NGX_AGAIN; |
764 } | 784 } |
765 | 785 |
766 if (n == 0) { | 786 if (n == 0) { |
778 | 798 |
779 return n; | 799 return n; |
780 } | 800 } |
781 | 801 |
782 | 802 |
783 void ngx_http_finalize_request(ngx_http_request_t *r, int error) | 803 void ngx_http_finalize_request(ngx_http_request_t *r, int rc) |
784 { | 804 { |
785 int rc; | |
786 ngx_event_t *rev, *wev; | 805 ngx_event_t *rev, *wev; |
787 | 806 |
788 if (r->main) { | 807 if (r->main || r->closed) { |
789 return; | 808 return; |
790 } | 809 } |
791 | |
792 rc = error; | |
793 | 810 |
794 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | 811 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
795 | 812 |
796 rev = r->connection->read; | 813 rev = r->connection->read; |
797 if (rev->timer_set) { | 814 if (rev->timer_set) { |
803 if (wev->timer_set) { | 820 if (wev->timer_set) { |
804 ngx_del_timer(wev); | 821 ngx_del_timer(wev); |
805 wev->timer_set = 0; | 822 wev->timer_set = 0; |
806 } | 823 } |
807 | 824 |
808 rc = ngx_http_special_response_handler(r, rc); | 825 ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc)); |
809 | 826 |
810 if (rc == NGX_AGAIN) { | 827 return; |
811 return; | |
812 } | |
813 | |
814 if (rc == NGX_ERROR) { | |
815 ngx_http_close_request(r, 0); | |
816 ngx_http_close_connection(r->connection); | |
817 return; | |
818 } | |
819 | |
820 #if 1 | |
821 return; | |
822 #endif | |
823 | 828 |
824 } else if (rc == NGX_ERROR) { | 829 } else if (rc == NGX_ERROR) { |
825 r->keepalive = 0; | 830 ngx_http_close_request(r, 0); |
826 r->lingering_close = 0; | 831 ngx_http_close_connection(r->connection); |
827 | 832 return; |
828 } else { | 833 |
829 if (ngx_http_send_last(r) == NGX_ERROR) { | 834 } else if (rc == NGX_AGAIN) { |
830 ngx_http_close_request(r, 0); | 835 ngx_http_set_write_handler(r); |
831 ngx_http_close_connection(r->connection); | 836 return; |
832 return; | |
833 } | |
834 | |
835 if (rc == NGX_AGAIN) { | |
836 ngx_http_set_write_handler(r); | |
837 return; | |
838 } | |
839 } | 837 } |
840 | 838 |
841 rev = r->connection->read; | 839 rev = r->connection->read; |
842 if (rev->timer_set) { | 840 if (rev->timer_set) { |
843 ngx_del_timer(rev); | 841 ngx_del_timer(rev); |
863 | 861 |
864 return; | 862 return; |
865 } | 863 } |
866 | 864 |
867 | 865 |
868 void ngx_http_set_write_handler(ngx_http_request_t *r) | 866 static void ngx_http_set_write_handler(ngx_http_request_t *r) |
869 { | 867 { |
870 int event; | 868 int event; |
871 ngx_event_t *wev; | 869 ngx_event_t *wev; |
872 ngx_http_core_loc_conf_t *clcf; | 870 ngx_http_core_loc_conf_t *clcf; |
873 | 871 |
881 clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r, | 879 clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r, |
882 ngx_http_core_module); | 880 ngx_http_core_module); |
883 ngx_add_timer(wev, clcf->send_timeout); | 881 ngx_add_timer(wev, clcf->send_timeout); |
884 wev->timer_set = 1; | 882 wev->timer_set = 1; |
885 | 883 |
884 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { | |
885 ngx_http_close_request(r, 0); | |
886 ngx_http_close_connection(r->connection); | |
887 } | |
888 | |
889 #if 0 | |
890 | |
886 if (ngx_event_flags & (NGX_HAVE_AIO_EVENT|NGX_HAVE_EDGE_EVENT)) { | 891 if (ngx_event_flags & (NGX_HAVE_AIO_EVENT|NGX_HAVE_EDGE_EVENT)) { |
887 /* aio, iocp, epoll */ | 892 /* aio, iocp, epoll */ |
888 return; | 893 return; |
889 } | 894 } |
890 | 895 |
908 if (ngx_add_event(wev, NGX_WRITE_EVENT, event) == NGX_ERROR) { | 913 if (ngx_add_event(wev, NGX_WRITE_EVENT, event) == NGX_ERROR) { |
909 ngx_http_close_request(r, 0); | 914 ngx_http_close_request(r, 0); |
910 ngx_http_close_connection(r->connection); | 915 ngx_http_close_connection(r->connection); |
911 } | 916 } |
912 | 917 |
918 #endif | |
919 | |
913 return; | 920 return; |
914 } | 921 } |
915 | 922 |
916 | 923 |
917 static void ngx_http_writer(ngx_event_t *wev) | 924 void ngx_http_writer(ngx_event_t *wev) |
918 { | 925 { |
919 int rc; | 926 int rc; |
920 ngx_event_t *rev; | 927 ngx_event_t *rev; |
921 ngx_connection_t *c; | 928 ngx_connection_t *c; |
922 ngx_http_request_t *r; | 929 ngx_http_request_t *r; |
1452 /* ctx->url was allocated from r->pool */ | 1459 /* ctx->url was allocated from r->pool */ |
1453 ctx = (ngx_http_log_ctx_t *) r->connection->log->data; | 1460 ctx = (ngx_http_log_ctx_t *) r->connection->log->data; |
1454 ctx->url = NULL; | 1461 ctx->url = NULL; |
1455 | 1462 |
1456 ngx_destroy_pool(r->pool); | 1463 ngx_destroy_pool(r->pool); |
1464 | |
1465 r->closed = 1; | |
1466 | |
1467 return; | |
1457 } | 1468 } |
1458 | 1469 |
1459 | 1470 |
1460 void ngx_http_close_connection(ngx_connection_t *c) | 1471 void ngx_http_close_connection(ngx_connection_t *c) |
1461 { | 1472 { |
1495 } | 1506 } |
1496 | 1507 |
1497 c->fd = -1; | 1508 c->fd = -1; |
1498 | 1509 |
1499 ngx_destroy_pool(c->pool); | 1510 ngx_destroy_pool(c->pool); |
1511 | |
1512 return; | |
1500 } | 1513 } |
1501 | 1514 |
1502 | 1515 |
1503 static void ngx_http_header_parse_error(ngx_http_request_t *r, int parse_err) | 1516 static void ngx_http_header_parse_error(ngx_http_request_t *r, int parse_err) |
1504 { | 1517 { |