X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=udp_send.c;h=68d75e3c3ef87dc089a3a1eec4d59fb647e73e44;hb=HEAD;hp=eea1c93355c1461ada446942ef4d2d91f71cef46;hpb=0b786d977ded3c3922e851e5b8d60837b43469b9;p=paraslash.git diff --git a/udp_send.c b/udp_send.c index eea1c933..fe001025 100644 --- a/udp_send.c +++ b/udp_send.c @@ -18,13 +18,13 @@ #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 "send.h" #include "vss.h" #include "portable_io.h" -#include "net.h" #include "fd.h" #include "close_on_fork.h" @@ -56,9 +56,11 @@ static void udp_close_target(struct sender_client *sc) 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)) @@ -70,10 +72,14 @@ 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); @@ -164,6 +170,13 @@ static void udp_shutdown_targets(void) 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; @@ -174,7 +187,7 @@ static int udp_resolve_target(const char *url, struct sender_command_data *scd) return ret; port = scd->port > 0 ? scd->port : OPT_UINT32_VAL(UDP_DEFAULT_PORT); - ret = para_connect_simple(IPPROTO_UDP, scd->host, port); + ret = para_connect(IPPROTO_UDP, scd->host, port); if (ret < 0) return ret; @@ -236,7 +249,7 @@ static int udp_init_fec(struct sender_client *sc) 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); @@ -313,8 +326,8 @@ static int udp_com_add(struct sender_command_data *scd) 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; @@ -323,7 +336,7 @@ static int udp_com_add(struct sender_command_data *scd) sc->private_data = ut; sc->fd = -1; - ret = para_connect_simple(IPPROTO_UDP, scd->host, scd->port); + ret = para_connect(IPPROTO_UDP, scd->host, scd->port); if (ret < 0) goto err; sc->fd = ret; @@ -382,7 +395,7 @@ static void udp_init_target_list(void) struct sender_command_data scd; int i; - INIT_LIST_HEAD(&targets); + 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) @@ -415,7 +428,7 @@ static char *udp_help(void) /* Initialize the list of udp targets. */ static void udp_send_init(void) { - INIT_LIST_HEAD(&targets); + init_list_head(&targets); sender_status = SENDER_off; udp_init_target_list(); if (!OPT_GIVEN(UDP_NO_AUTOSTART)) @@ -435,6 +448,7 @@ static void udp_send_init(void) 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 = {