testclient.c
2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "trbase.h"
#include "trcomm.h"
#include "trio.h"
#include "trevent.h"
#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});
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, j=0;
//TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger2);
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<ITERATIONS; i++) {
message = (TR_ProtoMessageRaw)TR_protoCreateRequest(
protocol, (TR_Socket)socket);
message->size = sizeof("test");
message->data = TR_malloc(message->size);
memcpy(message->data, "test", sizeof("test"));
message = (TR_ProtoMessageRaw)TR_simpleClientIssue(
client,
(TR_ProtoMessage)message,
100000000000000000);
if (! message) break;
#if 0
printf("%s\n", message->data);
#else
if (0 == strncmp("test", message->data, sizeof("test")-1)) {
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%c", 'f', spinner[i%4]);
}
#endif
fflush(stdout);
TR_delete(message);
}
puts("");
puts("cleanup...");
TR_delete(client);
TR_delete(protocol);
TR_simpleClientClassCleanup();
TR_cleanup();
return 0;
}
// vim: set ts=4 sw=4: