comparison src/http/ngx_http_event.c @ 1:d220029ac7f3

nginx-0.0.1-2002-08-15-21:20:26 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 15 Aug 2002 17:20:26 +0000
parents 4eff17414a43
children ffffe1499bce
comparison
equal deleted inserted replaced
0:4eff17414a43 1:d220029ac7f3
36 int ngx_http_init_connection(ngx_connection_t *c) 36 int ngx_http_init_connection(ngx_connection_t *c)
37 { 37 {
38 ngx_event_t *ev; 38 ngx_event_t *ev;
39 39
40 ev = c->read; 40 ev = c->read;
41 /*
42 ev->event_handler = ngx_http_init_request; 41 ev->event_handler = ngx_http_init_request;
43 */
44 ev->event_handler = NULL;
45 ev->log->action = "reading client request line"; 42 ev->log->action = "reading client request line";
46 43
47 ngx_log_debug(ev->log, "ngx_http_init_connection: entered"); 44 ngx_log_debug(ev->log, "ngx_http_init_connection: entered");
48 45
49 /* XXX: ev->timer ? */ 46 /* XXX: ev->timer ? */
60 #else 57 #else
61 return ngx_add_event(ev, NGX_READ_EVENT, NGX_ONESHOT_EVENT); 58 return ngx_add_event(ev, NGX_READ_EVENT, NGX_ONESHOT_EVENT);
62 #endif 59 #endif
63 } 60 }
64 61
65 #if 0
66
67 int ngx_http_init_request(ngx_event_t *ev) 62 int ngx_http_init_request(ngx_event_t *ev)
68 { 63 {
69 ngx_connection_t *c = (ngx_connection_t *) ev->data; 64 ngx_connection_t *c = (ngx_connection_t *) ev->data;
70 ngx_http_request_t *r; 65 ngx_http_request_t *r;
71 66
72 ngx_log_debug(ev->log, "ngx_http_init_request: entered"); 67 ngx_log_debug(ev->log, "ngx_http_init_request: entered");
73 68
69 ngx_test_null(c->pool, ngx_create_pool(16384, ev->log), -1);
74 ngx_test_null(r, ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)), -1); 70 ngx_test_null(r, ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)), -1);
75 71
76 c->data = r; 72 c->data = r;
77 r->connection = c; 73 r->connection = c;
78 74
75 ngx_test_null(r->pool, ngx_create_pool(16384, ev->log), -1);
79 ngx_test_null(r->buff, ngx_palloc(r->pool, sizeof(ngx_buff_t)), -1); 76 ngx_test_null(r->buff, ngx_palloc(r->pool, sizeof(ngx_buff_t)), -1);
80 ngx_test_null(r->buff->buff, 77 ngx_test_null(r->buff->buff,
81 ngx_pcalloc(r->pool, sizeof(c->server->buff_size)), -1); 78 ngx_pcalloc(r->pool, sizeof(c->server->buff_size)), -1);
82 79
83 r->buff->pos = r->buff->last = r->buff->buff; 80 r->buff->pos = r->buff->last = r->buff->buff;
97 ngx_connection_t *c = (ngx_connection_t *) ev->data; 94 ngx_connection_t *c = (ngx_connection_t *) ev->data;
98 ngx_http_request_t *r = (ngx_http_request_t *) c->data; 95 ngx_http_request_t *r = (ngx_http_request_t *) c->data;
99 96
100 ngx_log_debug(ev->log, "http process request"); 97 ngx_log_debug(ev->log, "http process request");
101 98
102 ngx_log_debug(ev->log, "http: eof:%d, avail:%d", ev->eof, ev->available); 99 n = ngx_event_recv(ev, r->buff->last, r->buff->end - r->buff->last);
103 100
104 if (ev->eof && ev->available == 0) { 101 if (n == -2)
105 if (ev->err_no) 102 return 0;
106 ngx_log_error(NGX_LOG_ERR, ev->log, ev->err_no, 103
107 "ngx_http_process_request: " 104 if (n == -1)
108 "read failed while %s", ev->action); 105 return -1;
109 106
110 return -1; 107 ngx_log_debug(ev->log, "http read %d" _ n);
111 }
112
113 if ((n = read(c->fd, r->buff->last, r->buff->end - r->buff->last)) == -1) {
114
115 if (errno == NGX_EWOULDBLOCK) {
116 ngx_log_error(NGX_LOG_INFO, ev->log, errno,
117 "ngx_http_process_request: "
118 "EAGAIN while %s", ev->action);
119 return 0;
120 }
121
122 ngx_log_error(NGX_LOG_ERR, ev->log, errno,
123 "ngx_http_process_request: "
124 "read failed while %s", ev->action);
125 return -1;
126 }
127
128 ngx_log_debug(ev->log, "http read %d", n);
129 108
130 if (n == 0) { 109 if (n == 0) {
131 if (ev->unexpected_eof) { 110 if (ev->unexpected_eof) {
132 ngx_log_error(NGX_LOG_INFO, ev->log, 0, 111 ngx_log_error(NGX_LOG_INFO, ev->log, 0,
133 "ngx_http_process_request: " 112 "ngx_http_process_request: "
136 } 115 }
137 116
138 return ngx_http_close_request(ev); 117 return ngx_http_close_request(ev);
139 } 118 }
140 119
141 n == r->buff->end - r->buff->last;
142
143 if (!ev->read_discarded) { 120 if (!ev->read_discarded) {
144 r->buff->last += n; 121 r->buff->last += n;
145 122
146 /* state_handlers are called in following order: 123 /* state_handlers are called in following order:
147 ngx_process_http_request_line() 124 ngx_process_http_request_line()
166 { 143 {
167 int n; 144 int n;
168 145
169 if ((n = ngx_read_http_request_line(r)) == 1) { 146 if ((n = ngx_read_http_request_line(r)) == 1) {
170 *r->uri_end = '\0'; 147 *r->uri_end = '\0';
171 ngx_log_debug(r->connection->log, "HTTP: %d, %d, %s", 148 ngx_log_debug(r->connection->log, "HTTP: %d, %d, %s" _
172 r->method, r->http_version, r->uri_start); 149 r->method _ r->http_version _ r->uri_start);
173 r->state_handler = ngx_process_http_request_header; 150 r->state_handler = ngx_process_http_request_header;
174 r->connection->read->action = "reading client request headers"; 151 r->connection->read->action = "reading client request headers";
175 } 152 }
176 153
177 return n; 154 return n;
182 int n; 159 int n;
183 160
184 while ((n = ngx_read_http_header_line(r)) == 1) { 161 while ((n = ngx_read_http_header_line(r)) == 1) {
185 *r->header_name_end = '\0'; 162 *r->header_name_end = '\0';
186 *r->header_end = '\0'; 163 *r->header_end = '\0';
187 ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'", 164 ngx_log_debug(r->connection->log, "HTTP header: '%s: %s'" _
188 r->header_name_start, r->header_start); 165 r->header_name_start _ r->header_start);
189 } 166 }
190 167
191 if (n != 2) 168 if (n != 2)
192 return n; 169 return n;
193 170
198 r->connection->read->unexpected_eof = 0; 175 r->connection->read->unexpected_eof = 0;
199 ngx_log_debug(r->connection->log, "HTTP header done"); 176 ngx_log_debug(r->connection->log, "HTTP header done");
200 177
201 return ngx_process_http_request(r); 178 return ngx_process_http_request(r);
202 } 179 }
180
181 static int ngx_process_http_request(ngx_http_request_t *r)
182 {
183 return -1;
184 }
185
186 #if 0
203 187
204 static int ngx_process_http_request(ngx_http_request_t *r) 188 static int ngx_process_http_request(ngx_http_request_t *r)
205 { 189 {
206 int fd; 190 int fd;
207 struct stat sb; 191 struct stat sb;
256 ngx_event_write(r->connection, header); 240 ngx_event_write(r->connection, header);
257 241
258 return 0; 242 return 0;
259 } 243 }
260 244
245 #endif
246
261 static int ngx_http_close_request(ngx_event_t *ev) 247 static int ngx_http_close_request(ngx_event_t *ev)
262 { 248 {
263 ngx_connection_t *c = (ngx_connection_t *) ev->data; 249 ngx_connection_t *c = (ngx_connection_t *) ev->data;
264 250
265 ngx_log_debug(ev->log, "http close"); 251 ngx_log_debug(ev->log, "http close");
267 ngx_del_event(c->read, NGX_TIMER_EVENT); 253 ngx_del_event(c->read, NGX_TIMER_EVENT);
268 ngx_del_event(c->write, NGX_TIMER_EVENT); 254 ngx_del_event(c->write, NGX_TIMER_EVENT);
269 255
270 return ngx_event_close(ev); 256 return ngx_event_close(ev);
271 } 257 }
272
273 #endif