Browse Source

add udp code into testclient

1.0.0
Georg Hopp 11 years ago
parent
commit
ea86374952
  1. 38
      testers/testclient.c

38
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; i<ITERATIONS; i++) {
message = (TR_ProtoMessageRaw)TR_protoCreateRequest(
protocol, (TR_Socket)socket);
message->size = 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);

Loading…
Cancel
Save