-/*
- * Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
/** \file udp_send.c Para_server's udp sender. */
#include <arpa/inet.h>
#include <sys/un.h>
#include <netdb.h>
+#include <lopsub.h>
-#include "server.cmdline.h"
+#include "server.lsg.h"
#include "para.h"
#include "error.h"
#include "string.h"
#include "afh.h"
+#include "net.h"
#include "server.h"
#include "list.h"
#include "send.h"
#include "sched.h"
#include "vss.h"
#include "portable_io.h"
-#include "net.h"
#include "fd.h"
#include "close_on_fork.h"
size_t len;
struct udp_target *ut = sc->private_data;
+ if (process_is_command_handler())
+ return;
if (ut->sent_fec_eof)
return;
- PARA_NOTICE_LOG("sending FEC EOF\n");
+ PARA_INFO_LOG("sending FEC EOF\n");
len = vss_get_fec_eof_packet(&buf);
/* Ignore write() errors since we are closing the target anyway. */
- if (write(sc->fd, buf, len) == len)
- ut->sent_fec_eof = true;
+ if (write(sc->fd, buf, len))
+ do_nothing; /* avoid "ignoring return value" warning */
+ ut->sent_fec_eof = true;
}
static void udp_delete_target(struct sender_client *sc, const char *msg)
{
struct udp_target *ut = sc->private_data;
- PARA_NOTICE_LOG("deleting %s (%s) from list\n", sc->name, msg);
+ if (!process_is_command_handler())
+ PARA_NOTICE_LOG("deleting %s (%s) from list\n", sc->name, msg);
udp_close_target(sc);
- close(sc->fd);
- del_close_on_fork_list(sc->fd);
+ /* command handlers already called close_listed_fds() */
+ if (!process_is_command_handler()) {
+ close(sc->fd);
+ del_close_on_fork_list(sc->fd);
+ }
vss_del_fec_client(ut->fc);
list_del(&sc->node);
free(sc->name);
{
struct sockaddr_storage ss;
socklen_t sslen = sizeof(ss);
- int ttl = conf.udp_ttl_arg, id = 0;
+ int ttl = OPT_INT32_VAL(UDP_TTL), id = 0;
const int on = 1;
- if (conf.udp_mcast_iface_given) {
- char *iface = conf.udp_mcast_iface_arg;
+ if (OPT_GIVEN(UDP_MCAST_IFACE)) {
+ const char *iface = OPT_STRING_VAL(UDP_MCAST_IFACE);
id = if_nametoindex(iface);
if (id == 0)
udp_close_target(sc);
}
+static void udp_shutdown(void)
+{
+ struct sender_client *sc, *tmp;
+ list_for_each_entry_safe(sc, tmp, &targets, node)
+ udp_delete_target(sc, "shutdown");
+}
+
static int udp_resolve_target(const char *url, struct sender_command_data *scd)
{
const char *result;
ret = parse_fec_url(url, scd);
if (ret)
return ret;
- port = scd->port > 0 ? scd->port : conf.udp_default_port_arg;
+ port = scd->port > 0 ? scd->port : OPT_UINT32_VAL(UDP_DEFAULT_PORT);
ret = para_connect_simple(IPPROTO_UDP, scd->host, port);
if (ret < 0)
struct udp_target *ut = sc->private_data;
int mps;
- PARA_NOTICE_LOG("sending to udp %s\n", sc->name);
+ PARA_INFO_LOG("sending to udp %s\n", sc->name);
ut->sent_fec_eof = false;
mps = generic_max_transport_msg_size(sc->fd) - sizeof(struct udphdr);
PARA_INFO_LOG("current MPS = %d bytes\n", mps);
sc->name);
return -E_TARGET_EXISTS;
}
- ut = para_calloc(sizeof(*ut));
- sc = para_calloc(sizeof(*sc));
+ ut = zalloc(sizeof(*ut));
+ sc = zalloc(sizeof(*sc));
ut->fcp.slices_per_group = scd->slices_per_group;
ut->fcp.data_slices_per_group = scd->data_slices_per_group;
ut->fcp.init_fec = udp_init_fec;
"port: %s\n"
"targets: %s\n",
(sender_status == SENDER_on)? "on" : "off",
- stringify_port(conf.udp_default_port_arg, "udp"),
+ stringify_port(OPT_UINT32_VAL(UDP_DEFAULT_PORT), "udp"),
tgts? tgts : "(none)"
);
free(tgts);
struct sender_command_data scd;
int i;
- INIT_LIST_HEAD(&targets);
- for (i = 0; i < conf.udp_target_given; i++) {
- if (udp_resolve_target(conf.udp_target_arg[i], &scd) < 0)
+ init_list_head(&targets);
+ for (i = 0; i < OPT_GIVEN(UDP_TARGET); i++) {
+ const char *arg = lls_string_val(i, OPT_RESULT(UDP_TARGET));
+ if (udp_resolve_target(arg, &scd) < 0)
PARA_CRIT_LOG("not adding requested target '%s'\n",
- conf.udp_target_arg[i]);
+ arg);
else
udp_com_add(&scd);
}
);
}
-/**
- * The init function of para_server's udp sender.
- *
- * \param s Pointer to the udp sender struct.
- *
- * It initializes all function pointers of \a s and the list of udp targets.
- */
-void udp_send_init(struct sender *s)
+/* Initialize the list of udp targets. */
+static void udp_send_init(void)
{
- INIT_LIST_HEAD(&targets);
- s->status = udp_status;
- s->help = udp_help;
- s->send = NULL;
- s->pre_select = NULL;
- s->post_select = NULL;
- s->shutdown_clients = udp_shutdown_targets;
- s->resolve_target = udp_resolve_target;
- s->client_cmds[SENDER_on] = udp_com_on;
- s->client_cmds[SENDER_off] = udp_com_off;
- s->client_cmds[SENDER_deny] = NULL;
- s->client_cmds[SENDER_allow] = NULL;
- s->client_cmds[SENDER_add] = udp_com_add;
- s->client_cmds[SENDER_delete] = udp_com_delete;
+ init_list_head(&targets);
sender_status = SENDER_off;
udp_init_target_list();
- if (!conf.udp_no_autostart_given)
+ if (!OPT_GIVEN(UDP_NO_AUTOSTART))
sender_status = SENDER_on;
PARA_DEBUG_LOG("udp sender init complete\n");
}
+
+/**
+ * The UDP sender.
+ *
+ * In contrast to the other senders the UDP sender is active in the sense that
+ * it initiates the network connection according to its list of targets rather
+ * than passively waiting for clients to connect. Like DCCP streams, UDP
+ * streams are always sent FEC-encoded. The UDP sender is the only sender which
+ * supports IP multicasting.
+ */
+const struct sender udp_sender = {
+ .name = "udp",
+ .init = udp_send_init,
+ .shutdown = udp_shutdown,
+ .shutdown_clients = udp_shutdown_targets,
+ .resolve_target = udp_resolve_target,
+ .client_cmds = {
+ [SENDER_on] = udp_com_on,
+ [SENDER_off] = udp_com_off,
+ [SENDER_add] = udp_com_add,
+ [SENDER_delete] = udp_com_delete,
+ },
+ .help = udp_help,
+ .status = udp_status,
+};