summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.c12
-rw-r--r--src/core.h1
2 files changed, 10 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;
}
diff --git a/src/core.h b/src/core.h
index 88a07a9..7d6d403 100644
--- a/src/core.h
+++ b/src/core.h
@@ -84,6 +84,7 @@ struct tip_client_redirect {
struct sockaddr_in addr;
const char *uri;
struct ev_timer timer;
+ uint32_t users;
};
#endif