Skip to content

Commit 0ca4be9

Browse files
authored
Merge pull request #7 from CallMeFoxie/bothupsync
Allow both upsyncs at once
2 parents 2420672 + 0d78b65 commit 0ca4be9

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/ngx_stream_upsync_module.c

+17-8
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ static http_parser_settings settings = {
254254
.on_message_complete = 0
255255
};
256256

257-
ngx_atomic_t upsync_shared_created0;
258-
ngx_atomic_t *upsync_shared_created = &upsync_shared_created0;
257+
ngx_atomic_t stream_upsync_shared_created0;
258+
ngx_atomic_t *stream_upsync_shared_created = &stream_upsync_shared_created0;
259259

260260
static http_parser *parser = NULL;
261261
static ngx_stream_http_state state;
@@ -1878,7 +1878,12 @@ ngx_stream_upsync_init_module(ngx_cycle_t *cycle)
18781878
ngx_uint_t i;
18791879
ngx_stream_upsync_server_t *upsync_server;
18801880
ngx_stream_upsync_srv_conf_t *upscf;
1881-
1881+
1882+
// no stream {} block found
1883+
if (upsync_ctx == NULL) {
1884+
return NGX_OK;
1885+
}
1886+
18821887
upsync_server = upsync_ctx->upsync_server;
18831888

18841889
if (ngx_stream_upsync_init_shm_mutex(cycle) != NGX_OK) {
@@ -1913,10 +1918,10 @@ ngx_stream_upsync_init_shm_mutex(ngx_cycle_t *cycle)
19131918

19141919
upsync_server = upsync_ctx->upsync_server;
19151920

1916-
if (*upsync_shared_created) {
1917-
shm.size = 128 * (*upsync_shared_created);
1921+
if (*stream_upsync_shared_created) {
1922+
shm.size = 128 * (*stream_upsync_shared_created);
19181923
shm.log = cycle->log;
1919-
shm.addr = (u_char *)(upsync_shared_created);
1924+
shm.addr = (u_char *)(stream_upsync_shared_created);
19201925
shm.name.len = sizeof("ngx_upsync_shared_zone");
19211926
shm.name.data = (u_char *)"ngx_upsync_shared_zone";
19221927

@@ -1942,7 +1947,7 @@ ngx_stream_upsync_init_shm_mutex(ngx_cycle_t *cycle)
19421947
}
19431948
shared = shm.addr;
19441949

1945-
upsync_shared_created = (ngx_atomic_t *)shared;
1950+
stream_upsync_shared_created = (ngx_atomic_t *)shared;
19461951

19471952
for (i = 0; i < upsync_ctx->upstream_num; i++) {
19481953

@@ -1970,7 +1975,7 @@ ngx_stream_upsync_init_shm_mutex(ngx_cycle_t *cycle)
19701975
}
19711976
}
19721977

1973-
ngx_atomic_cmp_set(upsync_shared_created, *upsync_shared_created,
1978+
ngx_atomic_cmp_set(stream_upsync_shared_created, *stream_upsync_shared_created,
19741979
upsync_ctx->upstream_num);
19751980

19761981
return NGX_OK;
@@ -1988,6 +1993,10 @@ ngx_stream_upsync_init_process(ngx_cycle_t *cycle)
19881993
ngx_stream_upsync_ctx_t *ctx;
19891994
ngx_stream_upsync_server_t *upsync_server;
19901995

1996+
// no stream {} block found
1997+
if (upsync_ctx == NULL) {
1998+
return NGX_OK;
1999+
}
19912000
upsync_server = upsync_ctx->upsync_server;
19922001

19932002
for (i = 0; i < upsync_ctx->upstream_num; i++) {

0 commit comments

Comments
 (0)