Mercurial > hg > nginx
comparison src/http/ngx_http.c @ 3218:022a7662b4ed
refactor http listen code: remove duplicate options fields
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 21 Oct 2009 08:48:04 +0000 |
parents | a22bf524a456 |
children | 81b8416054b0 |
comparison
equal
deleted
inserted
replaced
3217:a22bf524a456 | 3218:022a7662b4ed |
---|---|
1211 | 1211 |
1212 /* check the duplicate "default" server for this address:port */ | 1212 /* check the duplicate "default" server for this address:port */ |
1213 | 1213 |
1214 if (listen->opt.default_server) { | 1214 if (listen->opt.default_server) { |
1215 | 1215 |
1216 if (addr[i].default_server) { | 1216 if (addr[i].opt.default_server) { |
1217 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1217 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1218 "the duplicate default server"); | 1218 "the duplicate default server"); |
1219 return NGX_ERROR; | 1219 return NGX_ERROR; |
1220 } | 1220 } |
1221 | 1221 |
1222 addr[i].core_srv_conf = cscf; | 1222 addr[i].core_srv_conf = cscf; |
1223 addr[i].default_server = 1; | |
1224 #if (NGX_HTTP_SSL) | |
1225 addr[i].ssl = listen->opt.ssl; | |
1226 #endif | |
1227 addr[i].opt = listen->opt; | 1223 addr[i].opt = listen->opt; |
1228 } | 1224 } |
1229 | 1225 |
1230 return NGX_OK; | 1226 return NGX_OK; |
1231 } | 1227 } |
1271 #if (NGX_PCRE) | 1267 #if (NGX_PCRE) |
1272 addr->nregex = 0; | 1268 addr->nregex = 0; |
1273 addr->regex = NULL; | 1269 addr->regex = NULL; |
1274 #endif | 1270 #endif |
1275 addr->core_srv_conf = cscf; | 1271 addr->core_srv_conf = cscf; |
1276 addr->default_server = listen->opt.default_server; | |
1277 addr->bind = listen->opt.bind; | |
1278 addr->wildcard = listen->opt.wildcard; | |
1279 #if (NGX_HTTP_SSL) | |
1280 addr->ssl = listen->opt.ssl; | |
1281 #endif | |
1282 addr->opt = listen->opt; | 1272 addr->opt = listen->opt; |
1283 | 1273 |
1284 return ngx_http_add_names(cf, cscf, addr); | 1274 return ngx_http_add_names(cf, cscf, addr); |
1285 } | 1275 } |
1286 | 1276 |
1529 ngx_http_conf_addr_t *first, *second; | 1519 ngx_http_conf_addr_t *first, *second; |
1530 | 1520 |
1531 first = (ngx_http_conf_addr_t *) one; | 1521 first = (ngx_http_conf_addr_t *) one; |
1532 second = (ngx_http_conf_addr_t *) two; | 1522 second = (ngx_http_conf_addr_t *) two; |
1533 | 1523 |
1534 if (first->wildcard) { | 1524 if (first->opt.wildcard) { |
1535 /* a wildcard address must be the last resort, shift it to the end */ | 1525 /* a wildcard address must be the last resort, shift it to the end */ |
1536 return 1; | 1526 return 1; |
1537 } | 1527 } |
1538 | 1528 |
1539 if (first->bind && !second->bind) { | 1529 if (first->opt.bind && !second->opt.bind) { |
1540 /* shift explicit bind()ed addresses to the start */ | 1530 /* shift explicit bind()ed addresses to the start */ |
1541 return -1; | 1531 return -1; |
1542 } | 1532 } |
1543 | 1533 |
1544 if (!first->bind && second->bind) { | 1534 if (!first->opt.bind && second->opt.bind) { |
1545 /* shift explicit bind()ed addresses to the start */ | 1535 /* shift explicit bind()ed addresses to the start */ |
1546 return 1; | 1536 return 1; |
1547 } | 1537 } |
1548 | 1538 |
1549 /* do not sort by default */ | 1539 /* do not sort by default */ |
1580 * the "*:port" only and ignore other implicit bindings. The bindings | 1570 * the "*:port" only and ignore other implicit bindings. The bindings |
1581 * have been already sorted: explicit bindings are on the start, then | 1571 * have been already sorted: explicit bindings are on the start, then |
1582 * implicit bindings go, and wildcard binding is in the end. | 1572 * implicit bindings go, and wildcard binding is in the end. |
1583 */ | 1573 */ |
1584 | 1574 |
1585 if (addr[last - 1].wildcard) { | 1575 if (addr[last - 1].opt.wildcard) { |
1586 addr[last - 1].bind = 1; | 1576 addr[last - 1].opt.bind = 1; |
1587 bind_wildcard = 1; | 1577 bind_wildcard = 1; |
1588 | 1578 |
1589 } else { | 1579 } else { |
1590 bind_wildcard = 0; | 1580 bind_wildcard = 0; |
1591 } | 1581 } |
1592 | 1582 |
1593 i = 0; | 1583 i = 0; |
1594 | 1584 |
1595 while (i < last) { | 1585 while (i < last) { |
1596 | 1586 |
1597 if (bind_wildcard && !addr[i].bind) { | 1587 if (bind_wildcard && !addr[i].opt.bind) { |
1598 i++; | 1588 i++; |
1599 continue; | 1589 continue; |
1600 } | 1590 } |
1601 | 1591 |
1602 ls = ngx_http_add_listening(cf, &addr[i]); | 1592 ls = ngx_http_add_listening(cf, &addr[i]); |
1721 | 1711 |
1722 sin = (struct sockaddr_in *) addr[i].sockaddr; | 1712 sin = (struct sockaddr_in *) addr[i].sockaddr; |
1723 addrs[i].addr = sin->sin_addr.s_addr; | 1713 addrs[i].addr = sin->sin_addr.s_addr; |
1724 addrs[i].conf.core_srv_conf = addr[i].core_srv_conf; | 1714 addrs[i].conf.core_srv_conf = addr[i].core_srv_conf; |
1725 #if (NGX_HTTP_SSL) | 1715 #if (NGX_HTTP_SSL) |
1726 addrs[i].conf.ssl = addr[i].ssl; | 1716 addrs[i].conf.ssl = addr[i].opt.ssl; |
1727 #endif | 1717 #endif |
1728 | 1718 |
1729 if (addr[i].hash.buckets == NULL | 1719 if (addr[i].hash.buckets == NULL |
1730 && (addr[i].wc_head == NULL | 1720 && (addr[i].wc_head == NULL |
1731 || addr[i].wc_head->hash.buckets == NULL) | 1721 || addr[i].wc_head->hash.buckets == NULL) |
1782 | 1772 |
1783 sin6 = (struct sockaddr_in6 *) addr[i].sockaddr; | 1773 sin6 = (struct sockaddr_in6 *) addr[i].sockaddr; |
1784 addrs6[i].addr6 = sin6->sin6_addr; | 1774 addrs6[i].addr6 = sin6->sin6_addr; |
1785 addrs6[i].conf.core_srv_conf = addr[i].core_srv_conf; | 1775 addrs6[i].conf.core_srv_conf = addr[i].core_srv_conf; |
1786 #if (NGX_HTTP_SSL) | 1776 #if (NGX_HTTP_SSL) |
1787 addrs6[i].conf.ssl = addr[i].ssl; | 1777 addrs6[i].conf.ssl = addr[i].opt.ssl; |
1788 #endif | 1778 #endif |
1789 | 1779 |
1790 if (addr[i].hash.buckets == NULL | 1780 if (addr[i].hash.buckets == NULL |
1791 && (addr[i].wc_head == NULL | 1781 && (addr[i].wc_head == NULL |
1792 || addr[i].wc_head->hash.buckets == NULL) | 1782 || addr[i].wc_head->hash.buckets == NULL) |