Klaus Demo nginx / 751bdd3
Events: moved sockets cloning to ngx_event_init_conf(). Previously, listenings sockets were not cloned if the worker_processes directive was specified after "listen ... reuseport". This also simplifies upcoming configuration check on the number of worker connections, as it needs to know the number of listening sockets before cloning. Maxim Dounin 3 years ago
5 changed file(s) with 30 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
9595
9696
9797 ngx_int_t
98 ngx_clone_listening(ngx_conf_t *cf, ngx_listening_t *ls)
98 ngx_clone_listening(ngx_cycle_t *cycle, ngx_listening_t *ls)
9999 {
100100 #if (NGX_HAVE_REUSEPORT)
101101
103103 ngx_core_conf_t *ccf;
104104 ngx_listening_t ols;
105105
106 if (!ls->reuseport) {
106 if (!ls->reuseport || ls->worker != 0) {
107107 return NGX_OK;
108108 }
109109
110110 ols = *ls;
111111
112 ccf = (ngx_core_conf_t *) ngx_get_conf(cf->cycle->conf_ctx,
113 ngx_core_module);
112 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
114113
115114 for (n = 1; n < ccf->worker_processes; n++) {
116115
117116 /* create a socket for each worker process */
118117
119 ls = ngx_array_push(&cf->cycle->listening);
118 ls = ngx_array_push(&cycle->listening);
120119 if (ls == NULL) {
121120 return NGX_ERROR;
122121 }
209209
210210 ngx_listening_t *ngx_create_listening(ngx_conf_t *cf, struct sockaddr *sockaddr,
211211 socklen_t socklen);
212 ngx_int_t ngx_clone_listening(ngx_conf_t *cf, ngx_listening_t *ls);
212 ngx_int_t ngx_clone_listening(ngx_cycle_t *cycle, ngx_listening_t *ls);
213213 ngx_int_t ngx_set_inherited_sockets(ngx_cycle_t *cycle);
214214 ngx_int_t ngx_open_listening_sockets(ngx_cycle_t *cycle);
215215 void ngx_configure_listening_sockets(ngx_cycle_t *cycle);
409409 static char *
410410 ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
411411 {
412 #if (NGX_HAVE_REUSEPORT)
413 ngx_uint_t i;
414 ngx_listening_t *ls;
415 #endif
416
412417 if (ngx_get_conf(cycle->conf_ctx, ngx_events_module) == NULL) {
413418 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
414419 "no \"events\" section in configuration");
415420 return NGX_CONF_ERROR;
416421 }
422
423 #if (NGX_HAVE_REUSEPORT)
424
425 ls = cycle->listening.elts;
426 for (i = 0; i < cycle->listening.nelts; i++) {
427
428 if (!ls[i].reuseport || ls[i].worker != 0) {
429 continue;
430 }
431
432 if (ngx_clone_listening(cycle, &ls[i]) != NGX_OK) {
433 return NGX_CONF_ERROR;
434 }
435
436 /* cloning may change cycle->listening.elts */
437
438 ls = cycle->listening.elts;
439 }
440
441 #endif
417442
418443 return NGX_CONF_OK;
419444 }
16841684 break;
16851685 }
16861686
1687 if (ngx_clone_listening(cf, ls) != NGX_OK) {
1688 return NGX_ERROR;
1689 }
1690
16911687 addr++;
16921688 last--;
16931689 }
537537 break;
538538 }
539539
540 if (ngx_clone_listening(cf, ls) != NGX_OK) {
541 return NGX_CONF_ERROR;
542 }
543
544540 addr++;
545541 last--;
546542 }