diff --git a/server/include/node.h b/server/include/node.h index c498b080f..8531c9f1f 100644 --- a/server/include/node.h +++ b/server/include/node.h @@ -29,7 +29,6 @@ /* Helper macros for virtual node type */ #define node_type(n) ((n)->_vt->type) #define node_parse(n, cfg) ((n)->_vt->parse(cfg, n)) -#define node_print(n) ((n)->_vt->print(n)) #define node_read(n, p, ps, f, c) ((n)->_vt->read(n, p, ps, f, c)) #define node_write(n, p, ps, f, c) ((n)->_vt->write(n, p, ps, f, c)) @@ -163,6 +162,7 @@ struct node_type { struct node { const char *name; /**< A short identifier of the node, only used for configuration and logging */ + char *_print; /**< A string used to print to screen. */ int refcnt; /**< How many paths are sending / receiving from this node? */ int combine; /**< Number of messages to send / recv at once (scatter / gather) */ @@ -206,13 +206,8 @@ int node_deinit(); */ int node_start(struct node *n); -/** Deferred TCP connection setup - * - * @todo Dirty hack! - * We should check the address of the connecting node! - * We should preserve the original socket for proper shutdown. - */ -int node_start_defer(struct node *n); +/** Return a pointer to a string which should be used to print this node */ +char * node_print(struct node *n); /** Stops a node. * diff --git a/server/include/path.h b/server/include/path.h index f0a873065..c536481a5 100644 --- a/server/include/path.h +++ b/server/include/path.h @@ -53,6 +53,8 @@ struct path config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this path */ + char *_print; /**< A string which is used to print this path to screen. */ + /** The following fields are mostly managed by hook_ functions @{ */ struct hist hist_owd; /**< Histogram for one-way-delay (OWD) of received messages */ diff --git a/server/src/cfg.c b/server/src/cfg.c index 493f6ff52..d8727234a 100644 --- a/server/src/cfg.c +++ b/server/src/cfg.c @@ -186,9 +186,7 @@ int config_parse_path(config_setting_t *cfg, } } else { - char *buf = path_print(p); - warn("Path %s is not enabled", buf); - free(buf); + warn("Path %s is not enabled", path_print(p)); path_destroy(p); } diff --git a/server/src/hooks.c b/server/src/hooks.c index 2eeb8f0f4..92454915f 100644 --- a/server/src/hooks.c +++ b/server/src/hooks.c @@ -273,10 +273,8 @@ int hook_restart(struct path *p, struct hook *h, int when) { if (p->current->sequence == 0 && p->previous->sequence <= UINT32_MAX - 32) { - char *buf = path_print(p); warn("Simulation for path %s restarted (prev->seq=%u, current->seq=%u)", - buf, p->previous->sequence, p->current->sequence); - free(buf); + path_print(p), p->previous->sequence, p->current->sequence); p->sent = p->invalid = @@ -378,6 +376,7 @@ int hook_stats(struct path *p, struct hook *h, int when) if (p->received > 1) stats("%-40.40s|%10.2g|%10.2f|%10u|%10u|%10u|%10u|%10u|%10u|%10u|", buf, + stats("%-40.40s|%10.2g|%10.2f|%10u|%10u|%10u|%10u|%10u|%10u|%10u|", path_print(p), p->hist_owd.last, 1 / p->hist_gap_msg.last, p->sent, p->received, p->dropped, p->skipped, p->invalid, p->overrun, list_length(p->current) ); diff --git a/server/src/node.c b/server/src/node.c index 9e2fe00ad..714c8710c 100644 --- a/server/src/node.c +++ b/server/src/node.c @@ -65,9 +65,7 @@ int node_start(struct node *n) return -1; } - char *buf = node_print(n); - debug(1, "Starting node '%s' of type '%s' (%s)", n->name, n->_vt->name, buf); - free(buf); + debug(1, "Starting node '%s' of type '%s' (%s)", n->name, n->_vt->name, node_print(n)); { INDENT return node_open(n); @@ -90,6 +88,14 @@ int node_stop(struct node *n) return ret; } +char * node_print(struct node *n) +{ + if (!n->_print) + n->_print = n->_vt->print(n); + + return n->_print; +} + void node_reverse(struct node *n) { switch (node_type(n)) { @@ -131,6 +137,7 @@ void node_destroy(struct node *n) default: { } } + free(n->_print); free(n->socket); free(n); } diff --git a/server/src/path.c b/server/src/path.c index 5d2616f97..7658e621c 100644 --- a/server/src/path.c +++ b/server/src/path.c @@ -139,10 +139,8 @@ static void * path_run(void *arg) int path_start(struct path *p) { INDENT - char *buf = path_print(p); info("Starting path: %s (poolsize=%u, msgsize=%u, #hooks=%zu, rate=%.1f)", - buf, p->poolsize, p->msgsize, list_length(&p->hooks), p->rate); - free(buf); + path_print(p), p->poolsize, p->msgsize, list_length(&p->hooks), p->rate); /* We sort the hooks according to their priority before starting the path */ list_sort(&p->hooks, ({int cmp(const void *a, const void *b) { @@ -174,9 +172,7 @@ int path_start(struct path *p) int path_stop(struct path *p) { INDENT - char *buf = path_print(p); - info("Stopping path: %s", buf); - free(buf); + info("Stopping path: %s", path_print(p)); pthread_cancel(p->recv_tid); pthread_join(p->recv_tid, NULL); @@ -196,14 +192,16 @@ int path_stop(struct path *p) char * path_print(struct path *p) { - char *buf = alloc(32); + if (!p->_print) { + char *buf = alloc(64); - strcatf(&buf, "%s " MAG("=>"), p->in->name); + strcatf(&buf, "%s " MAG("=>"), p->in->name); - list_foreach(struct node *n, &p->destinations) - strcatf(&buf, " %s", n->name); + list_foreach(struct node *n, &p->destinations) + strcatf(&buf, " %s", n->name); + } - return buf; + return p->_print; } struct path * path_create() @@ -228,6 +226,7 @@ void path_destroy(struct path *p) list_destroy(&p->destinations); list_destroy(&p->hooks); + free(p->_print); free(p->pool); free(p); }