Commit 5cfb6cd29305f41835c8bd860b4eddeb08f64b51
1 parent
81801199
add connector and conn_entry_point and do some modifications
Showing
15 changed files
with
438 additions
and
88 deletions
@@ -27,6 +27,7 @@ | @@ -27,6 +27,7 @@ | ||
27 | 27 | ||
28 | #include "trbase.h" | 28 | #include "trbase.h" |
29 | #include "trevent.h" | 29 | #include "trevent.h" |
30 | +#include "trdata.h" | ||
30 | 31 | ||
31 | TR_CLASS(TR_CommEndPoint) { | 32 | TR_CLASS(TR_CommEndPoint) { |
32 | TR_EXTENDS(TR_EventSubject); | 33 | TR_EXTENDS(TR_EventSubject); |
@@ -60,6 +61,11 @@ TR_CLASSVARS_DECL(TR_CommEndPoint) { | @@ -60,6 +61,11 @@ TR_CLASSVARS_DECL(TR_CommEndPoint) { | ||
60 | #define TR_cepHasProto(ep, proto) (TR_INSTANCE_OF(proto, TR_cepGetProto(ep))) | 61 | #define TR_cepHasProto(ep, proto) (TR_INSTANCE_OF(proto, TR_cepGetProto(ep))) |
61 | #define TR_cepGetProto(ep) ((ep)->protocol) | 62 | #define TR_cepGetProto(ep) ((ep)->protocol) |
62 | #define TR_cepGetHandle(ep) ((ep)->transport->handle) | 63 | #define TR_cepGetHandle(ep) ((ep)->transport->handle) |
64 | +#define TR_cepHasPendingData(ep) (! TR_queueEmpty((ep)->write_buffer)) | ||
65 | +#define TR_cepNextWriteData(ep) (TR_queueGet(this->write_buffer)) | ||
66 | + | ||
67 | +void TR_cepAppendReadData(TR_CommEndPoint, TR_RemoteData); | ||
68 | +void TR_cepAppendWriteData(TR_CommEndPoint, TR_RemoteData); | ||
63 | 69 | ||
64 | #endif // __TR_COMM_END_POINT_H__ | 70 | #endif // __TR_COMM_END_POINT_H__ |
65 | 71 |
include/tr/connect_entry_point.h
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 | +#ifndef __TR_CONNECT_ENTRY_POINT_H__ | ||
24 | +#define __TR_CONNECT_ENTRY_POINT_H__ | ||
25 | + | ||
26 | +#include <sys/types.h> | ||
27 | + | ||
28 | +#include "trbase.h" | ||
29 | +#include "trio.h" | ||
30 | + | ||
31 | +#include "tr/comm_end_point.h" | ||
32 | + | ||
33 | +TR_CLASS(TR_ConnEntryPoint) { | ||
34 | + TR_EXTENDS(TR_CommEndPoint); | ||
35 | +}; | ||
36 | +TR_INSTANCE_INIT(TR_ConnEntryPoint); | ||
37 | +TR_CLASSVARS_DECL(TR_ConnEntryPoint) { | ||
38 | + TR_CV_EXTENDS(TR_CommEndPoint); | ||
39 | +}; | ||
40 | + | ||
41 | +#define TR_CET_EVENT_ACC_READY (TR_CEP_EVENT_MAX + 1) | ||
42 | +#define TR_CET_EVENT_MAX ((size_t)TR_CET_EVENT_ACC_READY) | ||
43 | + | ||
44 | +TR_TcpSocket TR_cetAccept(TR_ConnEntryPoint); | ||
45 | + | ||
46 | +#endif // __TR_CONNECT_ENTRY_POINT_H__ | ||
47 | + | ||
48 | +// vim: set ts=4 sw=4: | ||
49 | + |
include/tr/connector.h
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 | +#ifndef __TR_CONNECTOR_H__ | ||
24 | +#define __TR_CONNECTOR_H__ | ||
25 | + | ||
26 | +#include <sys/types.h> | ||
27 | + | ||
28 | +#include "trbase.h" | ||
29 | +#include "trevent.h" | ||
30 | + | ||
31 | +TR_CLASS(TR_Connector) { | ||
32 | + TR_EXTENDS(TR_EventHandler); | ||
33 | +}; | ||
34 | +TR_INSTANCE_INIT(TR_Connector); | ||
35 | +TR_CLASSVARS_DECL(TR_Connector) { | ||
36 | + TR_CV_EXTENDS(TR_EventHandler); | ||
37 | +}; | ||
38 | + | ||
39 | +#endif // __TR_CONNECTOR_H__ | ||
40 | + | ||
41 | +// vim: set ts=4 sw=4: | ||
42 | + |
@@ -31,29 +31,17 @@ | @@ -31,29 +31,17 @@ | ||
31 | #include "tr/comm_end_point.h" | 31 | #include "tr/comm_end_point.h" |
32 | #include "tr/proto_message.h" | 32 | #include "tr/proto_message.h" |
33 | 33 | ||
34 | -typedef int (* fptr_TR_cepHasPendingData)(void *); | ||
35 | typedef TR_ProtoMessage (* fptr_TR_cepNextMessage)(void *); | 34 | typedef TR_ProtoMessage (* fptr_TR_cepNextMessage)(void *); |
36 | typedef int (* fptr_TR_cepCompose)(void *, TR_ProtoMessage); | 35 | typedef int (* fptr_TR_cepCompose)(void *, TR_ProtoMessage); |
37 | -typedef void (* fptr_TR_cepAppendReadData)(void *, TR_RemoteData); | ||
38 | -typedef TR_RemoteData (* fptr_TR_cepNextWriteData)(void *); | ||
39 | -typedef void (* fptr_TR_cepAppendWriteData)(void *, TR_RemoteData); | ||
40 | 36 | ||
41 | TR_INTERFACE(TR_CommEndPoint) { | 37 | TR_INTERFACE(TR_CommEndPoint) { |
42 | TR_IFID; | 38 | TR_IFID; |
43 | - fptr_TR_cepHasPendingData hasPendingData; | ||
44 | fptr_TR_cepNextMessage nextMessage; | 39 | fptr_TR_cepNextMessage nextMessage; |
45 | fptr_TR_cepCompose compose; | 40 | fptr_TR_cepCompose compose; |
46 | - fptr_TR_cepAppendReadData appendReadData; | ||
47 | - fptr_TR_cepNextWriteData nextWriteData; | ||
48 | - fptr_TR_cepAppendWriteData appendWriteData; | ||
49 | }; | 41 | }; |
50 | 42 | ||
51 | -int TR_cepHasPendingData(void *); | ||
52 | TR_ProtoMessage TR_cepNextMessage(void *); | 43 | TR_ProtoMessage TR_cepNextMessage(void *); |
53 | int TR_cepCompose(void *, TR_ProtoMessage); | 44 | int TR_cepCompose(void *, TR_ProtoMessage); |
54 | -void TR_cepAppendReadData(void *, TR_RemoteData); | ||
55 | -TR_RemoteData TR_cepNextWriteData(void *); | ||
56 | -void TR_cepAppendWriteData(void *, TR_RemoteData); | ||
57 | 45 | ||
58 | #endif // __TR_INTERFACE_COMM_END_POINT_H__ | 46 | #endif // __TR_INTERFACE_COMM_END_POINT_H__ |
59 | 47 |
@@ -3,13 +3,19 @@ AUTOMAKE_OPTIONS = subdir-objects | @@ -3,13 +3,19 @@ AUTOMAKE_OPTIONS = subdir-objects | ||
3 | 3 | ||
4 | AM_CFLAGS += -I../include/ | 4 | AM_CFLAGS += -I../include/ |
5 | 5 | ||
6 | -TRCOMM = comm_end_point.c \ | 6 | +TRCOMM = cep_append_read_data.c \ |
7 | + cep_append_write_data.c \ | ||
8 | + cet_accept.c \ | ||
9 | + comm_end_point.c \ | ||
10 | + con_compose.c \ | ||
7 | connection.c \ | 11 | connection.c \ |
8 | connector.c \ | 12 | connector.c \ |
13 | + conn_entry_point.c \ | ||
14 | + con_next_message.c \ | ||
9 | protocol.c \ | 15 | protocol.c \ |
10 | - proto_message.c \ | ||
11 | - protocol_raw.c \ | ||
12 | protocol_message_raw.c \ | 16 | protocol_message_raw.c \ |
17 | + protocol_raw.c \ | ||
18 | + proto_message.c \ | ||
13 | i_comm_end_point.c \ | 19 | i_comm_end_point.c \ |
14 | i_protocol.c | 20 | i_protocol.c |
15 | 21 |
src/cep_append_read_data.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 "trbase.h" | ||
24 | +#include "trio.h" | ||
25 | + | ||
26 | +#include "tr/comm_end_point.h" | ||
27 | + | ||
28 | +void | ||
29 | +cepAppendReadData(TR_CommEndPoint this, TR_RemoteData data) | ||
30 | +{ | ||
31 | + TR_queuePut(this->read_buffer, data); | ||
32 | +} | ||
33 | + | ||
34 | +// vim: set ts=4 sw=4: |
src/cep_append_write_data.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 "trbase.h" | ||
24 | +#include "trio.h" | ||
25 | + | ||
26 | +#include "tr/comm_end_point.h" | ||
27 | + | ||
28 | +void | ||
29 | +cepAppendWriteData(TR_CommEndPoint this, TR_RemoteData data) | ||
30 | +{ | ||
31 | + TR_queuePut(this->write_buffer, data); | ||
32 | +} | ||
33 | + | ||
34 | +// vim: set ts=4 sw=4: |
src/cet_accept.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/comm_end_point.h" | ||
26 | +#include "tr/connect_entry_point.h" | ||
27 | + | ||
28 | +TR_TcpSocket | ||
29 | +TR_cetAccept(TR_ConnEntryPoint cet) | ||
30 | +{ | ||
31 | + return TR_socketAccept((TR_TcpSocket)((TR_CommEndPoint)cet)->transport); | ||
32 | +} | ||
33 | + | ||
34 | +// vim: set ts=4 sw=4: |
@@ -59,34 +59,6 @@ commEndPointDtor(void * _this) | @@ -59,34 +59,6 @@ commEndPointDtor(void * _this) | ||
59 | } | 59 | } |
60 | 60 | ||
61 | static | 61 | static |
62 | -int | ||
63 | -commEndPointHasPendingData(void * _this) | ||
64 | -{ | ||
65 | - return ! TR_queueEmpty(((TR_CommEndPoint)_this)->write_buffer); | ||
66 | -} | ||
67 | - | ||
68 | -static | ||
69 | -void | ||
70 | -commEndPointAppendReadData(void * _this, TR_RemoteData data) | ||
71 | -{ | ||
72 | - TR_queuePut(((TR_CommEndPoint)_this)->read_buffer, data); | ||
73 | -} | ||
74 | - | ||
75 | -static | ||
76 | -TR_RemoteData | ||
77 | -commEndPointNextWriteData(void * _this) | ||
78 | -{ | ||
79 | - return TR_queueGet(((TR_CommEndPoint)_this)->write_buffer); | ||
80 | -} | ||
81 | - | ||
82 | -static | ||
83 | -void | ||
84 | -commEndPointAppendWriteData(void * _this, TR_RemoteData data) | ||
85 | -{ | ||
86 | - TR_queuePut(((TR_CommEndPoint)_this)->write_buffer, data); | ||
87 | -} | ||
88 | - | ||
89 | -static | ||
90 | void | 62 | void |
91 | commEndPointCvInit(TR_class_ptr cls) | 63 | commEndPointCvInit(TR_class_ptr cls) |
92 | { | 64 | { |
@@ -105,14 +77,7 @@ commEndPointCvInit(TR_class_ptr cls) | @@ -105,14 +77,7 @@ commEndPointCvInit(TR_class_ptr cls) | ||
105 | 77 | ||
106 | intptr_t comm_end_point_events[TR_CEP_EVENT_MAX + 1]; | 78 | intptr_t comm_end_point_events[TR_CEP_EVENT_MAX + 1]; |
107 | TR_INIT_IFACE(TR_Class, commEndPointCtor, commEndPointDtor, NULL); | 79 | TR_INIT_IFACE(TR_Class, commEndPointCtor, commEndPointDtor, NULL); |
108 | -TR_INIT_IFACE( | ||
109 | - TR_CommEndPoint, | ||
110 | - commEndPointHasPendingData, | ||
111 | - NULL, | ||
112 | - NULL, | ||
113 | - commEndPointAppendReadData, | ||
114 | - commEndPointNextWriteData, | ||
115 | - commEndPointAppendWriteData); | 80 | +TR_INIT_IFACE(TR_CommEndPoint, NULL, NULL); |
116 | TR_CREATE_CLASS( | 81 | TR_CREATE_CLASS( |
117 | TR_CommEndPoint, | 82 | TR_CommEndPoint, |
118 | TR_EventSubject, | 83 | TR_EventSubject, |
src/con_compose.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 | + | ||
24 | +// vim: set ts=4 sw=4: |
src/con_next_message.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 | + | ||
24 | +// vim: set ts=4 sw=4: |
src/conn_entry_point.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 <stdarg.h> | ||
24 | +#include <stdint.h> | ||
25 | + | ||
26 | +#include <sys/types.h> | ||
27 | + | ||
28 | +#include "trbase.h" | ||
29 | +#include "trio.h" | ||
30 | +#include "trevent.h" | ||
31 | + | ||
32 | +#include "tr/connect_entry_point.h" | ||
33 | +#include "tr/interface/comm_end_point.h" | ||
34 | + | ||
35 | +static | ||
36 | +int | ||
37 | +connEntryPointCtor(void * _this, va_list * params) | ||
38 | +{ | ||
39 | + TR_PARENTCALL(_this, TR_Class, ctor, params); | ||
40 | + return 0; | ||
41 | +} | ||
42 | + | ||
43 | +static | ||
44 | +void | ||
45 | +connEntryPointDtor(void * _this) | ||
46 | +{ | ||
47 | + TR_PARENTCALL(_this, TR_Class, dtor); | ||
48 | +} | ||
49 | + | ||
50 | +static | ||
51 | +void | ||
52 | +connEntryPointCvInit(TR_class_ptr cls) | ||
53 | +{ | ||
54 | + TR_EVENT_CREATE(cls, TR_CET_EVENT_ACC_READY); | ||
55 | +} | ||
56 | + | ||
57 | +intptr_t connEntryPoint_events[TR_CET_EVENT_MAX + 1]; | ||
58 | +TR_INIT_IFACE(TR_Class, connEntryPointCtor, connEntryPointDtor, NULL); | ||
59 | +TR_INIT_IFACE(TR_CommEndPoint, NULL, NULL); | ||
60 | +TR_CREATE_CLASS( | ||
61 | + TR_ConnEntryPoint, | ||
62 | + TR_CommEndPoint, | ||
63 | + connEntryPointCvInit, | ||
64 | + TR_IF(TR_Class), | ||
65 | + TR_IF(TR_CommEndPoint)) = { | ||
66 | + {{ | ||
67 | + TR_CET_EVENT_MAX + 1, | ||
68 | + connEntryPoint_events | ||
69 | + }} | ||
70 | +}; | ||
71 | + | ||
72 | +// vim: set ts=4 sw=4: |
@@ -131,15 +131,11 @@ intptr_t connection_events[TR_CON_EVENT_MAX + 1]; | @@ -131,15 +131,11 @@ intptr_t connection_events[TR_CON_EVENT_MAX + 1]; | ||
131 | TR_INIT_IFACE(TR_Class, connectionCtor, connectionDtor, NULL); | 131 | TR_INIT_IFACE(TR_Class, connectionCtor, connectionDtor, NULL); |
132 | TR_INIT_IFACE( | 132 | TR_INIT_IFACE( |
133 | TR_CommEndPoint, | 133 | TR_CommEndPoint, |
134 | - NULL, | ||
135 | connectionNextMessage, | 134 | connectionNextMessage, |
136 | - connectionCompose, | ||
137 | - NULL, | ||
138 | - NULL, | ||
139 | - NULL); | 135 | + connectionCompose); |
140 | TR_CREATE_CLASS( | 136 | TR_CREATE_CLASS( |
141 | TR_Connection, | 137 | TR_Connection, |
142 | - TR_EventSubject, | 138 | + TR_CommEndPoint, |
143 | connectionCvInit, | 139 | connectionCvInit, |
144 | TR_IF(TR_Class), | 140 | TR_IF(TR_Class), |
145 | TR_IF(TR_CommEndPoint)) = { | 141 | TR_IF(TR_CommEndPoint)) = { |
src/connector.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 <stdarg.h> | ||
24 | +#include <stdint.h> | ||
25 | + | ||
26 | +#include <sys/types.h> | ||
27 | + | ||
28 | +#include "trbase.h" | ||
29 | +#include "trio.h" | ||
30 | +#include "trevent.h" | ||
31 | + | ||
32 | +#include "tr/connector.h" | ||
33 | +#include "tr/connection.h" | ||
34 | +#include "tr/protocol.h" | ||
35 | + | ||
36 | +static | ||
37 | +int | ||
38 | +connectorCtor(void * _this, va_list * params) | ||
39 | +{ | ||
40 | + TR_PARENTCALL(_this, TR_Class, ctor, params); | ||
41 | + return 0; | ||
42 | +} | ||
43 | + | ||
44 | +static | ||
45 | +void | ||
46 | +connectorDtor(void * _this) | ||
47 | +{ | ||
48 | + TR_PARENTCALL(_this, TR_Class, dtor); | ||
49 | +} | ||
50 | + | ||
51 | +static | ||
52 | +int | ||
53 | +connectorAccept(void * _this, TR_Event event) | ||
54 | +{ | ||
55 | + TR_Connector this = _this; | ||
56 | + TR_CommEndPoint connection = (TR_CommEndPoint)event->subject; | ||
57 | + TR_TcpSocket socket = TR_socketAccept( | ||
58 | + (TR_TcpSocket)connection->transport); | ||
59 | + | ||
60 | + while (socket) { | ||
61 | + TR_Connection new_con = TR_new( | ||
62 | + TR_Connection, | ||
63 | + socket, | ||
64 | + connection->protocol, | ||
65 | + 8192); | ||
66 | + TR_eventHandlerIssueEvent( | ||
67 | + (TR_EventHandler)this, | ||
68 | + (TR_EventSubject)new_con, | ||
69 | + TR_CON_EVENT_NEW_CON, | ||
70 | + NULL); | ||
71 | + socket = TR_socketAccept((TR_TcpSocket)connection->transport); | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * TODO we need to identify socket failures and close socket then. | ||
76 | + */ | ||
77 | + | ||
78 | + return 1; | ||
79 | +} | ||
80 | + | ||
81 | +static | ||
82 | +void | ||
83 | +connectorCvInit(TR_class_ptr cls) | ||
84 | +{ | ||
85 | + TR_EVENT_HANDLER_SET_METHOD( | ||
86 | + cls, | ||
87 | + TR_CommEndPoint, | ||
88 | + TR_CEP_EVENT_READ_READY, | ||
89 | + connectorAccept); | ||
90 | +} | ||
91 | + | ||
92 | +TR_INSTANCE(TR_Hash, _event_methods); | ||
93 | +TR_INIT_IFACE(TR_Class, connectorCtor, connectorDtor, NULL); | ||
94 | +TR_CREATE_CLASS( | ||
95 | + TR_Connector, | ||
96 | + TR_EventHandler, | ||
97 | + connectorCvInit, | ||
98 | + TR_IF(TR_Class)) = { | ||
99 | + { &(__event_methods.data) } | ||
100 | +}; | ||
101 | + | ||
102 | +// vim: set ts=4 sw=4: |
@@ -28,48 +28,22 @@ | @@ -28,48 +28,22 @@ | ||
28 | #include "tr/interface/comm_end_point.h" | 28 | #include "tr/interface/comm_end_point.h" |
29 | #include "tr/proto_message.h" | 29 | #include "tr/proto_message.h" |
30 | 30 | ||
31 | -TR_CREATE_INTERFACE(TR_CommEndPoint, 4); | ||
32 | - | ||
33 | -int | ||
34 | -TR_cepHasPendingData(void * _this) | ||
35 | -{ | ||
36 | - int callret; | ||
37 | - | ||
38 | - TR_RETCALL(_this, TR_CommEndPoint, hasPendingData, callret); | ||
39 | - | ||
40 | - return callret; | ||
41 | -} | 31 | +TR_CREATE_INTERFACE(TR_CommEndPoint, 2); |
42 | 32 | ||
43 | TR_ProtoMessage | 33 | TR_ProtoMessage |
44 | TR_cepNextMessage(void * _this) | 34 | TR_cepNextMessage(void * _this) |
45 | { | 35 | { |
46 | TR_ProtoMessage callret; | 36 | TR_ProtoMessage callret; |
47 | - | ||
48 | TR_RETCALL(_this, TR_CommEndPoint, nextMessage, callret); | 37 | TR_RETCALL(_this, TR_CommEndPoint, nextMessage, callret); |
49 | - | ||
50 | return callret; | 38 | return callret; |
51 | } | 39 | } |
52 | 40 | ||
53 | -void | ||
54 | -TR_cepAppendReadData(void * _this, TR_RemoteData data) | ||
55 | -{ | ||
56 | - TR_CALL(_this, TR_CommEndPoint, appendReadData, data); | ||
57 | -} | ||
58 | - | ||
59 | -TR_RemoteData | ||
60 | -TR_cepNextWriteData(void * _this) | 41 | +int |
42 | +TR_cepCompose(void * _this, TR_ProtoMessage message) | ||
61 | { | 43 | { |
62 | - TR_RemoteData callret; | ||
63 | - | ||
64 | - TR_RETCALL(_this, TR_CommEndPoint, nextWriteData, callret); | ||
65 | - | 44 | + int callret; |
45 | + TR_RETCALL(_this, TR_CommEndPoint, compose, callret, message); | ||
66 | return callret; | 46 | return callret; |
67 | } | 47 | } |
68 | 48 | ||
69 | -void | ||
70 | -TR_cepAppendWriteData(void * _this, TR_RemoteData data) | ||
71 | -{ | ||
72 | - TR_CALL(_this, TR_CommEndPoint, appendWriteData, data); | ||
73 | -} | ||
74 | - | ||
75 | // vim: set ts=4 sw=4: | 49 | // vim: set ts=4 sw=4: |
Please
register
or
login
to post a comment