1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

Feature: Prepare for support to move single clients

This commit is contained in:
Philipp Schafft 2020-09-30 17:50:26 +00:00
parent e86a46ee4a
commit d92c9758a6
4 changed files with 33 additions and 19 deletions

View File

@ -659,7 +659,7 @@ static void command_move_clients(client_t *client,
node = admin_build_rootnode(doc, "iceresponse"); node = admin_build_rootnode(doc, "iceresponse");
xmlDocSetRootElement(doc, node); xmlDocSetRootElement(doc, node);
source_move_clients(source, dest); source_move_clients(source, dest, NULL);
snprintf(buf, sizeof(buf), "Clients moved from %s to %s", snprintf(buf, sizeof(buf), "Clients moved from %s to %s",
source->mount, dest_source); source->mount, dest_source);

View File

@ -467,7 +467,7 @@ static void *start_relay_stream (void *arg)
fallback_source = source_find_mount(relay->source->fallback_mount); fallback_source = source_find_mount(relay->source->fallback_mount);
if (fallback_source != NULL) if (fallback_source != NULL)
source_move_clients(relay->source, fallback_source); source_move_clients(relay->source, fallback_source, NULL);
avl_tree_unlock(global.source_tree); avl_tree_unlock(global.source_tree);
} }

View File

@ -367,7 +367,7 @@ static inline void source_move_clients__single(source_t *source, avl_tree *from,
* The only lock that should be held when this is called is the * The only lock that should be held when this is called is the
* source tree lock * source tree lock
*/ */
void source_move_clients(source_t *source, source_t *dest) void source_move_clients(source_t *source, source_t *dest, connection_id_t *id)
{ {
unsigned long count = 0; unsigned long count = 0;
if (strcmp(source->mount, dest->mount) == 0) { if (strcmp(source->mount, dest->mount) == 0) {
@ -405,6 +405,19 @@ void source_move_clients(source_t *source, source_t *dest)
} }
} }
if (id) {
client_t fakeclient;
connection_t fakecon;
void *result;
fakeclient.con = &fakecon;
fakeclient.con->id = *id;
if (avl_get_by_key(source->client_tree, &fakeclient, &result) == 0) {
source_move_clients__single(source, source->client_tree, dest->pending_tree, result);
count++;
}
} else {
while (1) { while (1) {
avl_node *node = avl_get_first(source->pending_tree); avl_node *node = avl_get_first(source->pending_tree);
if (node == NULL) if (node == NULL)
@ -420,6 +433,7 @@ void source_move_clients(source_t *source, source_t *dest)
source_move_clients__single(source, source->client_tree, dest->pending_tree, node); source_move_clients__single(source, source->client_tree, dest->pending_tree, node);
count++; count++;
} }
}
ICECAST_LOG_INFO("passing %lu listeners to \"%s\"", count, dest->mount); ICECAST_LOG_INFO("passing %lu listeners to \"%s\"", count, dest->mount);
@ -653,7 +667,7 @@ static void source_init (source_t *source)
fallback_source = source_find_mount(source->fallback_mount); fallback_source = source_find_mount(source->fallback_mount);
if (fallback_source) if (fallback_source)
source_move_clients (fallback_source, source); source_move_clients(fallback_source, source, NULL);
avl_tree_unlock(global.source_tree); avl_tree_unlock(global.source_tree);
} }
@ -852,7 +866,7 @@ static void source_shutdown (source_t *source)
fallback_source = source_find_mount(source->fallback_mount); fallback_source = source_find_mount(source->fallback_mount);
if (fallback_source != NULL) if (fallback_source != NULL)
source_move_clients(source, fallback_source); source_move_clients(source, fallback_source, NULL);
avl_tree_unlock(global.source_tree); avl_tree_unlock(global.source_tree);
} }

View File

@ -95,7 +95,7 @@ source_t *source_find_mount_raw(const char *mount);
client_t *source_find_client(source_t *source, connection_id_t id); client_t *source_find_client(source_t *source, connection_id_t id);
int source_compare_sources(void *arg, void *a, void *b); int source_compare_sources(void *arg, void *a, void *b);
void source_free_source(source_t *source); void source_free_source(source_t *source);
void source_move_clients (source_t *source, source_t *dest); void source_move_clients(source_t *source, source_t *dest, connection_id_t *id);
int source_remove_client(void *key); int source_remove_client(void *key);
void source_main(source_t *source); void source_main(source_t *source);
void source_recheck_mounts (int update_all); void source_recheck_mounts (int update_all);