diff --git a/server/include/config.h b/server/include/config.h index 7fb0cda5b..c82ce3e76 100644 --- a/server/include/config.h +++ b/server/include/config.h @@ -18,9 +18,15 @@ /** The version number of the s2ss server */ #define VERSION "v0.4-" _GIT_REV -/** Maximum number of double values in a struct msg */ +/** Maximum number of float values in a message */ #define MAX_VALUES 16 +/** Maximum number of messages in the circular history buffer */ +#define POOL_SIZE 16 + +/** Width of log output in characters */ +#define LOG_WIDTH 100 + /** Socket priority */ #define SOCKET_PRIO 7 diff --git a/server/include/log.h b/server/include/log.h index 8aea009aa..5d2856efb 100644 --- a/server/include/log.h +++ b/server/include/log.h @@ -16,9 +16,6 @@ #define INDENT ; #endif -/** Width of log output in characters */ -#define LOG_WIDTH 100 - /* The log level which is passed as first argument to print() */ #define DEBUG GRY("Debug") #define INFO "" diff --git a/server/include/path.h b/server/include/path.h index 4195855c7..2907a312f 100644 --- a/server/include/path.h +++ b/server/include/path.h @@ -42,6 +42,8 @@ struct path struct msg *current; /** A pointer to the previously received message */ struct msg *previous; + /** A circular buffer of past messages */ + struct msg *history; /** Counter for received messages according to their sequence no displacement */ struct hist histogram; @@ -94,6 +96,15 @@ int path_start(struct path *p); */ int path_stop(struct path *p); + +/** Reset internal counters and histogram of a path. + * + * @param p A pointer to the path structure. + * @retval 0 Success. Everything went well. + * @retval <0 Error. Something went wrong. + */ +int path_reset(struct path *p); + /** Show some basic statistics for a path. * * @param p A pointer to the path structure. diff --git a/server/src/log.c b/server/src/log.c index ea41e7e0b..3eac7d2b2 100644 --- a/server/src/log.c +++ b/server/src/log.c @@ -9,6 +9,7 @@ #include "log.h" #include "utils.h" +#include "config.h" /** Debug level used by the debug() macro. * It defaults to V (defined by the Makefile) and can be diff --git a/server/src/path.c b/server/src/path.c index c95f7c2d9..4e228a3f6 100644 --- a/server/src/path.c +++ b/server/src/path.c @@ -69,10 +69,6 @@ static void * path_send(void *arg) static void * path_run(void *arg) { struct path *p = arg; - - p->previous = alloc(sizeof(struct msg)); - p->current = alloc(sizeof(struct msg)); - char buf[33]; /* Open deferred TCP connection */ @@ -81,7 +77,11 @@ static void * path_run(void *arg) /* Main thread loop */ while (1) { - node_read(p->in, p->current); /* Receive message */ + /* Receive message */ + p->previous = &p->history[(p->received-1) % POOL_SIZE]; + p->current = &p->history[ p->received % POOL_SIZE]; + + node_read(p->in, p->current); p->received++; @@ -125,8 +125,6 @@ static void * path_run(void *arg) p->sent++; } - - SWAP(p->previous, p->current); } return NULL; @@ -212,6 +210,8 @@ int path_print(struct path *p, char *buf, int len) struct path * path_create() { struct path *p = alloc(sizeof(struct path)); + + p->history = alloc(POOL_SIZE * sizeof(struct msg)); list_init(&p->destinations, NULL); list_init(&p->hooks, NULL); @@ -227,7 +227,6 @@ void path_destroy(struct path *p) list_destroy(&p->hooks); hist_destroy(&p->histogram); - free(p->current); - free(p->previous); + free(p->history); free(p); }