Showing
6 changed files
with
90 additions
and
10 deletions
@@ -30,6 +30,7 @@ | @@ -30,6 +30,7 @@ | ||
30 | #include "trdata.h" | 30 | #include "trdata.h" |
31 | 31 | ||
32 | #include "tr/comm_end_point.h" | 32 | #include "tr/comm_end_point.h" |
33 | +#include "tr/datagram_service.h" | ||
33 | 34 | ||
34 | TR_CLASS(TR_DatagramEntryPoint) { | 35 | TR_CLASS(TR_DatagramEntryPoint) { |
35 | TR_EXTENDS(TR_DatagramService); | 36 | TR_EXTENDS(TR_DatagramService); |
@@ -32,6 +32,7 @@ | @@ -32,6 +32,7 @@ | ||
32 | #include "tr/connector.h" | 32 | #include "tr/connector.h" |
33 | #include "tr/io_handler.h" | 33 | #include "tr/io_handler.h" |
34 | #include "tr/protocol_handler.h" | 34 | #include "tr/protocol_handler.h" |
35 | +#include "tr/protocol.h" | ||
35 | 36 | ||
36 | TR_CLASS(TR_Server) { | 37 | TR_CLASS(TR_Server) { |
37 | TR_CommManager comm_manager; | 38 | TR_CommManager comm_manager; |
@@ -49,6 +50,8 @@ TR_CLASSVARS_DECL(TR_Server) {}; | @@ -49,6 +50,8 @@ TR_CLASSVARS_DECL(TR_Server) {}; | ||
49 | #define TR_serverAddHandler(srv, handler) \ | 50 | #define TR_serverAddHandler(srv, handler) \ |
50 | TR_eventDispatcherRegisterHandler((srv)->dispatcher, (handler)) | 51 | TR_eventDispatcherRegisterHandler((srv)->dispatcher, (handler)) |
51 | 52 | ||
53 | +void TR_serverBindTcp(TR_Server, const char *, int, TR_Protocol); | ||
54 | +void TR_serverBindUdp(TR_Server, const char *, int, TR_Protocol); | ||
52 | void TR_serverStart(TR_Server, int); | 55 | void TR_serverStart(TR_Server, int); |
53 | 56 | ||
54 | #define TR_serverClassCleanup() \ | 57 | #define TR_serverClassCleanup() \ |
@@ -24,6 +24,8 @@ TRCOMM = cep_append_read_data.c \ | @@ -24,6 +24,8 @@ TRCOMM = cep_append_read_data.c \ | ||
24 | protocol_message_raw.c \ | 24 | protocol_message_raw.c \ |
25 | protocol_raw.c \ | 25 | protocol_raw.c \ |
26 | server.c \ | 26 | server.c \ |
27 | + server_bind_tcp.c \ | ||
28 | + server_bind_udp.c \ | ||
27 | server_start.c \ | 29 | server_start.c \ |
28 | i_comm_end_point.c \ | 30 | i_comm_end_point.c \ |
29 | i_comm_manager.c \ | 31 | i_comm_manager.c \ |
src/server_bind_tcp.c
0 → 100644
1 | +/** | ||
2 | + * \file | ||
3 | + * | ||
4 | + * \author Georg Hopp | ||
5 | + * | ||
6 | + * \copyright | ||
7 | + * Copyright © 2014 Georg Hopp | ||
8 | + * | ||
9 | + * This program is free software: you can redistribute it and/or modify | ||
10 | + * it under the terms of the GNU General Public License as published by | ||
11 | + * the Free Software Foundation, either version 3 of the License, or | ||
12 | + * (at your option) any later version. | ||
13 | + * | ||
14 | + * This program is distributed in the hope that it will be useful, | ||
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | + * GNU General Public License for more details. | ||
18 | + * | ||
19 | + * You should have received a copy of the GNU General Public License | ||
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | + */ | ||
22 | + | ||
23 | +#include "trio.h" | ||
24 | + | ||
25 | +#include "tr/server.h" | ||
26 | +#include "tr/protocol.h" | ||
27 | +#include "tr/connect_entry_point.h" | ||
28 | + | ||
29 | +void | ||
30 | +TR_serverBindTcp(TR_Server this, const char * host, int port, TR_Protocol proto) | ||
31 | +{ | ||
32 | + TR_Socket socket = (TR_Socket)TR_new( | ||
33 | + TR_TcpSocket, | ||
34 | + TR_logger, | ||
35 | + host, | ||
36 | + port, 0); | ||
37 | + | ||
38 | + TR_serverAddEndpoint(this, TR_new(TR_ConnEntryPoint, socket, proto)); | ||
39 | +} | ||
40 | + | ||
41 | +// vim: set ts=4 sw=4: |
src/server_bind_udp.c
0 → 100644
1 | +/** | ||
2 | + * \file | ||
3 | + * | ||
4 | + * \author Georg Hopp | ||
5 | + * | ||
6 | + * \copyright | ||
7 | + * Copyright © 2014 Georg Hopp | ||
8 | + * | ||
9 | + * This program is free software: you can redistribute it and/or modify | ||
10 | + * it under the terms of the GNU General Public License as published by | ||
11 | + * the Free Software Foundation, either version 3 of the License, or | ||
12 | + * (at your option) any later version. | ||
13 | + * | ||
14 | + * This program is distributed in the hope that it will be useful, | ||
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | + * GNU General Public License for more details. | ||
18 | + * | ||
19 | + * You should have received a copy of the GNU General Public License | ||
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | + */ | ||
22 | + | ||
23 | +#include "trio.h" | ||
24 | + | ||
25 | +#include "tr/server.h" | ||
26 | +#include "tr/protocol.h" | ||
27 | +#include "tr/datagram_entry_point.h" | ||
28 | + | ||
29 | +void | ||
30 | +TR_serverBindUdp(TR_Server this, const char * host, int port, TR_Protocol proto) | ||
31 | +{ | ||
32 | + TR_Socket socket = (TR_Socket)TR_new( | ||
33 | + TR_UdpSocket, | ||
34 | + TR_logger, | ||
35 | + host, | ||
36 | + port, 0); | ||
37 | + | ||
38 | + TR_serverAddEndpoint(this, TR_new(TR_DatagramEntryPoint, socket, proto)); | ||
39 | +} | ||
40 | + | ||
41 | +// vim: set ts=4 sw=4: |
@@ -17,20 +17,12 @@ main (int argc, char * argv[]) | @@ -17,20 +17,12 @@ main (int argc, char * argv[]) | ||
17 | TR_Server server = TR_new(TR_Server); | 17 | TR_Server server = TR_new(TR_Server); |
18 | TR_Protocol protocol = TR_new(TR_ProtocolRaw); | 18 | TR_Protocol protocol = TR_new(TR_ProtocolRaw); |
19 | TestHandler test_handler = TR_new(TestHandler); | 19 | TestHandler test_handler = TR_new(TestHandler); |
20 | - TR_Socket socket; | ||
21 | 20 | ||
22 | TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger); | 21 | TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger); |
23 | 22 | ||
24 | TR_serverAddHandler(server, (TR_EventHandler)test_handler); | 23 | TR_serverAddHandler(server, (TR_EventHandler)test_handler); |
25 | - socket = (TR_Socket)TR_new(TR_TcpSocket, TR_logger, "0.0.0.0", 5678, 0); | ||
26 | - TR_serverAddEndpoint( | ||
27 | - server, | ||
28 | - TR_new(TR_ConnEntryPoint, socket, protocol)); | ||
29 | - | ||
30 | - socket = TR_new(TR_UdpSocket, TR_logger, "0.0.0.0", 5678, 0); | ||
31 | - TR_serverAddEndpoint( | ||
32 | - server, | ||
33 | - TR_new(TR_DatagramEntryPoint, socket, protocol)); | 24 | + TR_serverBindTcp(server, "0.0.0.0", 5678, protocol); |
25 | + TR_serverBindUdp(server, "0.0.0.0", 5678, protocol); | ||
34 | 26 | ||
35 | TR_serverStart(server, 1000); | 27 | TR_serverStart(server, 1000); |
36 | 28 |
Please
register
or
login
to post a comment