From: Sven M. Hallberg Date: Thu, 6 Nov 2014 17:38:27 +0000 (+0100) Subject: add more and timestamped debug output to channels test X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=35c4e5f2158d4fc32febb34f06f1bd21e1bb69fc;p=meshlink add more and timestamped debug output to channels test --- diff --git a/test/channels.c b/test/channels.c index 9c3e35b5..284a13b7 100644 --- a/test/channels.c +++ b/test/channels.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "../src/meshlink.h" @@ -9,22 +10,33 @@ volatile bool bar_reachable = false; volatile bool bar_responded = false; void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) { + static struct timeval tv0; + struct timeval tv; + + if(tv0.tv_sec == 0) + gettimeofday(&tv0, NULL); + gettimeofday(&tv, NULL); + fprintf(stderr, "%u.%.03u ", (unsigned int)(tv.tv_sec-tv0.tv_sec), (unsigned int)tv.tv_usec/1000); + if(mesh) fprintf(stderr, "(%s) ", mesh->name); fprintf(stderr, "[%d] %s\n", level, text); } void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { + printf("status_cb: %s %sreachable\n", node->name, reachable?"":"un"); if(!strcmp(node->name, "bar")) bar_reachable = reachable; } void foo_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { + printf("foo_receive_cb %zu: ", len); fwrite(data, 1, len, stdout); printf("\n"); if(len == 5 && !memcmp(data, "Hello", 5)) bar_responded = true; } void bar_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { + printf("bar_receive_cb %zu: ", len); fwrite(data, 1, len, stdout); // Echo the data back. meshlink_channel_send(mesh, channel, data, len); } @@ -34,6 +46,9 @@ bool reject_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t po } bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) { + printf("accept_cb: (from %s on port %u) ", channel->node->name, (unsigned int)port); + if(data) { fwrite(data, 1, len, stdout); printf("\n"); } + if(port != 7) return false; meshlink_set_channel_receive_cb(mesh, channel, bar_receive_cb); @@ -65,6 +80,9 @@ int main(int argc, char *argv[]) { return 1; } + meshlink_set_log_cb(mesh1, MESHLINK_DEBUG, log_cb); + meshlink_set_log_cb(mesh2, MESHLINK_DEBUG, log_cb); + // Import and export both side's data meshlink_add_address(mesh1, "localhost");