Showing
6 changed files
with
90 additions
and
10 deletions
| ... | ... | @@ -32,6 +32,7 @@ |
| 32 | 32 | #include "tr/connector.h" |
| 33 | 33 | #include "tr/io_handler.h" |
| 34 | 34 | #include "tr/protocol_handler.h" |
| 35 | +#include "tr/protocol.h" | |
| 35 | 36 | |
| 36 | 37 | TR_CLASS(TR_Server) { |
| 37 | 38 | TR_CommManager comm_manager; |
| ... | ... | @@ -49,6 +50,8 @@ TR_CLASSVARS_DECL(TR_Server) {}; |
| 49 | 50 | #define TR_serverAddHandler(srv, handler) \ |
| 50 | 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 | 55 | void TR_serverStart(TR_Server, int); |
| 53 | 56 | |
| 54 | 57 | #define TR_serverClassCleanup() \ | ... | ... |
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 | 17 | TR_Server server = TR_new(TR_Server); |
| 18 | 18 | TR_Protocol protocol = TR_new(TR_ProtocolRaw); |
| 19 | 19 | TestHandler test_handler = TR_new(TestHandler); |
| 20 | - TR_Socket socket; | |
| 21 | 20 | |
| 22 | 21 | TR_logger = TR_INSTANCE_CAST(TR_Logger, mylogger); |
| 23 | 22 | |
| 24 | 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 | 27 | TR_serverStart(server, 1000); |
| 36 | 28 | ... | ... |
Please
register
or
login
to post a comment