Browse Source

simplify server interface

1.0.0
Georg Hopp 11 years ago
parent
commit
b84e10694f
  1. 1
      include/tr/datagram_entry_point.h
  2. 3
      include/tr/server.h
  3. 2
      src/Makefile.am
  4. 41
      src/server_bind_tcp.c
  5. 41
      src/server_bind_udp.c
  6. 12
      testers/testserver2.c

1
include/tr/datagram_entry_point.h

@ -30,6 +30,7 @@
#include "trdata.h" #include "trdata.h"
#include "tr/comm_end_point.h" #include "tr/comm_end_point.h"
#include "tr/datagram_service.h"
TR_CLASS(TR_DatagramEntryPoint) { TR_CLASS(TR_DatagramEntryPoint) {
TR_EXTENDS(TR_DatagramService); TR_EXTENDS(TR_DatagramService);

3
include/tr/server.h

@ -32,6 +32,7 @@
#include "tr/connector.h" #include "tr/connector.h"
#include "tr/io_handler.h" #include "tr/io_handler.h"
#include "tr/protocol_handler.h" #include "tr/protocol_handler.h"
#include "tr/protocol.h"
TR_CLASS(TR_Server) { TR_CLASS(TR_Server) {
TR_CommManager comm_manager; TR_CommManager comm_manager;
@ -49,6 +50,8 @@ TR_CLASSVARS_DECL(TR_Server) {};
#define TR_serverAddHandler(srv, handler) \ #define TR_serverAddHandler(srv, handler) \
TR_eventDispatcherRegisterHandler((srv)->dispatcher, (handler)) TR_eventDispatcherRegisterHandler((srv)->dispatcher, (handler))
void TR_serverBindTcp(TR_Server, const char *, int, TR_Protocol);
void TR_serverBindUdp(TR_Server, const char *, int, TR_Protocol);
void TR_serverStart(TR_Server, int); void TR_serverStart(TR_Server, int);
#define TR_serverClassCleanup() \ #define TR_serverClassCleanup() \

2
src/Makefile.am

@ -24,6 +24,8 @@ TRCOMM = cep_append_read_data.c \
protocol_message_raw.c \ protocol_message_raw.c \
protocol_raw.c \ protocol_raw.c \
server.c \ server.c \
server_bind_tcp.c \
server_bind_udp.c \
server_start.c \ server_start.c \
i_comm_end_point.c \ i_comm_end_point.c \
i_comm_manager.c \ i_comm_manager.c \

41
src/server_bind_tcp.c

@ -0,0 +1,41 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "trio.h"
#include "tr/server.h"
#include "tr/protocol.h"
#include "tr/connect_entry_point.h"
void
TR_serverBindTcp(TR_Server this, const char * host, int port, TR_Protocol proto)
{
TR_Socket socket = (TR_Socket)TR_new(
TR_TcpSocket,
TR_logger,
host,
port, 0);
TR_serverAddEndpoint(this, TR_new(TR_ConnEntryPoint, socket, proto));
}
// vim: set ts=4 sw=4:

41
src/server_bind_udp.c

@ -0,0 +1,41 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "trio.h"
#include "tr/server.h"
#include "tr/protocol.h"
#include "tr/datagram_entry_point.h"
void
TR_serverBindUdp(TR_Server this, const char * host, int port, TR_Protocol proto)
{
TR_Socket socket = (TR_Socket)TR_new(
TR_UdpSocket,
TR_logger,
host,
port, 0);
TR_serverAddEndpoint(this, TR_new(TR_DatagramEntryPoint, socket, proto));
}
// vim: set ts=4 sw=4:

12
testers/testserver2.c

@ -17,20 +17,12 @@ main (int argc, char * argv[])
TR_Server server = TR_new(TR_Server); TR_Server server = TR_new(TR_Server);
TR_Protocol protocol = TR_new(TR_ProtocolRaw); TR_Protocol protocol = TR_new(TR_ProtocolRaw);
TestHandler test_handler = TR_new(TestHandler); TestHandler test_handler = TR_new(TestHandler);
TR_Socket socket;
TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger); TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger);
TR_serverAddHandler(server, (TR_EventHandler)test_handler); 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_serverAddEndpoint(
server,
TR_new(TR_DatagramEntryPoint, socket, protocol));
TR_serverBindTcp(server, "0.0.0.0", 5678, protocol);
TR_serverBindUdp(server, "0.0.0.0", 5678, protocol);
TR_serverStart(server, 1000); TR_serverStart(server, 1000);

Loading…
Cancel
Save