[PATCH] Core: configurable listening try number
Han Cheng
hc0606 at gmail.com
Mon Apr 7 08:34:52 UTC 2014
Hello, there,
I'm a new guy to nginx.
Recently, I'm reading the source code. I found some TODOs. I'm trying to
implement some. This is my first small attempt.
Any suggestion?
Thank you!
Regards,
Cheng
# HG changeset patch
# User Han Cheng <hc0606 at gmail.com>
# Date 1396856176 -28800
# Mon Apr 07 15:36:16 2014 +0800
# Node ID de04aae10531d3bae43804231ed3566ececec481
# Parent 0c0dd1aacdf55f3422cfa2edd4dfe85f4d0d8b34
Core: configurable listening try number
diff -r 0c0dd1aacdf5 -r de04aae10531 src/core/nginx.c
--- a/src/core/nginx.c Tue Apr 01 20:53:18 2014 +0400
+++ b/src/core/nginx.c Mon Apr 07 15:36:16 2014 +0800
@@ -23,6 +23,8 @@
void *conf);
static char *ngx_set_worker_processes(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
+static char *ngx_set_listening_tries(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
static ngx_conf_enum_t ngx_debug_points[] = {
@@ -83,6 +85,13 @@
offsetof(ngx_core_conf_t, debug_points),
&ngx_debug_points },
+ { ngx_string("listening_tries"),
+ NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
+ ngx_set_listening_tries,
+ 0,
+ 0,
+ NULL },
+
{ ngx_string("user"),
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE12,
ngx_set_user,
@@ -952,6 +961,8 @@
ccf->worker_processes = NGX_CONF_UNSET;
ccf->debug_points = NGX_CONF_UNSET;
+ ccf->listening_tries = NGX_CONF_UNSET;
+
ccf->rlimit_nofile = NGX_CONF_UNSET;
ccf->rlimit_core = NGX_CONF_UNSET;
ccf->rlimit_sigpending = NGX_CONF_UNSET;
@@ -986,6 +997,8 @@
ngx_conf_init_value(ccf->worker_processes, 1);
ngx_conf_init_value(ccf->debug_points, 0);
+ ngx_conf_init_value(ccf->listening_tries, 5);
+
#if (NGX_HAVE_CPU_AFFINITY)
if (ccf->cpu_affinity_n
@@ -1361,3 +1374,29 @@
return NGX_CONF_OK;
}
+
+
+static char *
+ngx_set_listening_tries(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_str_t *value;
+ ngx_core_conf_t *ccf;
+
+ ccf = (ngx_core_conf_t *) conf;
+
+ if (ccf->listening_tries != NGX_CONF_UNSET) {
+ return "is duplicate";
+ }
+
+ value = (ngx_str_t *) cf->args->elts;
+
+ ccf->listening_tries = ngx_atoi(value[1].data, value[1].len);
+
+ if (ccf->listening_tries == NGX_ERROR) {
+ return "invalid value";
+ } else if (ccf->listening_tries > 1024) {
+ return "too much tries";
+ }
+
+ return NGX_CONF_OK;
+}
diff -r 0c0dd1aacdf5 -r de04aae10531 src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Tue Apr 01 20:53:18 2014 +0400
+++ b/src/core/ngx_connection.c Mon Apr 07 15:36:16 2014 +0800
@@ -305,11 +305,13 @@
ngx_open_listening_sockets(ngx_cycle_t *cycle)
{
int reuseaddr;
- ngx_uint_t i, tries, failed;
+ ngx_uint_t i, failed;
+ ngx_int_t tries;
ngx_err_t err;
ngx_log_t *log;
ngx_socket_t s;
ngx_listening_t *ls;
+ ngx_core_conf_t *ccf;
reuseaddr = 1;
#if (NGX_SUPPRESS_WARN)
@@ -318,9 +320,9 @@
log = cycle->log;
- /* TODO: configurable try number */
+ ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
- for (tries = 5; tries; tries--) {
+ for (tries = ccf->listening_tries; tries; tries--) {
failed = 0;
/* for each listening socket */
diff -r 0c0dd1aacdf5 -r de04aae10531 src/core/ngx_cycle.h
--- a/src/core/ngx_cycle.h Tue Apr 01 20:53:18 2014 +0400
+++ b/src/core/ngx_cycle.h Mon Apr 07 15:36:16 2014 +0800
@@ -81,6 +81,8 @@
ngx_int_t worker_processes;
ngx_int_t debug_points;
+ ngx_int_t listening_tries;
+
ngx_int_t rlimit_nofile;
ngx_int_t rlimit_sigpending;
off_t rlimit_core;
More information about the nginx-devel
mailing list