Mercurial > hg > nginx-ranges
comparison src/core/ngx_resolver.c @ 572:daf4847b43ff NGINX_0_8_32
nginx 0.8.32
*) Bugfix: UTF-8 encoding usage in the ngx_http_autoindex_module.
Thanks to Maxim Dounin.
*) Bugfix: regular expression named captures worked for two names only.
Thanks to Maxim Dounin.
*) Bugfix: now the "localhost" name is used in the "Host" request
header line, if an unix domain socket is defined in the "auth_http"
directive.
Thanks to Maxim Dounin.
*) Bugfix: nginx did nor support chunked transfer encoding for 201
responses.
Thanks to Julian Reich.
*) Bugfix: if the "expires modified" set date in the past, the a
negative number was set in the "Cache-Control" response header
line.
Thanks to Alex Kapranoff.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 11 Jan 2010 00:00:00 +0300 |
parents | 25255878df91 |
children | c456a023113c |
comparison
equal
deleted
inserted
replaced
571:6026569dbf64 | 572:daf4847b43ff |
---|---|
85 static void *ngx_resolver_alloc(ngx_resolver_t *r, size_t size); | 85 static void *ngx_resolver_alloc(ngx_resolver_t *r, size_t size); |
86 static void *ngx_resolver_calloc(ngx_resolver_t *r, size_t size); | 86 static void *ngx_resolver_calloc(ngx_resolver_t *r, size_t size); |
87 static void ngx_resolver_free(ngx_resolver_t *r, void *p); | 87 static void ngx_resolver_free(ngx_resolver_t *r, void *p); |
88 static void ngx_resolver_free_locked(ngx_resolver_t *r, void *p); | 88 static void ngx_resolver_free_locked(ngx_resolver_t *r, void *p); |
89 static void *ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size); | 89 static void *ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size); |
90 static u_char *ngx_resolver_log_error(ngx_log_t *log, u_char *buf, size_t len); | |
90 | 91 |
91 | 92 |
92 ngx_resolver_t * | 93 ngx_resolver_t * |
93 ngx_resolver_create(ngx_conf_t *cf, ngx_addr_t *addr) | 94 ngx_resolver_create(ngx_conf_t *cf, ngx_addr_t *addr) |
94 { | 95 { |
148 r->udp_connection = uc; | 149 r->udp_connection = uc; |
149 | 150 |
150 uc->sockaddr = addr->sockaddr; | 151 uc->sockaddr = addr->sockaddr; |
151 uc->socklen = addr->socklen; | 152 uc->socklen = addr->socklen; |
152 uc->server = addr->name; | 153 uc->server = addr->name; |
153 uc->log = &cf->cycle->new_log; | 154 |
155 uc->log = cf->cycle->new_log; | |
156 uc->log.handler = ngx_resolver_log_error; | |
157 uc->log.data = uc; | |
158 uc->log.action = "resolving"; | |
154 } | 159 } |
155 | 160 |
156 return r; | 161 return r; |
157 } | 162 } |
158 | 163 |
838 if (n == -1) { | 843 if (n == -1) { |
839 return NGX_ERROR; | 844 return NGX_ERROR; |
840 } | 845 } |
841 | 846 |
842 if ((size_t) n != (size_t) rn->qlen) { | 847 if ((size_t) n != (size_t) rn->qlen) { |
843 ngx_log_error(NGX_LOG_CRIT, uc->log, 0, "send() incomplete"); | 848 ngx_log_error(NGX_LOG_CRIT, &uc->log, 0, "send() incomplete"); |
844 return NGX_ERROR; | 849 return NGX_ERROR; |
845 } | 850 } |
846 | 851 |
847 return NGX_OK; | 852 return NGX_OK; |
848 } | 853 } |
2069 | 2074 |
2070 return "Unknown error"; | 2075 return "Unknown error"; |
2071 } | 2076 } |
2072 | 2077 |
2073 | 2078 |
2079 static u_char * | |
2080 ngx_resolver_log_error(ngx_log_t *log, u_char *buf, size_t len) | |
2081 { | |
2082 u_char *p; | |
2083 ngx_udp_connection_t *uc; | |
2084 | |
2085 p = buf; | |
2086 | |
2087 if (log->action) { | |
2088 p = ngx_snprintf(buf, len, " while %s", log->action); | |
2089 len -= p - buf; | |
2090 } | |
2091 | |
2092 uc = log->data; | |
2093 | |
2094 if (uc) { | |
2095 p = ngx_snprintf(p, len, ", resolver: %V", &uc->server); | |
2096 } | |
2097 | |
2098 return p; | |
2099 } | |
2100 | |
2101 | |
2074 ngx_int_t | 2102 ngx_int_t |
2075 ngx_udp_connect(ngx_udp_connection_t *uc) | 2103 ngx_udp_connect(ngx_udp_connection_t *uc) |
2076 { | 2104 { |
2077 int rc; | 2105 int rc; |
2078 ngx_int_t event; | 2106 ngx_int_t event; |
2080 ngx_socket_t s; | 2108 ngx_socket_t s; |
2081 ngx_connection_t *c; | 2109 ngx_connection_t *c; |
2082 | 2110 |
2083 s = ngx_socket(AF_INET, SOCK_DGRAM, 0); | 2111 s = ngx_socket(AF_INET, SOCK_DGRAM, 0); |
2084 | 2112 |
2085 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, uc->log, 0, "UDP socket %d", s); | 2113 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &uc->log, 0, "UDP socket %d", s); |
2086 | 2114 |
2087 if (s == -1) { | 2115 if (s == -1) { |
2088 ngx_log_error(NGX_LOG_ALERT, uc->log, ngx_socket_errno, | 2116 ngx_log_error(NGX_LOG_ALERT, &uc->log, ngx_socket_errno, |
2089 ngx_socket_n " failed"); | 2117 ngx_socket_n " failed"); |
2090 return NGX_ERROR; | 2118 return NGX_ERROR; |
2091 } | 2119 } |
2092 | 2120 |
2093 c = ngx_get_connection(s, uc->log); | 2121 c = ngx_get_connection(s, &uc->log); |
2094 | 2122 |
2095 if (c == NULL) { | 2123 if (c == NULL) { |
2096 if (ngx_close_socket(s) == -1) { | 2124 if (ngx_close_socket(s) == -1) { |
2097 ngx_log_error(NGX_LOG_ALERT, uc->log, ngx_socket_errno, | 2125 ngx_log_error(NGX_LOG_ALERT, &uc->log, ngx_socket_errno, |
2098 ngx_close_socket_n "failed"); | 2126 ngx_close_socket_n "failed"); |
2099 } | 2127 } |
2100 | 2128 |
2101 return NGX_ERROR; | 2129 return NGX_ERROR; |
2102 } | 2130 } |
2103 | 2131 |
2104 if (ngx_nonblocking(s) == -1) { | 2132 if (ngx_nonblocking(s) == -1) { |
2105 ngx_log_error(NGX_LOG_ALERT, uc->log, ngx_socket_errno, | 2133 ngx_log_error(NGX_LOG_ALERT, &uc->log, ngx_socket_errno, |
2106 ngx_nonblocking_n " failed"); | 2134 ngx_nonblocking_n " failed"); |
2107 | 2135 |
2108 ngx_free_connection(c); | 2136 ngx_free_connection(c); |
2109 | 2137 |
2110 if (ngx_close_socket(s) == -1) { | 2138 if (ngx_close_socket(s) == -1) { |
2111 ngx_log_error(NGX_LOG_ALERT, uc->log, ngx_socket_errno, | 2139 ngx_log_error(NGX_LOG_ALERT, &uc->log, ngx_socket_errno, |
2112 ngx_close_socket_n " failed"); | 2140 ngx_close_socket_n " failed"); |
2113 } | 2141 } |
2114 | 2142 |
2115 return NGX_ERROR; | 2143 return NGX_ERROR; |
2116 } | 2144 } |
2117 | 2145 |
2118 rev = c->read; | 2146 rev = c->read; |
2119 wev = c->write; | 2147 wev = c->write; |
2120 | 2148 |
2121 rev->log = uc->log; | 2149 rev->log = &uc->log; |
2122 wev->log = uc->log; | 2150 wev->log = &uc->log; |
2123 | 2151 |
2124 uc->connection = c; | 2152 uc->connection = c; |
2125 | 2153 |
2126 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); | 2154 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); |
2127 | 2155 |
2134 rev->own_lock = &c->lock; | 2162 rev->own_lock = &c->lock; |
2135 wev->own_lock = &c->lock; | 2163 wev->own_lock = &c->lock; |
2136 | 2164 |
2137 #endif | 2165 #endif |
2138 | 2166 |
2139 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, uc->log, 0, | 2167 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, &uc->log, 0, |
2140 "connect to %V, fd:%d #%d", &uc->server, s, c->number); | 2168 "connect to %V, fd:%d #%d", &uc->server, s, c->number); |
2141 | 2169 |
2142 rc = connect(s, uc->sockaddr, uc->socklen); | 2170 rc = connect(s, uc->sockaddr, uc->socklen); |
2143 | 2171 |
2144 /* TODO: aio, iocp */ | 2172 /* TODO: aio, iocp */ |
2145 | 2173 |
2146 if (rc == -1) { | 2174 if (rc == -1) { |
2147 ngx_log_error(NGX_LOG_CRIT, uc->log, ngx_socket_errno, | 2175 ngx_log_error(NGX_LOG_CRIT, &uc->log, ngx_socket_errno, |
2148 "connect() to %V failed", &uc->server); | 2176 "connect() failed"); |
2149 | 2177 |
2150 return NGX_ERROR; | 2178 return NGX_ERROR; |
2151 } | 2179 } |
2152 | 2180 |
2153 /* UDP sockets are always ready to write */ | 2181 /* UDP sockets are always ready to write */ |