Make the maximum number of clients configurable
authorJuho Vähä-Herttua <juhovh@iki.fi>
Mon, 14 May 2012 20:04:41 +0000 (23:04 +0300)
committerJuho Vähä-Herttua <juhovh@iki.fi>
Wed, 16 May 2012 21:57:07 +0000 (00:57 +0300)
src/include/raop.h
src/lib/httpd.c
src/lib/raop.c
src/test/example.c

index 1a7ebc2325ab43610a8069a8103cbbab89e293a2..5d5dc08d9131c78a17a64f4a0fab5f43a303b286 100644 (file)
@@ -43,8 +43,8 @@ struct raop_callbacks_s {
 };
 typedef struct raop_callbacks_s raop_callbacks_t;
 
-RAOP_API raop_t *raop_init(raop_callbacks_t *callbacks, const char *pemkey);
-RAOP_API raop_t *raop_init_from_keyfile(raop_callbacks_t *callbacks, const char *keyfile);
+RAOP_API raop_t *raop_init(int max_clients, raop_callbacks_t *callbacks, const char *pemkey);
+RAOP_API raop_t *raop_init_from_keyfile(int max_clients, raop_callbacks_t *callbacks, const char *keyfile);
 
 RAOP_API void raop_set_log_level(raop_t *raop, int level);
 RAOP_API void raop_set_log_callback(raop_t *raop, raop_log_callback_t callback);
index 971a5bf3e99e0717a3b2feddfd6248a4d5b893bd..2bed984203ebbdd907eb480daa8ea20749f2c682 100644 (file)
@@ -110,6 +110,7 @@ httpd_add_connection(httpd_t *httpd, int fd, unsigned char *local, int local_len
                }
        }
        if (i == httpd->max_connections) {
+               /* This code should never be reached, we do not select server_fd when full */
                logger_log(httpd->logger, LOGGER_INFO, "Max connections reached");
                shutdown(fd, SHUT_RDWR);
                closesocket(fd);
index 9ede243911c58bdd9876751085e63d136925a864..fd02edfebfdd1a1534dc3978be98071e089e0ee7 100644 (file)
@@ -349,7 +349,7 @@ conn_destroy(void *ptr)
 }
 
 raop_t *
-raop_init(raop_callbacks_t *callbacks, const char *pemkey)
+raop_init(int max_clients, raop_callbacks_t *callbacks, const char *pemkey)
 {
        raop_t *raop;
        httpd_t *httpd;
@@ -357,6 +357,8 @@ raop_init(raop_callbacks_t *callbacks, const char *pemkey)
        httpd_callbacks_t httpd_cbs;
 
        assert(callbacks);
+       assert(max_clients > 0);
+       assert(max_clients < 100);
        assert(pemkey);
 
        /* Initialize the network */
@@ -388,7 +390,7 @@ raop_init(raop_callbacks_t *callbacks, const char *pemkey)
        httpd_cbs.conn_destroy = &conn_destroy;
 
        /* Initialize the http daemon */
-       httpd = httpd_init(raop->logger, &httpd_cbs, 10, 1);
+       httpd = httpd_init(raop->logger, &httpd_cbs, max_clients, 1);
        if (!httpd) {
                free(raop);
                return NULL;
@@ -412,7 +414,7 @@ raop_init(raop_callbacks_t *callbacks, const char *pemkey)
 }
 
 raop_t *
-raop_init_from_keyfile(raop_callbacks_t *callbacks, const char *keyfile)
+raop_init_from_keyfile(int max_clients, raop_callbacks_t *callbacks, const char *keyfile)
 {
        raop_t *raop;
        char *pemstr;
@@ -420,7 +422,7 @@ raop_init_from_keyfile(raop_callbacks_t *callbacks, const char *keyfile)
        if (utils_read_file(&pemstr, keyfile) < 0) {
                return NULL;
        }
-       raop = raop_init(callbacks, pemstr);
+       raop = raop_init(max_clients, callbacks, pemstr);
        free(pemstr);
        return raop;
 }
index c07b1268c6a2d271b3949028c18e98982f563140..fdd97048b75f24c13581ff23ab909802464fe507 100644 (file)
@@ -92,7 +92,7 @@ main(int argc, char *argv[])
        raop_cbs.audio_flush = audio_flush;
        raop_cbs.audio_destroy = audio_destroy;
 
-       raop = raop_init_from_keyfile(&raop_cbs, "airport.key");
+       raop = raop_init_from_keyfile(10, &raop_cbs, "airport.key");
        raop_set_log_level(raop, RAOP_LOG_DEBUG);
        raop_set_log_callback(raop, &raop_log_callback);
        raop_start(raop, &raop_port, hwaddr, sizeof(hwaddr), "test");