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

separate source initialisation, and collect the YP setup code into one area

svn path=/trunk/icecast/; revision=5868
This commit is contained in:
Karl Heyes 2004-02-26 16:51:43 +00:00
parent aff756a4c7
commit 9916341436
2 changed files with 63 additions and 62 deletions

View File

@ -345,38 +345,17 @@ void source_move_clients (source_t *source, source_t *dest)
} }
void *source_main(void *arg) static void source_init (source_t *source)
{ {
source_t *source = (source_t *)arg; ice_config_t *config = config_get_config();
source_t *fallback_source; char *listenurl;
char buffer[4096]; int listen_url_size;
long bytes, sbytes;
int ret;
client_t *client;
avl_node *client_node;
refbuf_t *refbuf, *abuf;
int data_done;
#ifdef USE_YP #ifdef USE_YP
char *s; char *s;
long current_time; long current_time;
int i; int i;
char *ai; char *ai;
#endif
ice_config_t *config;
char *hostname;
char *listenurl;
int listen_url_size;
int port;
config = config_get_config();
hostname = strdup(config->hostname);
port = config->port;
#ifdef USE_YP
for (i=0;i<config->num_yp_directories;i++) { for (i=0;i<config->num_yp_directories;i++) {
if (config->yp_url[i]) { if (config->yp_url[i]) {
source->ypdata[source->num_yp_directories] = yp_create_ypdata(); source->ypdata[source->num_yp_directories] = yp_create_ypdata();
@ -388,20 +367,7 @@ void *source_main(void *arg)
source->num_yp_directories++; source->num_yp_directories++;
} }
} }
#endif
config_release_config();
/* grab a read lock, to make sure we get a chance to cleanup */
thread_rwlock_rlock(source->shutdown_rwlock);
/* start off the statistics */
source->listeners = 0;
stats_event_inc(NULL, "sources");
stats_event_inc(NULL, "source_total_connections");
stats_event(source->mount, "listeners", "0");
stats_event(source->mount, "type", source->format->format_description);
#ifdef USE_YP
source->audio_info = util_dict_new(); source->audio_info = util_dict_new();
/* ice-* is icecast, icy-* is shoutcast */ /* ice-* is icecast, icy-* is shoutcast */
if ((s = httpp_getvar(source->parser, "ice-url"))) { if ((s = httpp_getvar(source->parser, "ice-url"))) {
@ -462,12 +428,11 @@ void *source_main(void *arg)
free(source->ypdata[i]->listen_url); free(source->ypdata[i]->listen_url);
} }
/* 6 for max size of port */ /* 6 for max size of port */
listen_url_size = strlen("http://") + listen_url_size = strlen("http://") + strlen(config->hostname) +
strlen(hostname) + strlen(":") + 6 + strlen (source->mount) + 1;
strlen(":") + 6 + strlen(source->mount) + 1; source->ypdata[i]->listen_url = malloc (listen_url_size);
source->ypdata[i]->listen_url = malloc(listen_url_size); sprintf (source->ypdata[i]->listen_url, "http://%s:%d%s",
sprintf(source->ypdata[i]->listen_url, "http://%s:%d%s", config->hostname, config->port, source->mount);
hostname, port, source->mount);
} }
if(source->yp_public) { if(source->yp_public) {
@ -485,20 +450,23 @@ void *source_main(void *arg)
} }
} }
#endif #endif
/* 6 for max size of port */ /* 6 for max size of port */
listen_url_size = strlen("http://") + listen_url_size = strlen("http://") + strlen(config->hostname) +
strlen(hostname) + strlen(":") + 6 + strlen(source->mount) + 1; strlen(":") + 6 + strlen(source->mount) + 1;
listenurl = malloc(listen_url_size); listenurl = malloc (listen_url_size);
memset(listenurl, '\000', listen_url_size); memset (listenurl, '\000', listen_url_size);
sprintf(listenurl, "http://%s:%d%s", hostname, port, source->mount); snprintf (listenurl, listen_url_size, "http://%s:%d%s",
stats_event(source->mount, "listenurl", listenurl); config->hostname, config->port, source->mount);
if (hostname) { config_release_config();
free(hostname);
} stats_event (source->mount, "listenurl", listenurl);
if (listenurl) { if (listenurl) {
free(listenurl); free(listenurl);
} }
if (source->dumpfilename != NULL) if (source->dumpfilename != NULL)
{ {
source->dumpfile = fopen (source->dumpfilename, "ab"); source->dumpfile = fopen (source->dumpfilename, "ab");
@ -509,6 +477,16 @@ void *source_main(void *arg)
} }
} }
/* grab a read lock, to make sure we get a chance to cleanup */
thread_rwlock_rlock (source->shutdown_rwlock);
/* start off the statistics */
source->listeners = 0;
stats_event_inc (NULL, "sources");
stats_event_inc (NULL, "source_total_connections");
stats_event (source->mount, "listeners", "0");
stats_event (source->mount, "type", source->format->format_description);
sock_set_blocking (source->con->sock, SOCK_NONBLOCK); sock_set_blocking (source->con->sock, SOCK_NONBLOCK);
DEBUG0("Source creation complete"); DEBUG0("Source creation complete");
@ -521,7 +499,10 @@ void *source_main(void *arg)
** loop or jingle track or whatever the fallback is used for ** loop or jingle track or whatever the fallback is used for
*/ */
if(source->fallback_override && source->fallback_mount) { if (source->fallback_override && source->fallback_mount)
{
source_t *fallback_source;
avl_tree_rlock(global.source_tree); avl_tree_rlock(global.source_tree);
fallback_source = source_find_mount(source->fallback_mount); fallback_source = source_find_mount(source->fallback_mount);
@ -530,6 +511,21 @@ void *source_main(void *arg)
avl_tree_unlock(global.source_tree); avl_tree_unlock(global.source_tree);
} }
}
void source_main (source_t *source)
{
char buffer[4096];
long bytes, sbytes;
int ret;
client_t *client;
avl_node *client_node;
refbuf_t *refbuf, *abuf;
int data_done;
source_init (source);
while (global.running == ICE_RUNNING && source->running) { while (global.running == ICE_RUNNING && source->running) {
ret = source->format->get_buffer(source->format, NULL, 0, &refbuf); ret = source->format->get_buffer(source->format, NULL, 0, &refbuf);
@ -782,13 +778,18 @@ done:
/* we have de-activated the source now, so no more clients will be /* we have de-activated the source now, so no more clients will be
* added, now move the listeners we have to the fallback (if any) * added, now move the listeners we have to the fallback (if any)
*/ */
avl_tree_rlock(global.source_tree); if (source->fallback_mount)
fallback_source = source_find_mount (source->fallback_mount); {
source_t *fallback_source;
if (fallback_source != NULL) avl_tree_rlock(global.source_tree);
source_move_clients (source, fallback_source); fallback_source = source_find_mount (source->fallback_mount);
avl_tree_unlock (global.source_tree); if (fallback_source != NULL)
source_move_clients (source, fallback_source);
avl_tree_unlock (global.source_tree);
}
/* delete this sources stats */ /* delete this sources stats */
stats_event_dec(NULL, "sources"); stats_event_dec(NULL, "sources");
@ -808,7 +809,7 @@ done:
therefore reserved */ therefore reserved */
source_clear_source (source); source_clear_source (source);
return NULL; return;
} }
static int _compare_clients(void *compare_arg, void *a, void *b) static int _compare_clients(void *compare_arg, void *a, void *b)

View File

@ -71,7 +71,7 @@ int source_compare_sources(void *arg, void *a, void *b);
int source_free_source(void *key); int source_free_source(void *key);
void source_move_clients (source_t *source, source_t *dest); void source_move_clients (source_t *source, source_t *dest);
int source_remove_client(void *key); int source_remove_client(void *key);
void *source_main(void *arg); void source_main(source_t *source);
extern mutex_t move_clients_mutex; extern mutex_t move_clients_mutex;