Commit f3ee0d7e022dfc1bf7956ddbeefa5c134395bd3c

Authored by Georg Hopp
1 parent 079be381

add datagram entry point class

... ... @@ -6,6 +6,7 @@ nobase_include_HEADERS = trcomm.h \
6 6 tr/connection.h \
7 7 tr/connector.h \
8 8 tr/datagram_service.h \
  9 + tr/datagram_entry_point.h \
9 10 tr/io_handler.h \
10 11 tr/proto_message.h \
11 12 tr/protocol.h \
... ...
... ... @@ -20,5 +20,26 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
  23 +#ifndef __TR_DATAGRAM_ENTRY_POINT_H__
  24 +#define __TR_DATAGRAM_ENTRY_POINT_H__
  25 +
  26 +#include <sys/types.h>
  27 +
  28 +#include "trbase.h"
  29 +#include "trevent.h"
  30 +#include "trdata.h"
  31 +
  32 +#include "tr/comm_end_point.h"
  33 +
  34 +TR_CLASS(TR_DatagramEntryPoint) {
  35 + TR_EXTENDS(TR_DatagramService);
  36 +};
  37 +TR_INSTANCE_INIT(TR_DatagramEntryPoint);
  38 +TR_CLASSVARS_DECL(TR_DatagramEntryPoint) {
  39 + TR_CV_EXTENDS(TR_CommEndPoint);
  40 +};
  41 +
  42 +#endif // __TR_DATAGRAM_ENTRY_POINT_H__
23 43
24 44 // vim: set ts=4 sw=4:
  45 +
... ...
... ... @@ -8,6 +8,7 @@
8 8 #include "tr/connection.h"
9 9 #include "tr/connector.h"
10 10 #include "tr/datagram_service.h"
  11 +#include "tr/datagram_entry_point.h"
11 12 #include "tr/io_handler.h"
12 13 #include "tr/proto_message.h"
13 14 #include "tr/protocol.h"
... ...
... ... @@ -12,12 +12,11 @@ TRCOMM = cep_append_read_data.c \
12 12 comm_manager.c \
13 13 comm_manager_poll.c \
14 14 comm_manager_shutdown.c \
15   - con_compose.c \
16   - con_next_message.c \
17 15 conn_entry_point.c \
18 16 connection.c \
19 17 connector.c \
20 18 datagram_service.c \
  19 + datagram_entry_point.c \
21 20 io_handler.c \
22 21 proto_message.c \
23 22 protocol.c \
... ...
... ... @@ -20,5 +20,45 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
  23 +#include <stdarg.h>
  24 +
  25 +#include "trbase.h"
  26 +
  27 +#include "tr/datagram_service.h"
  28 +#include "tr/datagram_entry_point.h"
  29 +
  30 +static
  31 +int
  32 +datagramEntryPointCtor(void * _this, va_list * params)
  33 +{
  34 + TR_CommEndPoint this = _this;
  35 +
  36 + TR_PARENTCALL(TR_DatagramEntryPoint, _this, TR_Class, ctor, params);
  37 +
  38 + TR_socketBind((TR_Socket)this->transport);
  39 + TR_socketNonblock((TR_Socket)this->transport);
  40 +
  41 + return 0;
  42 +}
  43 +
  44 +static
  45 +void
  46 +datagramEntryPointDtor(void * _this)
  47 +{
  48 + TR_PARENTCALL(TR_DatagramEntryPoint, _this, TR_Class, dtor);
  49 +}
  50 +
  51 +intptr_t datagramEntryPoint_events[TR_CEP_EVENT_MAX + 1];
  52 +TR_INIT_IFACE(TR_Class, datagramEntryPointCtor, datagramEntryPointDtor, NULL);
  53 +TR_CREATE_CLASS(
  54 + TR_DatagramEntryPoint,
  55 + TR_DatagramService,
  56 + NULL,
  57 + TR_IF(TR_Class)) = {
  58 + {{
  59 + TR_CEP_EVENT_MAX + 1,
  60 + datagramEntryPoint_events
  61 + }}
  62 +};
23 63
24 64 // vim: set ts=4 sw=4:
... ...
... ... @@ -28,11 +28,9 @@ main (int argc, char * argv[])
28 28 TR_new(TR_ConnEntryPoint, socket, protocol));
29 29
30 30 socket = TR_new(TR_UdpSocket, TR_logger, "0.0.0.0", 5678, 0);
31   - TR_socketBind((TR_Socket)socket);
32   - TR_socketNonblock((TR_Socket)socket);
33 31 TR_serverAddEndpoint(
34 32 server,
35   - TR_new(TR_DatagramService, socket, protocol));
  33 + TR_new(TR_DatagramEntryPoint, socket, protocol));
36 34
37 35 TR_serverStart(server, 1000);
38 36
... ...
Please register or login to post a comment