- 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);
- ut->fcp.slices_per_group = 16;
- ut->fcp.data_slices_per_group = 14;
- ut->fcp.max_slice_bytes = 1400;
- ut->fcp.send = udp_send_fec;
- ut->fcp.private_data = ut;
- vss_add_fec_client(&ut->fcp, &ut->fc);
+ int ret, port = scd->port > 0 ? scd->port : conf.udp_default_port_arg;
+ 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->private_data = ut;
+ ut->sc->fd = -1;
+ ret = para_connect_simple(IPPROTO_UDP, scd->host, port);
+ if (ret < 0)
+ goto err;
+ ut->sc->fd = ret;
+
+ ret = mcast_sender_setup(ut->sc);
+ if (ret < 0)
+ goto err;
+ ret = mark_fd_nonblocking(ut->sc->fd);
+ if (ret < 0)
+ goto err;
+ PARA_INFO_LOG("adding to target list (%s#%d)\n", ut->host, ut->port);
+ ut->fc = vss_add_fec_client(ut->sc, &ut->fcp);
+ para_list_add(&ut->sc->node, &targets);
+ return;
+err:
+ if (ut->sc->fd >= 0)
+ close(ut->sc->fd);
+ PARA_NOTICE_LOG("failed to set up %s#%d (%s)- not adding it\n",
+ scd->host, port, para_strerror(-ret));
+ free(ut->sc);
+ free(ut);