]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - udp_send.c
udp_send: Do not send the current chunk if queue is not empty.
[paraslash.git] / udp_send.c
index 5c1cdf02c2fb9e1be95783f65cfeb12994a15056..49f84acdd156e870d7ec5219e1400dff07aa61d4 100644 (file)
@@ -11,6 +11,7 @@
 #include <sys/time.h>
 #include <dirent.h>
 #include <sys/socket.h>
+#include <netinet/udp.h>
 #include <net/if.h>
 #include <osl.h>
 
@@ -232,6 +233,19 @@ static int udp_com_delete(struct sender_command_data *scd)
        return 1;
 }
 
+/** Initialize UDP session and set maximum payload size. */
+static int udp_init_fec(struct sender_client *sc)
+{
+       int mps, ret = udp_init_session(sc);
+
+       if (ret < 0)
+               return ret;
+
+       mps = generic_max_transport_msg_size(sc->fd) - sizeof(struct udphdr);
+       PARA_INFO_LOG("current MPS = %d bytes\n", mps);
+       return mps;
+}
+
 static int udp_send_fec(struct sender_client *sc, char *buf, size_t len)
 {
        struct udp_target *ut = sc->private_data;
@@ -239,10 +253,7 @@ static int udp_send_fec(struct sender_client *sc, char *buf, size_t len)
 
        if (sender_status == SENDER_OFF)
                return 0;
-       ret = udp_init_session(sc);
-       if (ret < 0)
-               goto fail;
-       ret = send_queued_chunks(sc->fd, sc->cq, 0);
+       ret = send_queued_chunks(sc->fd, sc->cq);
        if (ret == -ERRNO_TO_PARA_ERROR(ECONNREFUSED))
                ret = 0;
        if (ret < 0)
@@ -252,8 +263,9 @@ static int udp_send_fec(struct sender_client *sc, char *buf, size_t len)
        if (!ret) { /* still data left in the queue */
                ret = cq_force_enqueue(sc->cq, buf, len);
                assert(ret >= 0);
+               return 0;
        }
-       ret = write_nonblock(sc->fd, buf, len, 0);
+       ret = write_nonblock(sc->fd, buf, len);
        if (ret == -ERRNO_TO_PARA_ERROR(ECONNREFUSED))
                ret = 0;
        if (ret < 0)
@@ -278,7 +290,7 @@ static void udp_add_target(struct sender_command_data *scd)
        ut->fcp.slices_per_group      = scd->slices_per_group;
        ut->fcp.data_slices_per_group = scd->data_slices_per_group;
        ut->fcp.max_slice_bytes       = scd->max_slice_bytes;
-       ut->fcp.init_fec              = NULL; /* FIXME */
+       ut->fcp.init_fec              = udp_init_fec;
        ut->fcp.send_fec              = udp_send_fec;
 
        ut->sc = para_calloc(sizeof(*ut->sc));