Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

support old nginx versions for previous commit

based on commit 7957d05:
    fixed the compatible problem with nginx-1.5.8

Signed-off-by: paulyang <y_y@neusoft.com>
  • Loading branch information...
commit 922fbc53c36b82b0471e4bc244720c3e80265ee4 1 parent 7957d05
paulyang authored
View
18 ngx_tcp_upstream.c
@@ -242,6 +242,9 @@ ngx_tcp_upstream_init(ngx_tcp_session_t *s)
}
ctx->name = *host;
+#if (nginx_version) < 1005008
+ ctx->type = NGX_RESOLVE_A;
+#endif
ctx->handler = ngx_tcp_upstream_resolve_handler;
ctx->data = s;
ctx->timeout = cscf->resolver_timeout;
@@ -295,18 +298,33 @@ ngx_tcp_upstream_resolve_handler(ngx_resolver_ctx_t *ctx)
#if (NGX_DEBUG)
{
+#if (nginx_version) >= 1005008
u_char text[NGX_SOCKADDR_STRLEN];
ngx_str_t addr;
+#else
+ in_addr_t addr;
+#endif
ngx_uint_t i;
+#if (nginx_version) >= 1005008
addr.data = text;
+#endif
for (i = 0; i < ctx->naddrs; i++) {
+#if (nginx_version) >= 1005008
addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen,
text, NGX_SOCKADDR_STRLEN, 0);
ngx_log_debug1(NGX_LOG_DEBUG_TCP, s->connection->log, 0,
"name was resolved to %V", &addr);
+#else
+ addr = ntohl(ur->addrs[i]);
+
+ ngx_log_debug4(NGX_LOG_DEBUG_TCP, s->connection->log, 0,
+ "name was resolved to %ud.%ud.%ud.%ud",
+ (addr >> 24) & 0xff, (addr >> 16) & 0xff,
+ (addr >> 8) & 0xff, addr & 0xff);
+#endif
}
}
#endif
View
4 ngx_tcp_upstream.h
@@ -139,7 +139,11 @@ struct ngx_tcp_upstream_resolved_s {
ngx_uint_t no_port; /* unsigned no_port:1 */
ngx_uint_t naddrs;
+#if (nginx_version) >= 1005008
ngx_addr_t *addrs;
+#else
+ in_addr_t *addrs;
+#endif
struct sockaddr *sockaddr;
socklen_t socklen;
View
30 ngx_tcp_upstream_round_robin.c
@@ -288,9 +288,13 @@ ngx_tcp_upstream_create_round_robin_peer(ngx_tcp_session_t *s,
{
u_char *p;
size_t len;
+#if (nginx_version) >= 1005008
socklen_t socklen;
- ngx_uint_t i, n;
struct sockaddr *sockaddr;
+#else
+ struct sockaddr_in *sin;
+#endif
+ ngx_uint_t i, n;
ngx_tcp_upstream_rr_peers_t *peers;
ngx_tcp_upstream_rr_peer_data_t *rrp;
@@ -329,6 +333,7 @@ ngx_tcp_upstream_create_round_robin_peer(ngx_tcp_session_t *s,
for (i = 0; i < ur->naddrs; i++) {
+#if (nginx_version) >= 1005008
socklen = ur->addrs[i].socklen;
sockaddr = ngx_palloc(s->pool, socklen);
@@ -357,6 +362,29 @@ ngx_tcp_upstream_create_round_robin_peer(ngx_tcp_session_t *s,
peers->peer[i].sockaddr = sockaddr;
peers->peer[i].socklen = socklen;
+#else
+ len = NGX_INET_ADDRSTRLEN + sizeof(":65536") - 1;
+
+ p = ngx_pnalloc(s->pool, len);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ len = ngx_inet_ntop(AF_INET, &ur->addrs[i], p, NGX_INET_ADDRSTRLEN);
+ len = ngx_sprintf(&p[len], ":%d", ur->port) - p;
+
+ sin = ngx_pcalloc(s->pool, sizeof(struct sockaddr_in));
+ if (sin == NULL) {
+ return NGX_ERROR;
+ }
+
+ sin->sin_family = AF_INET;
+ sin->sin_port = htons(ur->port);
+ sin->sin_addr.s_addr = ur->addrs[i];
+
+ peers->peer[i].sockaddr = (struct sockaddr *) sin;
+ peers->peer[i].socklen = sizeof(struct sockaddr_in);
+#endif
peers->peer[i].name.len = len;
peers->peer[i].name.data = p;
peers->peer[i].weight = 1;
Please sign in to comment.
Something went wrong with that request. Please try again.