From ea8637495205d96f4731c6c58662cd993a4674ca Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Mon, 22 Sep 2014 21:23:24 +0100 Subject: [PATCH] add udp code into testclient --- testers/testclient.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/testers/testclient.c b/testers/testclient.c index d133ee0..cee1b2f 100644 --- a/testers/testclient.c +++ b/testers/testclient.c @@ -9,30 +9,46 @@ #include "test_handler.h" +#define ITERATIONS 10000000 +int spinner[] = {'|', '/', '-', '\\'}; + TR_INSTANCE(TR_LoggerSyslog, mylogger, {TR_LOGGER_INFO}); TR_INSTANCE(TR_LoggerStderr, mylogger2, {TR_LOGGER_INFO}); +#define UDP 1 + int main (int argc, char * argv[]) { +#if UDP + TR_UdpSocket socket; + TR_DatagramService connection; +#else TR_TcpSocket socket; TR_Connection connection; +#endif TR_SimpleClient client; TR_Protocol protocol; TR_ProtoMessageRaw message; - int i; + int i, j=0; TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger2); - socket = TR_new(TR_TcpSocket, TR_logger, "192.168.2.13", 5678, 0); protocol = TR_new(TR_ProtocolRaw); +#if UDP + socket = TR_new(TR_UdpSocket, TR_logger, "127.0.0.1", 5678, 0); + connection = TR_new(TR_DatagramService, socket, protocol); + TR_socketOpen((TR_Socket)socket); +#else + socket = TR_new(TR_TcpSocket, TR_logger, "127.0.0.1", 5678, 0); connection = TR_new(TR_Connection, socket, protocol); - TR_socketConnect((TR_Socket)socket); +#endif + TR_socketNonblock((TR_Socket)socket); client = TR_new(TR_SimpleClient, connection); - for (i=0; i<10000000; i++) { + for (i=0; isize = sizeof("test"); @@ -49,15 +65,15 @@ main (int argc, char * argv[]) printf("%s\n", message->data); #else if (0 == strncmp("test", message->data, sizeof("test")-1)) { - if (i % 1000 == 0) { - if (i % 10000 == 0) { - printf("%c", '#'); - } else { - printf("%c", '.'); - } + if (i % (ITERATIONS/80) == 0) { + if (j != 0) putchar('\b'); + printf("%c%c", '.', spinner[j%4]); + } else { + printf("%c%c", '\b', spinner[j%4]); } + j++; } else { - printf("%c", 'f'); + printf("%c%c", 'f', spinner[i%4]); } #endif fflush(stdout);