testserver.c
2.28 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
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "trbase.h"
#include "trcomm.h"
#include "trevent.h"
#include "test_handler.h"
TR_INSTANCE(TR_LoggerSyslog, mylogger, {TR_LOGGER_DEBUG});
int
main (int argc, char * argv[])
{
TR_CommManager cmgr = (TR_CommManager)TR_new(TR_CommManagerPoll);
TR_EventDispatcher dispatcher = TR_new(TR_EventDispatcher);
TR_Connector connector = TR_new(TR_Connector);
TR_IoHandler io_handler = TR_new(TR_IoHandler);
TR_ProtocolHandler protocol_handler = TR_new(TR_ProtocolHandler);
TestHandler test_handler = TR_new(TestHandler);
TR_ConnEntryPoint tcp_ep;
TR_TcpSocket tcp_ep_sock;
TR_DatagramService udp_ep;
TR_UdpSocket udp_ep_sock;
TR_Protocol protocol;
TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger);
TR_eventDispatcherRegisterHandler(dispatcher, (TR_EventHandler)cmgr);
TR_eventDispatcherRegisterHandler(dispatcher, (TR_EventHandler)connector);
TR_eventDispatcherRegisterHandler(dispatcher, (TR_EventHandler)io_handler);
TR_eventDispatcherRegisterHandler(
dispatcher,
(TR_EventHandler)protocol_handler);
TR_eventDispatcherRegisterHandler(
dispatcher,
(TR_EventHandler)test_handler);
protocol = TR_new(TR_ProtocolRaw);
tcp_ep_sock = TR_new(TR_TcpSocket, TR_logger, "0.0.0.0", 5678, 0);
tcp_ep = TR_new(TR_ConnEntryPoint, tcp_ep_sock, protocol);
udp_ep_sock = TR_new(TR_UdpSocket, TR_logger, "0.0.0.0", 5678, 0);
TR_socketBind((TR_Socket)udp_ep_sock);
TR_socketNonblock((TR_Socket)udp_ep_sock);
udp_ep = TR_new(TR_DatagramService, udp_ep_sock, protocol);
TR_commManagerAddEndpoint(cmgr, (TR_CommEndPoint)tcp_ep);
TR_commManagerAddEndpoint(cmgr, (TR_CommEndPoint)udp_ep);
TR_eventDispatcherSetHeartbeat(dispatcher, 1000);
TR_eventDispatcherStart(dispatcher);
puts("cleanup...");
TR_delete(cmgr);
TR_delete(dispatcher);
TR_delete(connector);
TR_delete(io_handler);
TR_delete(protocol_handler);
TR_delete(test_handler);
TR_delete(protocol);
//TR_delete(ep);
TR_eventHandlerClassCleanup(TestHandler);
TR_eventHandlerClassCleanup(TR_ProtocolHandler);
TR_eventHandlerClassCleanup(TR_IoHandler);
TR_eventHandlerClassCleanup(TR_Connector);
TR_eventHandlerClassCleanup(TR_CommManagerPoll);
TR_cleanup();
return 0;
}
// vim: set ts=4 sw=4: