testserver2.c 1.17 KB
#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_DEBUG});

int
main (int argc, char * argv[])
{
	TR_Server    server       = TR_new(TR_Server);
	TR_Protocol  protocol     = TR_new(TR_ProtocolRaw);
	TestHandler  test_handler = TR_new(TestHandler);
	TR_Socket    socket;

	TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger);

	TR_serverAddHandler(server, (TR_EventHandler)test_handler);
	socket = (TR_Socket)TR_new(TR_TcpSocket, TR_logger, "0.0.0.0", 5678, 0);
	TR_serverAddEndpoint(
			server, 
			TR_new(TR_ConnEntryPoint, socket, protocol));

	socket = TR_new(TR_UdpSocket, TR_logger, "0.0.0.0", 5678, 0);
	TR_socketBind((TR_Socket)socket);
	TR_socketNonblock((TR_Socket)socket);
	TR_serverAddEndpoint(
			server, 
			TR_new(TR_DatagramService, socket, protocol));

	TR_serverStart(server, 1000);

	puts("cleanup...");

	TR_delete(server);
	TR_delete(test_handler);
	TR_delete(protocol);
	//TR_delete(ep);

	TR_eventHandlerClassCleanup(TestHandler);
	TR_serverClassCleanup();

	TR_cleanup();

	return 0;
}

// vim: set ts=4 sw=4: