Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 1805:bb72f7518992
use ngx_http_server_addr()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 29 Dec 2007 16:00:34 +0000 |
parents | d457a1576532 |
children | 755e09d5c271 |
comparison
equal
deleted
inserted
replaced
1804:d457a1576532 | 1805:bb72f7518992 |
---|---|
218 | 218 |
219 static void | 219 static void |
220 ngx_http_init_request(ngx_event_t *rev) | 220 ngx_http_init_request(ngx_event_t *rev) |
221 { | 221 { |
222 ngx_time_t *tp; | 222 ngx_time_t *tp; |
223 socklen_t len; | |
224 ngx_uint_t i; | 223 ngx_uint_t i; |
225 struct sockaddr_in sin; | |
226 ngx_connection_t *c; | 224 ngx_connection_t *c; |
227 ngx_http_request_t *r; | 225 ngx_http_request_t *r; |
228 ngx_http_in_port_t *hip; | 226 ngx_http_in_port_t *hip; |
229 ngx_http_in_addr_t *hia; | 227 ngx_http_in_addr_t *hia; |
230 ngx_http_log_ctx_t *ctx; | 228 ngx_http_log_ctx_t *ctx; |
293 r->port = hip->port; | 291 r->port = hip->port; |
294 r->port_text = &hip->port_text; | 292 r->port_text = &hip->port_text; |
295 | 293 |
296 i = 0; | 294 i = 0; |
297 | 295 |
296 r->connection = c; | |
297 | |
298 if (hip->naddrs > 1) { | 298 if (hip->naddrs > 1) { |
299 | 299 |
300 /* | 300 /* |
301 * There are several addresses on this port and one of them | 301 * There are several addresses on this port and one of them |
302 * is the "*:port" wildcard so getsockname() is needed to determine | 302 * is the "*:port" wildcard so getsockname() is needed to determine |
303 * the server address. | 303 * the server address. |
304 * | 304 * |
305 * AcceptEx() already gave this address. | 305 * AcceptEx() already has given this address. |
306 */ | 306 */ |
307 | 307 |
308 #if (NGX_WIN32) | 308 #if (NGX_WIN32) |
309 if (c->local_sockaddr) { | 309 if (c->local_sockaddr) { |
310 r->in_addr = | 310 r->in_addr = |
311 ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; | 311 ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; |
312 | 312 |
313 } else | 313 } else |
314 #endif | 314 #endif |
315 { | 315 { |
316 len = sizeof(struct sockaddr_in); | 316 if (ngx_http_server_addr(r, NULL) != NGX_OK) { |
317 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) { | |
318 ngx_connection_error(c, ngx_socket_errno, | |
319 "getsockname() failed"); | |
320 ngx_http_close_connection(c); | 317 ngx_http_close_connection(c); |
321 return; | 318 return; |
322 } | 319 } |
323 | |
324 r->in_addr = sin.sin_addr.s_addr; | |
325 } | 320 } |
326 | 321 |
327 /* the last address is "*" */ | 322 /* the last address is "*" */ |
328 | 323 |
329 for ( /* void */ ; i < hip->naddrs - 1; i++) { | 324 for ( /* void */ ; i < hip->naddrs - 1; i++) { |
423 return; | 418 return; |
424 } | 419 } |
425 | 420 |
426 c->single_connection = 1; | 421 c->single_connection = 1; |
427 c->destroyed = 0; | 422 c->destroyed = 0; |
428 | |
429 r->connection = c; | |
430 | 423 |
431 r->main = r; | 424 r->main = r; |
432 | 425 |
433 tp = ngx_timeofday(); | 426 tp = ngx_timeofday(); |
434 r->start_sec = tp->sec; | 427 r->start_sec = tp->sec; |