Mercurial > hg > nginx-ranges
comparison src/mail/ngx_mail.c @ 495:6484cbba0222 NGINX_0_7_55
nginx 0.7.55
*) Bugfix: the http_XXX parameters in "proxy_cache_use_stale" and
"fastcgi_cache_use_stale" directives did not work.
*) Bugfix: fastcgi cache did not cache header only responses.
*) Bugfix: of "select() failed (9: Bad file descriptor)" error in
nginx/Unix and "select() failed (10022: ...)" error in nginx/Windows.
*) Bugfix: a segmentation fault might occur in worker process, if an
"debug_connection" directive was used; the bug had appeared in
0.7.54.
*) Bugfix: fix ngx_http_image_filter_module building errors.
*) Bugfix: the files bigger than 2G could not be transferred using
$r->sendfile.
Thanks to Maxim Dounin.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 06 May 2009 00:00:00 +0400 |
parents | ed5e10fb40fc |
children | 98143f74eb3d |
comparison
equal
deleted
inserted
replaced
494:21824e8058e6 | 495:6484cbba0222 |
---|---|
68 size_t len; | 68 size_t len; |
69 ngx_uint_t i, a, l, m, mi, s, p, last, bind_all, done; | 69 ngx_uint_t i, a, l, m, mi, s, p, last, bind_all, done; |
70 ngx_conf_t pcf; | 70 ngx_conf_t pcf; |
71 ngx_array_t in_ports; | 71 ngx_array_t in_ports; |
72 ngx_listening_t *ls; | 72 ngx_listening_t *ls; |
73 ngx_mail_listen_t *imls; | 73 ngx_mail_listen_t *mls; |
74 ngx_mail_module_t *module; | 74 ngx_mail_module_t *module; |
75 ngx_mail_in_port_t *imip; | 75 struct sockaddr_in sin; |
76 ngx_mail_in_port_t *mip; | |
76 ngx_mail_conf_ctx_t *ctx; | 77 ngx_mail_conf_ctx_t *ctx; |
77 ngx_mail_conf_in_port_t *in_port; | 78 ngx_mail_conf_in_port_t *in_port; |
78 ngx_mail_conf_in_addr_t *in_addr; | 79 ngx_mail_conf_in_addr_t *in_addr; |
79 ngx_mail_core_srv_conf_t **cscfp; | 80 ngx_mail_core_srv_conf_t **cscfp; |
80 ngx_mail_core_main_conf_t *cmcf; | 81 ngx_mail_core_main_conf_t *cmcf; |
221 != NGX_OK) | 222 != NGX_OK) |
222 { | 223 { |
223 return NGX_CONF_ERROR; | 224 return NGX_CONF_ERROR; |
224 } | 225 } |
225 | 226 |
226 imls = cmcf->listen.elts; | 227 mls = cmcf->listen.elts; |
227 | 228 |
228 for (l = 0; l < cmcf->listen.nelts; l++) { | 229 for (l = 0; l < cmcf->listen.nelts; l++) { |
229 | 230 |
230 /* AF_INET only */ | 231 /* AF_INET only */ |
231 | 232 |
232 in_port = in_ports.elts; | 233 in_port = in_ports.elts; |
233 for (p = 0; p < in_ports.nelts; p++) { | 234 for (p = 0; p < in_ports.nelts; p++) { |
234 if (in_port[p].port == imls[l].port) { | 235 if (in_port[p].port == mls[l].port) { |
235 in_port = &in_port[p]; | 236 in_port = &in_port[p]; |
236 goto found; | 237 goto found; |
237 } | 238 } |
238 } | 239 } |
239 | 240 |
240 in_port = ngx_array_push(&in_ports); | 241 in_port = ngx_array_push(&in_ports); |
241 if (in_port == NULL) { | 242 if (in_port == NULL) { |
242 return NGX_CONF_ERROR; | 243 return NGX_CONF_ERROR; |
243 } | 244 } |
244 | 245 |
245 in_port->port = imls[l].port; | 246 in_port->port = mls[l].port; |
246 | 247 |
247 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 2, | 248 if (ngx_array_init(&in_port->addrs, cf->temp_pool, 2, |
248 sizeof(ngx_mail_conf_in_addr_t)) | 249 sizeof(ngx_mail_conf_in_addr_t)) |
249 != NGX_OK) | 250 != NGX_OK) |
250 { | 251 { |
256 in_addr = ngx_array_push(&in_port->addrs); | 257 in_addr = ngx_array_push(&in_port->addrs); |
257 if (in_addr == NULL) { | 258 if (in_addr == NULL) { |
258 return NGX_CONF_ERROR; | 259 return NGX_CONF_ERROR; |
259 } | 260 } |
260 | 261 |
261 in_addr->addr = imls[l].addr; | 262 in_addr->addr = mls[l].addr; |
262 in_addr->ctx = imls[l].ctx; | 263 in_addr->ctx = mls[l].ctx; |
263 in_addr->bind = imls[l].bind; | 264 in_addr->bind = mls[l].bind; |
264 #if (NGX_MAIL_SSL) | 265 #if (NGX_MAIL_SSL) |
265 in_addr->ssl = imls[l].ssl; | 266 in_addr->ssl = mls[l].ssl; |
266 #endif | 267 #endif |
267 } | 268 } |
268 | 269 |
269 /* optimize the lists of ports and addresses */ | 270 /* optimize the lists of ports and addresses */ |
270 | 271 |
297 if (!bind_all && !in_addr[a].bind) { | 298 if (!bind_all && !in_addr[a].bind) { |
298 a++; | 299 a++; |
299 continue; | 300 continue; |
300 } | 301 } |
301 | 302 |
302 ls = ngx_listening_inet_stream_socket(cf, in_addr[a].addr, | 303 ngx_memzero(&sin, sizeof(struct sockaddr_in)); |
303 in_port[p].port); | 304 |
305 sin.sin_family = AF_INET; | |
306 sin.sin_addr.s_addr = in_addr[a].addr; | |
307 sin.sin_port = htons(in_port[p].port); | |
308 | |
309 ls = ngx_create_listening(cf, &sin, sizeof(struct sockaddr_in)); | |
304 if (ls == NULL) { | 310 if (ls == NULL) { |
305 return NGX_CONF_ERROR; | 311 return NULL; |
306 } | 312 } |
307 | |
308 ls->backlog = NGX_LISTEN_BACKLOG; | |
309 ls->rcvbuf = -1; | |
310 ls->sndbuf = -1; | |
311 | 313 |
312 ls->addr_ntop = 1; | 314 ls->addr_ntop = 1; |
313 ls->handler = ngx_mail_init_connection; | 315 ls->handler = ngx_mail_init_connection; |
314 ls->pool_size = 256; | 316 ls->pool_size = 256; |
315 | 317 |
316 /* TODO: error_log directive */ | 318 /* TODO: error_log directive */ |
317 ls->logp = &cf->cycle->new_log; | 319 ls->logp = &cf->cycle->new_log; |
318 ls->log.data = &ls->addr_text; | 320 ls->log.data = &ls->addr_text; |
319 ls->log.handler = ngx_accept_log_error; | 321 ls->log.handler = ngx_accept_log_error; |
320 | 322 |
321 imip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t)); | 323 mip = ngx_palloc(cf->pool, sizeof(ngx_mail_in_port_t)); |
322 if (imip == NULL) { | 324 if (mip == NULL) { |
323 return NGX_CONF_ERROR; | 325 return NGX_CONF_ERROR; |
324 } | 326 } |
325 | 327 |
326 ls->servers = imip; | 328 ls->servers = mip; |
327 | 329 |
328 in_addr = in_port[p].addrs.elts; | 330 in_addr = in_port[p].addrs.elts; |
329 | 331 |
330 if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) { | 332 if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) { |
331 imip->naddrs = 1; | 333 mip->naddrs = 1; |
332 done = 0; | 334 done = 0; |
333 | 335 |
334 } else if (in_port[p].addrs.nelts > 1 | 336 } else if (in_port[p].addrs.nelts > 1 |
335 && in_addr[last - 1].addr == INADDR_ANY) | 337 && in_addr[last - 1].addr == INADDR_ANY) |
336 { | 338 { |
337 imip->naddrs = last; | 339 mip->naddrs = last; |
338 done = 1; | 340 done = 1; |
339 | 341 |
340 } else { | 342 } else { |
341 imip->naddrs = 1; | 343 mip->naddrs = 1; |
342 done = 0; | 344 done = 0; |
343 } | 345 } |
344 | 346 |
345 #if 0 | 347 #if 0 |
346 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, | 348 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, |
347 "%ui: %V %d %ui %ui", | 349 "%ui: %V %d %ui %ui", |
348 a, &ls->addr_text, in_addr[a].bind, | 350 a, &ls->addr_text, in_addr[a].bind, |
349 imip->naddrs, last); | 351 mip->naddrs, last); |
350 #endif | 352 #endif |
351 | 353 |
352 imip->addrs = ngx_pcalloc(cf->pool, | 354 mip->addrs = ngx_pcalloc(cf->pool, |
353 imip->naddrs * sizeof(ngx_mail_in_addr_t)); | 355 mip->naddrs * sizeof(ngx_mail_in_addr_t)); |
354 if (imip->addrs == NULL) { | 356 if (mip->addrs == NULL) { |
355 return NGX_CONF_ERROR; | 357 return NGX_CONF_ERROR; |
356 } | 358 } |
357 | 359 |
358 for (i = 0; i < imip->naddrs; i++) { | 360 for (i = 0; i < mip->naddrs; i++) { |
359 imip->addrs[i].addr = in_addr[i].addr; | 361 mip->addrs[i].addr = in_addr[i].addr; |
360 imip->addrs[i].ctx = in_addr[i].ctx; | 362 mip->addrs[i].ctx = in_addr[i].ctx; |
361 | 363 |
362 text = ngx_pnalloc(cf->pool, | 364 text = ngx_pnalloc(cf->pool, |
363 NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1); | 365 NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1); |
364 if (text == NULL) { | 366 if (text == NULL) { |
365 return NGX_CONF_ERROR; | 367 return NGX_CONF_ERROR; |
368 len = ngx_inet_ntop(AF_INET, &in_addr[i].addr, text, | 370 len = ngx_inet_ntop(AF_INET, &in_addr[i].addr, text, |
369 NGX_INET_ADDRSTRLEN); | 371 NGX_INET_ADDRSTRLEN); |
370 | 372 |
371 len = ngx_sprintf(text + len, ":%d", in_port[p].port) - text; | 373 len = ngx_sprintf(text + len, ":%d", in_port[p].port) - text; |
372 | 374 |
373 imip->addrs[i].addr_text.len = len; | 375 mip->addrs[i].addr_text.len = len; |
374 imip->addrs[i].addr_text.data = text; | 376 mip->addrs[i].addr_text.data = text; |
375 | 377 |
376 #if (NGX_MAIL_SSL) | 378 #if (NGX_MAIL_SSL) |
377 imip->addrs[i].ssl = in_addr[i].ssl; | 379 mip->addrs[i].ssl = in_addr[i].ssl; |
378 #endif | 380 #endif |
379 } | 381 } |
380 | 382 |
381 if (done) { | 383 if (done) { |
382 break; | 384 break; |