From 7371d0ab215b038b75b027b1ba49139c8d8d1c17 Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Wed, 25 Feb 2004 16:24:30 +0000 Subject: [PATCH] move the source client '200 OK' response to the source client specific part of the source thread, and rearrange stats around that svn path=/trunk/icecast/; revision=5862 --- src/connection.c | 4 ---- src/source.c | 34 +++++++++++++++++++++------------- src/source.h | 1 - 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/connection.c b/src/connection.c index cb69380b..a5848ea0 100644 --- a/src/connection.c +++ b/src/connection.c @@ -479,8 +479,6 @@ int connection_complete_source (source_t *source) global.sources++; global_unlock(); - stats_event_inc(NULL, "sources"); - stats_event_inc(NULL, "source_total_connections"); /* for relays, we don't yet have a client, however we do require one * to retrieve the stream from. This is created here, quite late, @@ -490,8 +488,6 @@ int connection_complete_source (source_t *source) if (source->client == NULL) source->client = client_create (source->con, source->parser); - sock_set_blocking (source->con->sock, SOCK_NONBLOCK); - while (mountproxy) { if (strcmp (mountproxy->mountname, source->mount) == 0) diff --git a/src/source.c b/src/source.c index a3b797f1..d3552f7a 100644 --- a/src/source.c +++ b/src/source.c @@ -398,18 +398,10 @@ void *source_main(void *arg) /* grab a read lock, to make sure we get a chance to cleanup */ thread_rwlock_rlock(source->shutdown_rwlock); - /* If we connected successfully, we can send the message (if requested) - * back - */ - if(source->send_return) { - source->client->respcode = 200; - bytes = sock_write(source->client->con->sock, - "HTTP/1.0 200 OK\r\n\r\n"); - if(bytes > 0) source->client->con->sent_bytes = bytes; - } - /* 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 @@ -520,6 +512,7 @@ void *source_main(void *arg) } } + sock_set_blocking (source->con->sock, SOCK_NONBLOCK); DEBUG0("Source creation complete"); source->running = 1; @@ -913,10 +906,25 @@ void source_apply_mount (source_t *source, mount_proxy *mountinfo) void *source_client_thread (void *arg) { source_t *source = arg; + const char ok_msg[] = "HTTP/1.0 200 OK\r\n\r\n"; + int bytes; - source->send_return = 1; - stats_event_inc(NULL, "source_client_connections"); - source_main (source); + source->client->respcode = 200; + bytes = sock_write_bytes (source->client->con->sock, ok_msg, sizeof (ok_msg)-1); + if (bytes < sizeof (ok_msg)-1) + { + global_lock(); + global.sources--; + global_unlock(); + WARN0 ("Error writing 200 OK message to source client"); + } + else + { + source->client->con->sent_bytes += bytes; + + stats_event_inc(NULL, "source_client_connections"); + source_main (source); + } source_free_source (source); return NULL; } diff --git a/src/source.h b/src/source.h index ba39dfc9..cafef86a 100644 --- a/src/source.h +++ b/src/source.h @@ -53,7 +53,6 @@ typedef struct source_tag long listeners; long max_listeners; int yp_public; - int send_return; struct auth_tag *authenticator; int fallback_override; int no_mount;