testserver_thread.c
1015 Bytes
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
#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_ThreadedServer server = TR_new(TR_ThreadedServer, 2);
TR_Protocol protocol = TR_new(TR_ProtocolRaw);
TestHandler test_handler = TR_new(TestHandler);
//TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger2);
TR_serverAddHandler((TR_Server)server, (TR_EventHandler)test_handler);
TR_serverBindTcp((TR_Server)server, "0.0.0.0", 5678, protocol);
TR_serverBindUdp((TR_Server)server, "0.0.0.0", 5678, protocol);
TR_threadedServerStart(server, 1000);
puts("cleanup...");
TR_delete(server);
TR_delete(test_handler);
TR_delete(protocol);
TR_eventHandlerClassCleanup(TestHandler);
TR_serverClassCleanup();
TR_cleanup();
return 0;
}
// vim: set ts=4 sw=4: