- struct udp_target *ut = para_calloc(sizeof(struct udp_target));
-
- strncpy(ut->host, host, sizeof(ut->host));
- ut->port = port > 0 ? port : conf.udp_default_port_arg;
- ut->fd = -1; /* not yet connected */
- PARA_INFO_LOG("adding to target list (%s#%d)\n",
- ut->host, ut->port);
- para_list_add(&ut->node, &targets);
+ 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;
+ int ret;
+
+ if (sender_status == SENDER_OFF)
+ return 0;
+ ret = send_queued_chunks(sc->fd, sc->cq);
+ if (ret == -ERRNO_TO_PARA_ERROR(ECONNREFUSED))
+ ret = 0;
+ if (ret < 0)
+ goto fail;
+ if (!len)
+ return 0;
+ if (!ret) { /* still data left in the queue */
+ ret = cq_force_enqueue(sc->cq, buf, len);
+ assert(ret >= 0);
+ }
+ ret = write_nonblock(sc->fd, buf, len);
+ if (ret == -ERRNO_TO_PARA_ERROR(ECONNREFUSED))
+ ret = 0;
+ if (ret < 0)
+ goto fail;
+ if (ret != len) {
+ ret = cq_force_enqueue(sc->cq, buf + ret, len - ret);
+ assert(ret >= 0);
+ }
+ return 1;
+fail:
+ udp_delete_target(ut, para_strerror(-ret));
+ return ret;
+}
+
+static void udp_add_target(struct sender_command_data *scd)
+{
+ struct udp_target *ut = para_calloc(sizeof(*ut));
+
+ strncpy(ut->host, scd->host, sizeof(ut->host));
+ ut->port = scd->port > 0 ? scd->port : conf.udp_default_port_arg;
+
+ 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 = udp_init_fec;
+ ut->fcp.send_fec = udp_send_fec;
+
+ ut->sc = para_calloc(sizeof(*ut->sc));
+ ut->sc->fd = -1; /* not yet connected */
+ ut->sc->private_data = ut;
+ ut->fc = vss_add_fec_client(ut->sc, &ut->fcp);
+
+ PARA_INFO_LOG("adding to target list (%s#%d)\n", ut->host, ut->port);
+ para_list_add(&ut->sc->node, &targets);