changeset 3220:cdcd9e29c589

*) move sockaddr to the listen options *) rename ngx_http_listen_t to ngx_http_listen_opt_t
author Igor Sysoev <igor@sysoev.ru>
date Wed, 21 Oct 2009 16:47:44 +0000
parents 81b8416054b0
children c8de5a8b6d17
files src/http/ngx_http.c src/http/ngx_http.h src/http/ngx_http_core_module.c src/http/ngx_http_core_module.h
diffstat 4 files changed, 77 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -19,10 +19,10 @@ static ngx_int_t ngx_http_init_phase_han
 
 static ngx_int_t ngx_http_add_addresses(ngx_conf_t *cf,
     ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
-    ngx_http_listen_t *listen);
+    ngx_http_listen_opt_t *lsopt);
 static ngx_int_t ngx_http_add_address(ngx_conf_t *cf,
     ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
-    ngx_http_listen_t *listen);
+    ngx_http_listen_opt_t *lsopt);
 static ngx_int_t ngx_http_add_server(ngx_conf_t *cf,
     ngx_http_core_srv_conf_t *cscf, ngx_http_conf_addr_t *addr);
 
@@ -1095,7 +1095,7 @@ inclusive:
 
 ngx_int_t
 ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
-    ngx_http_listen_t *listen)
+    ngx_http_listen_opt_t *lsopt)
 {
     in_port_t                   p;
     ngx_uint_t                  i;
@@ -1117,7 +1117,7 @@ ngx_http_add_listen(ngx_conf_t *cf, ngx_
         }
     }
 
