]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Add chunk_queue infrastructure to the udp sender.
authorAndre Noll <maan@systemlinux.org>
Sat, 10 Jan 2009 17:15:18 +0000 (18:15 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 10 Jan 2009 17:15:18 +0000 (18:15 +0100)
The chunk queue is created and destroyed but not yet used.

udp_send.c

index 9e8bc0482cdf79153ded26ad08777bff044f938b..f2a430b6b774e9650cad9cb1aba864b4851fa3a9 100644 (file)
@@ -26,7 +26,7 @@
 #include "fd.h"
 #include "sched.h"
 #include "close_on_fork.h"
-
+#include "chunk_queue.h"
 
 /** Convert in_addr to ascii. */
 #define TARGET_ADDR(oc) inet_ntoa((oc)->addr)
@@ -41,19 +41,29 @@ struct udp_target {
        int port;
        /** The socket fd. */
        int fd;
+       /** The list of queued chunks for this fd. */
+       struct chunk_queue *cq;
 };
 
 static struct list_head targets;
 static int sender_status;
 
+static void udp_close_target(struct udp_target *ut)
+{
+       if (ut->fd < 0)
+               return;
+       close(ut->fd);
+       del_close_on_fork_list(ut->fd);
+       cq_destroy(ut->cq);
+       ut->cq = NULL;
+       ut->fd = -1;
+}
+
 static void udp_delete_target(struct udp_target *ut, const char *msg)
 {
        PARA_NOTICE_LOG("deleting %s:%d (%s) from list\n", TARGET_ADDR(ut),
                ut->port, msg);
-       if (ut->fd >= 0) {
-               close(ut->fd);
-               del_close_on_fork_list(ut->fd);
-       }
+       udp_close_target(ut);
        list_del(&ut->node);
        free(ut);
 }
@@ -74,6 +84,8 @@ static void udp_send_buf(char *buf, size_t len)
        }
 }
 
+#define UDP_CQ_BYTES 40000
+
 static int udp_init_session(struct udp_target *ut)
 {
        int ret;
@@ -92,6 +104,7 @@ static int udp_init_session(struct udp_target *ut)
                return ret;
        }
        add_close_on_fork_list(ut->fd);
+       ut->cq = cq_new(UDP_CQ_BYTES);
        return 1;
 }
 
@@ -106,9 +119,7 @@ static void udp_shutdown_targets(void)
                if (ut->fd < 0)
                        continue;
                write(ut->fd, buf, UDP_AUDIO_HEADER_LEN);
-               close(ut->fd);
-               del_close_on_fork_list(ut->fd);
-               ut->fd = -1;
+               udp_close_target(ut);
        }
 }