From 7094edd6baf0d69c3879da7f16c7222388952931 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Mon, 18 Jan 2010 15:57:33 +0100 Subject: error handling in C perf tests improved --- perf/c/remote_lat.c | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'perf/c/remote_lat.c') diff --git a/perf/c/remote_lat.c b/perf/c/remote_lat.c index 0c0a9f1..901afd5 100644 --- a/perf/c/remote_lat.c +++ b/perf/c/remote_lat.c @@ -21,7 +21,6 @@ #include #include #include -#include int main (int argc, char *argv []) { @@ -47,32 +46,56 @@ int main (int argc, char *argv []) roundtrip_count = atoi (argv [3]); ctx = zmq_init (1, 1, 0); - assert (ctx); + if (!ctx) { + printf ("error in zmq_init: %s\n", zmq_strerror (errno)); + return -1; + } s = zmq_socket (ctx, ZMQ_REQ); - assert (s); + if (!s) { + printf ("error in zmq_socket: %s\n", zmq_strerror (errno)); + return -1; + } rc = zmq_connect (s, connect_to); - assert (rc == 0); + if (rc != 0) { + printf ("error in zmq_connect: %s\n", zmq_strerror (errno)); + return -1; + } rc = zmq_msg_init_size (&msg, message_size); - assert (rc == 0); + if (rc != 0) { + printf ("error in zmq_msg_init_size: %s\n", zmq_strerror (errno)); + return -1; + } memset (zmq_msg_data (&msg), 0, message_size); watch = zmq_stopwatch_start (); for (i = 0; i != roundtrip_count; i++) { rc = zmq_send (s, &msg, 0); - assert (rc == 0); + if (rc != 0) { + printf ("error in zmq_send: %s\n", zmq_strerror (errno)); + return -1; + } rc = zmq_recv (s, &msg, 0); - assert (rc == 0); - assert (zmq_msg_size (&msg) == message_size); + if (rc != 0) { + printf ("error in zmq_recv: %s\n", zmq_strerror (errno)); + return -1; + } + if (zmq_msg_size (&msg) != message_size) { + printf ("message of incorrect size received\n"); + return -1; + } } elapsed = zmq_stopwatch_stop (watch); rc = zmq_msg_close (&msg); - assert (rc == 0); + if (rc != 0) { + printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno)); + return -1; + } latency = (double) elapsed / (roundtrip_count * 2); @@ -81,10 +104,16 @@ int main (int argc, char *argv []) printf ("average latency: %.3f [us]\n", (double) latency); rc = zmq_close (s); - assert (rc == 0); + if (rc != 0) { + printf ("error in zmq_close: %s\n", zmq_strerror (errno)); + return -1; + } rc = zmq_term (ctx); - assert (rc == 0); + if (rc != 0) { + printf ("error in zmq_term: %s\n", zmq_strerror (errno)); + return -1; + } return 0; } -- cgit v1.2.3