testclient.c
1.66 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
#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"
TR_INSTANCE(TR_LoggerSyslog, mylogger, {TR_LOGGER_INFO});
TR_INSTANCE(TR_LoggerStderr, mylogger2, {TR_LOGGER_INFO});
int
main (int argc, char * argv[])
{
TR_TcpSocket socket;
TR_Connection connection;
TR_SimpleClient client;
TR_Protocol protocol;
TR_ProtoMessageRaw message;
int i;
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);
connection = TR_new(TR_Connection, socket, protocol);
TR_socketConnect((TR_Socket)socket);
TR_socketNonblock((TR_Socket)socket);
client = TR_new(TR_SimpleClient, connection);
for (i=0; i<10000000; 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,
100);
if (! message) break;
#if 0
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", '.');
}
}
} else {
printf("%c", 'f');
}
#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: