diff options
author | tiptorrent development team <tiptorrent@soleta.eu> | 2021-09-13 16:40:46 +0200 |
---|---|---|
committer | tiptorrent development team <tiptorrent@soleta.eu> | 2021-09-29 15:48:24 +0200 |
commit | 5a7d9644e4712bde19bc9b01f8ae198c0d9b0fe9 (patch) | |
tree | 0619c9ed676e77bff17cc48f9e51c536d114afc5 /src | |
parent | 0be142b8c9934c3cce43abca755eca1f22144320 (diff) |
allow to reuse redirections
A redirection can be reused up to max_clients times.
Diffstat (limited to 'src')
-rw-r--r-- | src/core.c | 12 | ||||
-rw-r--r-- | src/core.h | 1 |
2 files changed, 10 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; } @@ -84,6 +84,7 @@ struct tip_client_redirect { struct sockaddr_in addr; const char *uri; struct ev_timer timer; + uint32_t users; }; #endif |