]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - udp_send.c
upd_send: Add socket fd to close_on_fork list.
[paraslash.git] / udp_send.c
index 9e03b402fe18d2a9d0584c2653a8d7baeb78af35..9e8bc0482cdf79153ded26ad08777bff044f938b 100644 (file)
@@ -25,6 +25,7 @@
 #include "net.h"
 #include "fd.h"
 #include "sched.h"
+#include "close_on_fork.h"
 
 
 /** Convert in_addr to ascii. */
@@ -49,8 +50,10 @@ 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)
+       if (ut->fd >= 0) {
                close(ut->fd);
+               del_close_on_fork_list(ut->fd);
+       }
        list_del(&ut->node);
        free(ut);
 }
@@ -61,14 +64,13 @@ static void udp_send_buf(char *buf, size_t len)
        int ret;
 
        list_for_each_entry_safe(ut, tmp, &targets, node) {
-               size_t written = len;
                if (ut->fd < 0)
                        continue;
-               ret = write_all(ut->fd, buf, &written);
+               ret = write_nonblock(ut->fd, buf, len, len);
                if (ret < 0) /* TODO: Use chunk queueing */
                        return udp_delete_target(ut, "send error");
-               if (written != len)
-                       PARA_WARNING_LOG("short write %zu/%zu\n", written, len);
+               if (ret != len)
+                       PARA_WARNING_LOG("short write %zu/%zu\n", ret, len);
        }
 }
 
@@ -84,7 +86,13 @@ static int udp_init_session(struct udp_target *ut)
        if (ret < 0)
                return ret;
        ut->fd = ret;
-       return mark_fd_nonblocking(ut->fd);
+       ret = mark_fd_nonblocking(ut->fd);
+       if (ret < 0) {
+               close(ut->fd);
+               return ret;
+       }
+       add_close_on_fork_list(ut->fd);
+       return 1;
 }
 
 static void udp_shutdown_targets(void)
@@ -99,6 +107,7 @@ static void udp_shutdown_targets(void)
                        continue;
                write(ut->fd, buf, UDP_AUDIO_HEADER_LEN);
                close(ut->fd);
+               del_close_on_fork_list(ut->fd);
                ut->fd = -1;
        }
 }