Commit d7f1285b authored by Karl Heyes's avatar Karl Heyes

drop the thread pool of connection threads, they were using a blocking socket

on incoming connections. Now we get the accept thread to create a client_t
and mark it as a shoutcast client if need be.  Then use a single connection
thread to poll the non-blocking sockets for the headers. When complete they
get handled as usual.

svn path=/icecast/trunk/icecast/; revision=9733
parent 30ce5c5b
......@@ -39,33 +39,34 @@
#undef CATMODULE
#define CATMODULE "client"
client_t *client_create(connection_t *con, http_parser_t *parser)
/* should be called with global lock held */
int client_create (client_t **c_ptr, connection_t *con, http_parser_t *parser)
{
ice_config_t *config = config_get_config ();
ice_config_t *config;
client_t *client = (client_t *)calloc(1, sizeof(client_t));
int client_limit = config->client_limit;
config_release_config ();
int ret = -1;
if (client == NULL)
return -1;
config = config_get_config ();
global_lock();
if (global.clients >= client_limit || client == NULL)
{
client_limit = global.clients;
global_unlock();
free (client);
WARN1 ("server client limit reached (%d clients)", client_limit);
return NULL;
}
global.clients++;
stats_event_args (NULL, "clients", "%d", global.clients);
global_unlock();
if (config->client_limit < global.clients)
WARN2 ("server client limit reached (%d/%d)", config->client_limit, global.clients);
else
ret = 0;
config_release_config ();
stats_event_args (NULL, "clients", "%d", global.clients);
client->con = con;
client->parser = parser;
client->refbuf = NULL;
client->pos = 0;
client->write_to_client = format_generic_write_to_client;
*c_ptr = client;
return client;
return ret;
}
void client_destroy(client_t *client)
......@@ -110,7 +111,23 @@ void client_destroy(client_t *client)
/* helper function for reading data from a client */
int client_read_bytes (client_t *client, void *buf, unsigned len)
{
int bytes = sock_read_bytes (client->con->sock, buf, len);
int bytes;
if (client->refbuf && client->refbuf->len)
{
/* we have data to read from a refbuf first */
if (client->refbuf->len < len)
len = client->refbuf->len;
memcpy (buf, client->refbuf->data, len);
if (client->refbuf->len < len)
{
char *ptr = client->refbuf->data;
memmove (ptr, ptr+len, client->refbuf->len - len);
}
client->refbuf->len -= len;
return len;
}
bytes = sock_read_bytes (client->con->sock, buf, len);
if (bytes > 0)
return bytes;
......
......@@ -67,7 +67,7 @@ typedef struct _client_tag
} client_t;
client_t *client_create(connection_t *con, http_parser_t *parser);
int client_create (client_t **c_ptr, connection_t *con, http_parser_t *parser);
void client_destroy(client_t *client);
void client_send_504(client_t *client, char *message);
void client_send_404(client_t *client, char *message);
......
This diff is collapsed.
......@@ -38,20 +38,15 @@ typedef struct connection_tag
char *ip;
char *host;
/* For 'fake' connections */
int event_number;
void *event;
} connection_t;
void connection_initialize(void);
void connection_shutdown(void);
void connection_accept_loop(void);
void connection_close(connection_t *con);
connection_t *create_connection(sock_t sock, sock_t serversock, char *ip);
connection_t *connection_create (sock_t sock, sock_t serversock, char *ip);
int connection_complete_source (struct source_tag *source);
void connection_inject_event(int eventnum, void *event_data);
int connection_check_source_pass(http_parser_t *parser, const char *mount);
int connection_check_relay_pass(http_parser_t *parser);
int connection_check_admin_pass(http_parser_t *parser);
......
......@@ -571,9 +571,6 @@ int fserve_add_client (client_t *client, FILE *file)
fclient->client = client;
fclient->ready = 0;
sock_set_blocking (client->con->sock, SOCK_NONBLOCK);
sock_set_nodelay (client->con->sock);
thread_mutex_lock (&pending_lock);
fclient->next = (fserve_t *)pending_list;
pending_list = fclient;
......
......@@ -56,6 +56,7 @@
#include "logging.h"
#include "source.h"
#include "format.h"
#include "event.h"
#define CATMODULE "slave"
......@@ -180,7 +181,7 @@ static void *start_relay_stream (void *arg)
relay->server, relay->port, relay->mount);
break;
}
con = create_connection (streamsock, -1, NULL);
con = connection_create (streamsock, -1, NULL);
if (relay->username && relay->password)
{
......@@ -598,6 +599,13 @@ static void *_slave_thread(void *arg)
{
relay_server *cleanup_relays;
/* re-read xml file if requested */
if (global . schedule_config_reread)
{
event_config_read (NULL);
global . schedule_config_reread = 0;
}
thread_sleep (1000000);
if (slave_running == 0)
break;
......
......@@ -602,9 +602,6 @@ static void source_init (source_t *source)
stats_event (source->mount, "listener_peak", "0");
stats_event_time (source->mount, "stream_start");
if (source->client->con)
sock_set_blocking (source->con->sock, SOCK_NONBLOCK);
DEBUG0("Source creation complete");
source->last_read = time (NULL);
source->running = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment