diff options
Diffstat (limited to 'src/core.c')
-rw-r--r-- | src/core.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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; } |