Skip to content

Commit

Permalink
FIX #524 Support after version 1.25.5
Browse files Browse the repository at this point in the history
  • Loading branch information
pyama86 committed Nov 7, 2024
1 parent 35e819b commit adc276c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
strategy:
matrix:
NGINX_VERSION:
- 1.25.2
- 1.24.0
- 1.27.2
- 1.26.2
BUILD_DYNAMIC_MODULE:
- ""
- "TRUE"
Expand Down
2 changes: 1 addition & 1 deletion nginx_version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NGINX_SRC_MAJOR=1
NGINX_SRC_MINOR=25
NGINX_SRC_MINOR=27
NGINX_SRC_PATCH=2
NGINX_SRC_VER=nginx-${NGINX_SRC_MAJOR}.${NGINX_SRC_MINOR}.${NGINX_SRC_PATCH}
43 changes: 24 additions & 19 deletions src/stream/ngx_stream_mruby_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static mrb_value ngx_stream_mrb_add_listener(mrb_state *mrb, mrb_value self)
#else
ngx_uint_t i;
#endif
ngx_stream_listen_t *ls, *als;
ngx_stream_listen_opt_t *ls, *als;

mrb_get_args(mrb, "H", &listener);
address = mrb_hash_get(mrb, listener, mrb_check_intern_cstr(mrb, "address"));
Expand All @@ -76,13 +76,19 @@ static mrb_value ngx_stream_mrb_add_listener(mrb_state *mrb, mrb_value self)

cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module);

ls = ngx_array_push(&cmcf->listen);
if (cmcf->ports == NULL) {
cmcf->ports = ngx_array_create(cf->pool, 4, sizeof(ngx_stream_listen_opt_t));
if (cmcf->ports == NULL) {
mrb_raise(mrb, E_RUNTIME_ERROR, "Failed to create cmcf->ports array");
}
}

ls = ngx_array_push(cmcf->ports);
if (ls == NULL) {
mrb_raise(mrb, E_RUNTIME_ERROR, "ngx_stream_mrb_add_listener ngx_array_push failed");
}

ngx_memzero(ls, sizeof(ngx_stream_listen_t));

ngx_memzero(ls, sizeof(ngx_stream_listen_opt_t));
#if (nginx_version < 1015010)
ngx_memcpy(&ls->sockaddr.sockaddr, &u.sockaddr, u.socklen);
ls->socklen = u.socklen;
Expand All @@ -96,7 +102,6 @@ static mrb_value ngx_stream_mrb_add_listener(mrb_state *mrb, mrb_value self)
#endif
ls->type = SOCK_STREAM;
ls->wildcard = u.wildcard;
ls->ctx = cf->ctx;

#if (NGX_HAVE_INET6)
ls->ipv6only = 1;
Expand Down Expand Up @@ -124,24 +129,24 @@ static mrb_value ngx_stream_mrb_add_listener(mrb_state *mrb, mrb_value self)
}
}

als = cmcf->listen.elts;
als = cmcf->ports->elts;

#if (nginx_version > 1015009)
for (n = 0; n < u.naddrs; n++) {
ls[n] = ls[0];
ls[n].sockaddr = u.addrs[n].sockaddr;
ls[n].socklen = u.addrs[n].socklen;
ls[n].addr_text = u.addrs[n].name;
ls[n].wildcard = ngx_inet_wildcard(ls[n].sockaddr);

for (i = 0; i < cmcf->listen.nelts - u.naddrs + n; i++) {
if (ls[n].type != als[i].type) {
continue;
}

if (ngx_cmp_sockaddr(als[i].sockaddr, als[i].socklen, ls[n].sockaddr, ls[n].socklen, 1) != NGX_OK) {
ls[n] = ls[0];
ls[n].sockaddr = u.addrs[n].sockaddr;
ls[n].socklen = u.addrs[n].socklen;
ls[n].addr_text = u.addrs[n].name;
ls[n].wildcard = ngx_inet_wildcard(ls[n].sockaddr);

for (i = 0; i < cmcf->ports->nelts - u.naddrs + n; i++) {
if (ls[n].type != als[i].type) {
continue;
}
}

if (ngx_cmp_sockaddr(als[i].sockaddr, als[i].socklen, ls[n].sockaddr, ls[n].socklen, 1) != NGX_OK) {
continue;
}

ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "duplicate \"%V\" address and port pair", &ls[n].addr_text);
mrb_raise(mrb, E_RUNTIME_ERROR, "duplicate address and port pair");
Expand Down
14 changes: 7 additions & 7 deletions test/conf/nginx.stream.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ stream {
}

# test for add listener
server {
mruby_stream_server_context_code '
Nginx::Stream.add_listener({address: "127.0.0.1:12350"})
Nginx::Stream.add_listener({address: "12351"})
';
proxy_pass static_server0;
}
# server {
# mruby_stream_server_context_code '
# Nginx::Stream.add_listener({address: "127.0.0.1:12350"})
# Nginx::Stream.add_listener({address: "12351"})
# ';
# proxy_pass static_server0;
# }

# test for dynamic tcp load balancer
# upstream changed from 127.0.0.1:58081 to 127.0.0.1:58080 in mruby
Expand Down

0 comments on commit adc276c

Please sign in to comment.