-    sa = (struct sockaddr *) &listen->sockaddr;
+    sa = (struct sockaddr *) &lsopt->sockaddr;
 
     switch (sa->sa_family) {
 
@@ -1143,7 +1143,7 @@ ngx_http_add_listen(ngx_conf_t *cf, ngx_
 
         /* a port is already in the port list */
 
-        return ngx_http_add_addresses(cf, cscf, &port[i], listen);
+        return ngx_http_add_addresses(cf, cscf, &port[i], lsopt);
     }
 
     /* add a port to the port list */
@@ -1157,13 +1157,13 @@ ngx_http_add_listen(ngx_conf_t *cf, ngx_
     port->port = p;
     port->addrs.elts = NULL;
 
-    return ngx_http_add_address(cf, cscf, port, listen);
+    return ngx_http_add_address(cf, cscf, port, lsopt);
 }
 
 
 static ngx_int_t
 ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
-    ngx_http_conf_port_t *port, ngx_http_listen_t *listen)
+    ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
 {
     u_char                *p;
     size_t                 len, off;
@@ -1176,7 +1176,7 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
      * may fill some fields in inherited sockaddr struct's
      */
 
-    sa = (struct sockaddr *) &listen->sockaddr;
+    sa = (struct sockaddr *) &lsopt->sockaddr;
 
     switch (sa->sa_family) {
 
@@ -1193,13 +1193,13 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
         break;
     }
 
-    p = listen->sockaddr + off;
+    p = lsopt->sockaddr + off;
 
     addr = port->addrs.elts;
 
     for (i = 0; i < port->addrs.nelts; i++) {
 
-        if (ngx_memcmp(p, (u_char *) addr[i].sockaddr + off, len) != 0) {
+        if (ngx_memcmp(p, (u_char *) addr[i].opt.sockaddr + off, len) != 0) {
             continue;
         }
 
@@ -1211,7 +1211,7 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
 
         /* check the duplicate "default" server for this address:port */
 
-        if (listen->opt.default_server) {
+        if (lsopt->default_server) {
 
             if (addr[i].opt.default_server) {
                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
@@ -1219,8 +1219,8 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
                 return NGX_ERROR;
             }
 
+            addr[i].opt = *lsopt;
             addr[i].core_srv_conf = cscf;
-            addr[i].opt = listen->opt;
         }
 
         return NGX_OK;
@@ -1228,7 +1228,7 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
 
     /* add the address to the addresses list that bound to this port */
 
-    return ngx_http_add_address(cf, cscf, port, listen);
+    return ngx_http_add_address(cf, cscf, port, lsopt);
 }
 
 
@@ -1239,7 +1239,7 @@ ngx_http_add_addresses(ngx_conf_t *cf, n
 
 static ngx_int_t
 ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
-    ngx_http_conf_port_t *port, ngx_http_listen_t *listen)
+    ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
 {
     ngx_http_conf_addr_t  *addr;
 
@@ -1257,8 +1257,7 @@ ngx_http_add_address(ngx_conf_t *cf, ngx
         return NGX_ERROR;
     }
 
-    ngx_memcpy(addr->sockaddr, listen->sockaddr, listen->socklen);
-    addr->socklen = listen->socklen;
+    addr->opt = *lsopt;
     addr->hash.buckets = NULL;
     addr->hash.size = 0;
     addr->wc_head = NULL;
@@ -1269,7 +1268,6 @@ ngx_http_add_address(ngx_conf_t *cf, ngx
 #endif
     addr->core_srv_conf = cscf;
     addr->servers.elts = NULL;
-    addr->opt = listen->opt;
 
     return ngx_http_add_server(cf, cscf, addr);
 }
@@ -1629,7 +1627,7 @@ ngx_http_add_listening(ngx_conf_t *cf, n
     ngx_http_core_loc_conf_t  *clcf;
     ngx_http_core_srv_conf_t  *cscf;
 
-    ls = ngx_create_listening(cf, addr->sockaddr, addr->socklen);
+    ls = ngx_create_listening(cf, addr->opt.sockaddr, addr->opt.socklen);
     if (ls == NULL) {
         return NULL;
     }
@@ -1698,7 +1696,7 @@ ngx_http_add_addrs(ngx_conf_t *cf, ngx_h
 
     for (i = 0; i < hport->naddrs; i++) {
 
-        sin = (struct sockaddr_in *) addr[i].sockaddr;
+        sin = (struct sockaddr_in *) addr[i].opt.sockaddr;
         addrs[i].addr = sin->sin_addr.s_addr;
         addrs[i].conf.core_srv_conf = addr[i].core_srv_conf;
 #if (NGX_HTTP_SSL)
@@ -1759,7 +1757,7 @@ ngx_http_add_addrs6(ngx_conf_t *cf, ngx_
 
     for (i = 0; i < hport->naddrs; i++) {
 
-        sin6 = (struct sockaddr_in6 *) addr[i].sockaddr;
+        sin6 = (struct sockaddr_in6 *) addr[i].opt.sockaddr;
         addrs6[i].addr6 = sin6->sin6_addr;
         addrs6[i].conf.core_srv_conf = addr[i].core_srv_conf;
 #if (NGX_HTTP_SSL)
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -58,7 +58,7 @@ struct ngx_http_log_ctx_s {
 ngx_int_t ngx_http_add_location(ngx_conf_t *cf, ngx_queue_t **locations,
     ngx_http_core_loc_conf_t *clcf);
 ngx_int_t ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
-    ngx_http_listen_t *listen);
+    ngx_http_listen_opt_t *lsopt);
 
 
 void ngx_http_init_connection(ngx_connection_t *c);
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -2832,16 +2832,16 @@ ngx_http_core_merge_srv_conf(ngx_conf_t 
     ngx_http_core_srv_conf_t *prev = parent;
     ngx_http_core_srv_conf_t *conf = child;
 
-    ngx_http_listen_t        ls;
     struct sockaddr_in      *sin;
+    ngx_http_listen_opt_t    lsopt;
     ngx_http_server_name_t  *sn;
 
     /* TODO: it does not merge, it inits only */
 
     if (!conf->listen) {
-        ngx_memzero(&ls, sizeof(ngx_http_listen_t));
-
-        sin = (struct sockaddr_in *) &ls.sockaddr;
+        ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
+
+        sin = (struct sockaddr_in *) &lsopt.sockaddr;
 
         sin->sin_family = AF_INET;
 #if (NGX_WIN32)
@@ -2851,17 +2851,17 @@ ngx_http_core_merge_srv_conf(ngx_conf_t 
 #endif
         sin->sin_addr.s_addr = INADDR_ANY;
 
-        ls.socklen = sizeof(struct sockaddr_in);
-
-        ls.opt.backlog = NGX_LISTEN_BACKLOG;
-        ls.opt.rcvbuf = -1;
-        ls.opt.sndbuf = -1;
-        ls.opt.wildcard = 1;
-
-        (void) ngx_sock_ntop((struct sockaddr *) &ls.sockaddr, ls.opt.addr,
+        lsopt.socklen = sizeof(struct sockaddr_in);
+
+        lsopt.backlog = NGX_LISTEN_BACKLOG;
+        lsopt.rcvbuf = -1;
+        lsopt.sndbuf = -1;
+        lsopt.wildcard = 1;
+
+        (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr,
                              NGX_SOCKADDR_STRLEN, 1);
 
-        if (ngx_http_add_listen(cf, conf, &ls) == NGX_OK) {
+        if (ngx_http_add_listen(cf, conf, &lsopt) == NGX_OK) {
             return NGX_CONF_OK;
         }
     }
@@ -3266,10 +3266,10 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
 {
     ngx_http_core_srv_conf_t *cscf = conf;
 
-    ngx_str_t          *value, size;
-    ngx_url_t           u;
-    ngx_uint_t          n;
-    ngx_http_listen_t   ls;
+    ngx_str_t              *value, size;
+    ngx_url_t               u;
+    ngx_uint_t              n;
+    ngx_http_listen_opt_t   lsopt;
 
     cscf->listen = 1;
 
@@ -3291,21 +3291,21 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
         return NGX_CONF_ERROR;
     }
 
-    ngx_memzero(&ls, sizeof(ngx_http_listen_t));
-
-    ngx_memcpy(ls.sockaddr, u.sockaddr, u.socklen);
-
-    ls.socklen = u.socklen;
-    ls.opt.backlog = NGX_LISTEN_BACKLOG;
-    ls.opt.rcvbuf = -1;
-    ls.opt.sndbuf = -1;
-    ls.opt.wildcard = u.wildcard;
-
-    (void) ngx_sock_ntop((struct sockaddr *) &ls.sockaddr, ls.opt.addr,
+    ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
+
+    ngx_memcpy(lsopt.sockaddr, u.sockaddr, u.socklen);
+
+    lsopt.socklen = u.socklen;
+    lsopt.backlog = NGX_LISTEN_BACKLOG;
+    lsopt.rcvbuf = -1;
+    lsopt.sndbuf = -1;
+    lsopt.wildcard = u.wildcard;
+
+    (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr,
                          NGX_SOCKADDR_STRLEN, 1);
 
     if (cf->args->nelts > 2 && ngx_strcmp(value[2].data, "default") == 0) {
-        ls.opt.default_server = 1;
+        lsopt.default_server = 1;
         n = 3;
 
     } else {
@@ -3314,7 +3314,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
 
     for ( /* void */ ; n < cf->args->nelts; n++) {
 
-        if (ls.opt.default_server == 0) {
+        if (lsopt.default_server == 0) {
             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                "\"%V\" parameter can be specified for "
                                "the default \"listen\" directive only",
@@ -3323,15 +3323,15 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
         }
 
         if (ngx_strcmp(value[n].data, "bind") == 0) {
-            ls.opt.bind = 1;
+            lsopt.bind = 1;
             continue;
         }
 
         if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
-            ls.opt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
-            ls.opt.bind = 1;
-
-            if (ls.opt.backlog == NGX_ERROR || ls.opt.backlog == 0) {
+            lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
+            lsopt.bind = 1;
+
+            if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) {
                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                    "invalid backlog \"%V\"", &value[n]);
                 return NGX_CONF_ERROR;
@@ -3344,10 +3344,10 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
             size.len = value[n].len - 7;
             size.data = value[n].data + 7;
 
-            ls.opt.rcvbuf = ngx_parse_size(&size);
-            ls.opt.bind = 1;
-
-            if (ls.opt.rcvbuf == NGX_ERROR) {
+            lsopt.rcvbuf = ngx_parse_size(&size);
+            lsopt.bind = 1;
+
+            if (lsopt.rcvbuf == NGX_ERROR) {
                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                    "invalid rcvbuf \"%V\"", &value[n]);
                 return NGX_CONF_ERROR;
@@ -3360,10 +3360,10 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
             size.len = value[n].len - 7;
             size.data = value[n].data + 7;
 
-            ls.opt.sndbuf = ngx_parse_size(&size);
-            ls.opt.bind = 1;
-
-            if (ls.opt.sndbuf == NGX_ERROR) {
+            lsopt.sndbuf = ngx_parse_size(&size);
+            lsopt.bind = 1;
+
+            if (lsopt.sndbuf == NGX_ERROR) {
                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                    "invalid sndbuf \"%V\"", &value[n]);
                 return NGX_CONF_ERROR;
@@ -3374,8 +3374,8 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
 
         if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
-            ls.opt.accept_filter = (char *) &value[n].data[14];
-            ls.opt.bind = 1;
+            lsopt.accept_filter = (char *) &value[n].data[14];
+            lsopt.bind = 1;
 #else
             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                "accept filters \"%V\" are not supported "
@@ -3387,8 +3387,8 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
 
         if (ngx_strcmp(value[n].data, "deferred") == 0) {
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
-            ls.opt.deferred_accept = 1;
-            ls.opt.bind = 1;
+            lsopt.deferred_accept = 1;
+            lsopt.bind = 1;
 #else
             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                "the deferred accept is not supported "
@@ -3401,15 +3401,15 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
             struct sockaddr  *sa;
 
-            sa = (struct sockaddr *) ls.sockaddr;
+            sa = (struct sockaddr *) lsopt.sockaddr;
 
             if (sa->sa_family == AF_INET6) {
 
                 if (ngx_strcmp(&value[n].data[10], "n") == 0) {
-                    ls.opt.ipv6only = 1;
+                    lsopt.ipv6only = 1;
 
                 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
-                    ls.opt.ipv6only = 2;
+                    lsopt.ipv6only = 2;
 
                 } else {
                     ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
@@ -3418,12 +3418,12 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
                     return NGX_CONF_ERROR;
                 }
 
-                ls.opt.bind = 1;
+                lsopt.bind = 1;
 
             } else {
                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                    "ipv6only is not supported "
-                                   "on addr \"%s\", ignored", ls.opt.addr);
+                                   "on addr \"%s\", ignored", lsopt.addr);
             }
 
             continue;
@@ -3437,7 +3437,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
 
         if (ngx_strcmp(value[n].data, "ssl") == 0) {
 #if (NGX_HTTP_SSL)
-            ls.opt.ssl = 1;
+            lsopt.ssl = 1;
             continue;
 #else
             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
@@ -3452,7 +3452,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
         return NGX_CONF_ERROR;
     }
 
-    if (ngx_http_add_listen(cf, cscf, &ls) == NGX_OK) {
+    if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) {
         return NGX_CONF_OK;
     }
 
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -43,6 +43,9 @@ typedef struct ngx_http_core_loc_conf_s 
 
 
 typedef struct {
+    u_char                     sockaddr[NGX_SOCKADDRLEN];
+    socklen_t                  socklen;
+
     unsigned                   default_server:1;
     unsigned                   bind:1;
     unsigned                   wildcard:1;
@@ -68,14 +71,6 @@ typedef struct {
 } ngx_http_listen_opt_t;
 
 
-typedef struct {
-    u_char                     sockaddr[NGX_SOCKADDRLEN];
-    socklen_t                  socklen;
-
-    ngx_http_listen_opt_t      opt;
-} ngx_http_listen_t;
-
-
 typedef enum {
     NGX_HTTP_POST_READ_PHASE = 0,
 
@@ -223,8 +218,7 @@ typedef struct {
 
 
 typedef struct {
-    u_char                     sockaddr[NGX_SOCKADDRLEN];
-    socklen_t                  socklen;
+    ngx_http_listen_opt_t      opt;
 
     ngx_hash_t                 hash;
     ngx_hash_wildcard_t       *wc_head;
@@ -238,8 +232,6 @@ typedef struct {
     /* the default server configuration for this address:port */
     ngx_http_core_srv_conf_t  *core_srv_conf;
     ngx_array_t                servers;  /* array of ngx_http_core_srv_conf_t */
-
-    ngx_http_listen_opt_t      opt;
 } ngx_http_conf_addr_t;