Commit ea8637495205d96f4731c6c58662cd993a4674ca

Authored by Georg Hopp
1 parent d9e22a9a

add udp code into testclient

Showing 1 changed file with 27 additions and 11 deletions
@@ -9,30 +9,46 @@ @@ -9,30 +9,46 @@
9 9
10 #include "test_handler.h" 10 #include "test_handler.h"
11 11
  12 +#define ITERATIONS 10000000
  13 +int spinner[] = {'|', '/', '-', '\\'};
  14 +
12 TR_INSTANCE(TR_LoggerSyslog, mylogger, {TR_LOGGER_INFO}); 15 TR_INSTANCE(TR_LoggerSyslog, mylogger, {TR_LOGGER_INFO});
13 TR_INSTANCE(TR_LoggerStderr, mylogger2, {TR_LOGGER_INFO}); 16 TR_INSTANCE(TR_LoggerStderr, mylogger2, {TR_LOGGER_INFO});
14 17
  18 +#define UDP 1
  19 +
15 int 20 int
16 main (int argc, char * argv[]) 21 main (int argc, char * argv[])
17 { 22 {
  23 +#if UDP
  24 + TR_UdpSocket socket;
  25 + TR_DatagramService connection;
  26 +#else
18 TR_TcpSocket socket; 27 TR_TcpSocket socket;
19 TR_Connection connection; 28 TR_Connection connection;
  29 +#endif
20 TR_SimpleClient client; 30 TR_SimpleClient client;
21 TR_Protocol protocol; 31 TR_Protocol protocol;
22 TR_ProtoMessageRaw message; 32 TR_ProtoMessageRaw message;
23 - int i; 33 + int i, j=0;
24 34
25 TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger2); 35 TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger2);
26 - socket = TR_new(TR_TcpSocket, TR_logger, "192.168.2.13", 5678, 0);  
27 protocol = TR_new(TR_ProtocolRaw); 36 protocol = TR_new(TR_ProtocolRaw);
  37 +#if UDP
  38 + socket = TR_new(TR_UdpSocket, TR_logger, "127.0.0.1", 5678, 0);
  39 + connection = TR_new(TR_DatagramService, socket, protocol);
  40 + TR_socketOpen((TR_Socket)socket);
  41 +#else
  42 + socket = TR_new(TR_TcpSocket, TR_logger, "127.0.0.1", 5678, 0);
28 connection = TR_new(TR_Connection, socket, protocol); 43 connection = TR_new(TR_Connection, socket, protocol);
29 -  
30 TR_socketConnect((TR_Socket)socket); 44 TR_socketConnect((TR_Socket)socket);
  45 +#endif
  46 +
31 TR_socketNonblock((TR_Socket)socket); 47 TR_socketNonblock((TR_Socket)socket);
32 48
33 client = TR_new(TR_SimpleClient, connection); 49 client = TR_new(TR_SimpleClient, connection);
34 50
35 - for (i=0; i<10000000; i++) { 51 + for (i=0; i<ITERATIONS; i++) {
36 message = (TR_ProtoMessageRaw)TR_protoCreateRequest( 52 message = (TR_ProtoMessageRaw)TR_protoCreateRequest(
37 protocol, (TR_Socket)socket); 53 protocol, (TR_Socket)socket);
38 message->size = sizeof("test"); 54 message->size = sizeof("test");
@@ -49,15 +65,15 @@ main (int argc, char * argv[]) @@ -49,15 +65,15 @@ main (int argc, char * argv[])
49 printf("%s\n", message->data); 65 printf("%s\n", message->data);
50 #else 66 #else
51 if (0 == strncmp("test", message->data, sizeof("test")-1)) { 67 if (0 == strncmp("test", message->data, sizeof("test")-1)) {
52 - if (i % 1000 == 0) {  
53 - if (i % 10000 == 0) {  
54 - printf("%c", '#');  
55 - } else {  
56 - printf("%c", '.');  
57 - } 68 + if (i % (ITERATIONS/80) == 0) {
  69 + if (j != 0) putchar('\b');
  70 + printf("%c%c", '.', spinner[j%4]);
  71 + } else {
  72 + printf("%c%c", '\b', spinner[j%4]);
58 } 73 }
  74 + j++;
59 } else { 75 } else {
60 - printf("%c", 'f'); 76 + printf("%c%c", 'f', spinner[i%4]);
61 } 77 }
62 #endif 78 #endif
63 fflush(stdout); 79 fflush(stdout);
Please register or login to post a comment