Implement chunk queing for the udp sender.
authorAndre Noll <maan@systemlinux.org>
Sat, 10 Jan 2009 17:36:59 +0000 (18:36 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 10 Jan 2009 17:36:59 +0000 (18:36 +0100)
udp_send.c

index 7704b0a..1408ae7 100644 (file)
@@ -76,13 +76,32 @@ static void udp_send_buf(char *buf, size_t len)
        list_for_each_entry_safe(ut, tmp, &targets, node) {
                if (ut->fd < 0)
                        continue;
-               ret = write_nonblock(ut->fd, buf, len, len);
+               ret = send_queued_chunks(ut->fd, ut->cq, 0);
                if (ret < 0) {
                        udp_delete_target(ut, para_strerror(-ret));
                        continue;
                }
-               if (ret != len)
-                       PARA_WARNING_LOG("short write %zu/%zu\n", ret, len);
+               if (!len)
+                       continue;
+               if (!ret) { /* still data left in the queue */
+                       ret = cq_enqueue(ut->cq, buf, len);
+                       if (ret < 0) {
+                               udp_delete_target(ut, para_strerror(-ret));
+                               continue;
+                       }
+               }
+               ret = write_nonblock(ut->fd, buf, len, 0);
+               if (ret < 0) {
+                       udp_delete_target(ut, para_strerror(-ret));
+                       continue;
+               }
+               if (ret != len) {
+                       ret = cq_enqueue(ut->cq, buf + ret, len - ret);
+                       if (ret < 0) {
+                               udp_delete_target(ut, para_strerror(-ret));
+                               continue;
+                       }
+               }
        }
 }