summaryrefslogtreecommitdiffstats
path: root/src/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/core.c b/src/core.c
index 952e1b0..f46df39 100644
--- a/src/core.c
+++ b/src/core.c
@@ -246,6 +246,7 @@ static int tip_client_redirect_create(const struct tip_client *cli)
redir->addr = cli->addr;
redir->addr.sin_port = htons(9999);
redir->uri = strdup(cli->uri);
+ redir->users = max_clients;
list_add_tail(&redir->list, &client_redirect_list);
ev_timer_init(&redir->timer, tip_client_redirect_timer_cb, 60, 0.);
@@ -386,10 +387,15 @@ bool tip_client_redirect(struct tip_client *cli)
inet_ntoa(redir->addr.sin_addr), htons(redir->addr.sin_port),
cli->uri);
- free((void *)redir->uri);
- ev_timer_stop(tip_main_loop, &redir->timer);
list_del(&redir->list);
- free(redir);
+ if (--redir->users == 0) {
+ free((void *)redir->uri);
+ ev_timer_stop(tip_main_loop, &redir->timer);
+ free(redir);
+ } else {
+ /* reinsert at the end to round-robin redirections. */
+ list_add_tail(&redir->list, &client_redirect_list);
+ }
return true;
}