Showing
11 changed files
with
83 additions
and
35 deletions
... | ... | @@ -46,7 +46,7 @@ TR_CLASSVARS_DECL(TR_CommManager) { |
46 | 46 | TR_CV_EXTENDS(TR_EventHandler); |
47 | 47 | }; |
48 | 48 | |
49 | -TR_EventDone TR_commManagerShutdown(TR_CommManager, TR_Event event); | |
49 | +TR_EventDone TR_commManagerShutdown(void *, TR_Event event); | |
50 | 50 | |
51 | 51 | #endif // __TR_COMM_MANAGER_H__ |
52 | 52 | ... | ... |
... | ... | @@ -31,7 +31,7 @@ |
31 | 31 | #include "tr/protocol.h" |
32 | 32 | #include "tr/proto_message.h" |
33 | 33 | |
34 | -typedef TR_ProtoMessage (* fptr_TR_protoCreateMessage)(void *); | |
34 | +typedef TR_ProtoMessage (* fptr_TR_protoCreateMessage)(void *, va_list *); | |
35 | 35 | typedef TR_ProtoMessage (* fptr_TR_protoCreateRequest)(void *, va_list *); |
36 | 36 | typedef TR_ProtoMessage (* fptr_TR_protoCreateResponse)(void *, va_list *); |
37 | 37 | typedef TR_RemoteData (* fptr_TR_protoCompose)(void *, TR_ProtoMessage); |
... | ... | @@ -47,7 +47,8 @@ TR_INTERFACE(TR_Protocol) { |
47 | 47 | fptr_TR_protoCompose compose; |
48 | 48 | }; |
49 | 49 | |
50 | -TR_ProtoMessage TR_protoCreateMessage(void *, TR_Socket); | |
50 | +TR_ProtoMessage TR_vprotoCreateMessage(void *, TR_Socket, va_list*); | |
51 | +TR_ProtoMessage TR_protoCreateMessage(void *, TR_Socket, ...); | |
51 | 52 | TR_ProtoMessage TR_vprotoCreateRequest(void *, TR_Socket, va_list*); |
52 | 53 | TR_ProtoMessage TR_protoCreateRequest(void *, TR_Socket, ...); |
53 | 54 | TR_ProtoMessage TR_vprotoCreateResponse(void *, TR_Socket, va_list*); | ... | ... |
... | ... | @@ -83,8 +83,9 @@ TR_commManagerEnableWrite(void * _this, TR_Event event) |
83 | 83 | |
84 | 84 | static |
85 | 85 | TR_EventDone |
86 | -TR_commManagerAddEndpointEvt(TR_CommManager this, TR_Event event) | |
86 | +TR_commManagerAddEndpointEvt(void * _this, TR_Event event) | |
87 | 87 | { |
88 | + TR_CommManager this = _this; | |
88 | 89 | TR_commManagerAddEndpoint(this, (TR_CommEndPoint)event->subject); |
89 | 90 | |
90 | 91 | return TR_EVENT_DONE; |
... | ... | @@ -96,8 +97,8 @@ TR_EventDone TR_commManagerPollRead(void *, TR_Event); |
96 | 97 | TR_EventDone TR_commManagerDisableRead(void *, TR_Event); |
97 | 98 | TR_EventDone TR_commManagerDisableWrite(void *, TR_Event); |
98 | 99 | TR_EventDone TR_commManagerClose(void *, TR_Event); |
99 | -TR_EventDone TR_commManagerShutdownRead(TR_CommManager, TR_Event); | |
100 | -TR_EventDone TR_commManagerShutdownWrite(TR_CommManager, TR_Event); | |
100 | +TR_EventDone TR_commManagerShutdownRead(void *, TR_Event); | |
101 | +TR_EventDone TR_commManagerShutdownWrite(void *, TR_Event); | |
101 | 102 | |
102 | 103 | static |
103 | 104 | void | ... | ... |
... | ... | @@ -66,7 +66,7 @@ commManagerEpollDtor(void * _this) |
66 | 66 | } |
67 | 67 | |
68 | 68 | static |
69 | -void | |
69 | +TR_EventDone | |
70 | 70 | TR_commManagerEpollAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
71 | 71 | { |
72 | 72 | TR_CommManagerEpoll this = _this; |
... | ... | @@ -79,10 +79,12 @@ TR_commManagerEpollAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
79 | 79 | event.events = this->events[handle]; |
80 | 80 | |
81 | 81 | epoll_ctl(this->handle, EPOLL_CTL_ADD, handle, &event); |
82 | + | |
83 | + return TR_EVENT_DONE; | |
82 | 84 | } |
83 | 85 | |
84 | 86 | static |
85 | -void | |
87 | +TR_EventDone | |
86 | 88 | TR_commManagerEpollSelect(void * _this, TR_Event event, unsigned long timeout) |
87 | 89 | { |
88 | 90 | TR_CommManagerEpoll this = _this; |
... | ... | @@ -131,11 +133,13 @@ TR_commManagerEpollSelect(void * _this, TR_Event event, unsigned long timeout) |
131 | 133 | NULL)); |
132 | 134 | } |
133 | 135 | } |
136 | + | |
137 | + return TR_EVENT_DONE; | |
134 | 138 | } |
135 | 139 | |
136 | 140 | static |
137 | 141 | inline |
138 | -void | |
142 | +TR_EventDone | |
139 | 143 | TR_commManagerEpollDisable(void * _this, uint32_t mask, TR_Event event) |
140 | 144 | { |
141 | 145 | TR_CommManagerEpoll this = _this; |
... | ... | @@ -148,11 +152,13 @@ TR_commManagerEpollDisable(void * _this, uint32_t mask, TR_Event event) |
148 | 152 | _event.events = this->events[handle]; |
149 | 153 | |
150 | 154 | epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &_event); |
155 | + | |
156 | + return TR_EVENT_DONE; | |
151 | 157 | } |
152 | 158 | |
153 | 159 | static |
154 | 160 | inline |
155 | -void | |
161 | +TR_EventDone | |
156 | 162 | TR_commManagerEpollEnable(void * _this, uint32_t mask, TR_Event event) |
157 | 163 | { |
158 | 164 | TR_CommManagerEpoll this = _this; |
... | ... | @@ -165,48 +171,60 @@ TR_commManagerEpollEnable(void * _this, uint32_t mask, TR_Event event) |
165 | 171 | _event.events = this->events[handle]; |
166 | 172 | |
167 | 173 | epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &_event); |
174 | + | |
175 | + return TR_EVENT_DONE; | |
168 | 176 | } |
169 | 177 | |
170 | 178 | static |
171 | -void | |
179 | +TR_EventDone | |
172 | 180 | TR_commManagerEpollEnableWrite(void * _this, TR_Event event) |
173 | 181 | { |
174 | 182 | if (! TR_socketFinWr(((TR_CommEndPoint)event->subject)->transport)) { |
175 | 183 | TR_commManagerEpollEnable(_this, EPOLLOUT, event); |
176 | 184 | } |
185 | + | |
186 | + return TR_EVENT_DONE; | |
177 | 187 | } |
178 | 188 | |
179 | 189 | static |
180 | -void | |
190 | +TR_EventDone | |
181 | 191 | TR_commManagerEpollEnableRead(void * _this, TR_Event event) |
182 | 192 | { |
183 | 193 | if (! TR_socketFinRd(((TR_CommEndPoint)event->subject)->transport)) { |
184 | 194 | TR_commManagerEpollEnable(_this, EPOLLIN, event); |
185 | 195 | } |
196 | + | |
197 | + return TR_EVENT_DONE; | |
186 | 198 | } |
187 | 199 | |
188 | 200 | static |
189 | -void | |
201 | +TR_EventDone | |
190 | 202 | TR_commManagerEpollDisableWrite(void * _this, TR_Event event) |
191 | 203 | { |
192 | 204 | TR_commManagerEpollDisable(_this, EPOLLOUT, event); |
205 | + | |
206 | + return TR_EVENT_DONE; | |
193 | 207 | } |
194 | 208 | |
195 | 209 | static |
196 | -void | |
210 | +TR_EventDone | |
197 | 211 | TR_commManagerEpollDisableRead(void * _this, TR_Event event) |
198 | 212 | { |
199 | 213 | TR_commManagerEpollDisable(_this, EPOLLIN, event); |
214 | + | |
215 | + return TR_EVENT_DONE; | |
200 | 216 | } |
201 | 217 | |
202 | 218 | static |
203 | -void | |
219 | +TR_EventDone | |
204 | 220 | TR_commManagerEpollClose(void * _this, TR_Event event) |
205 | 221 | { |
206 | 222 | TR_CommManagerEpoll this = _this; |
207 | 223 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
208 | 224 | |
209 | 225 | epoll_ctl(this->handle, EPOLL_CTL_DEL, endpoint->transport->handle, NULL); |
226 | + | |
227 | + return TR_EVENT_DONE; | |
210 | 228 | } |
211 | 229 | |
212 | 230 | static | ... | ... |
... | ... | @@ -65,17 +65,19 @@ commManagerPollDtor(void * _this) |
65 | 65 | } |
66 | 66 | |
67 | 67 | static |
68 | -void | |
68 | +TR_EventDone | |
69 | 69 | TR_commManagerPollAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
70 | 70 | { |
71 | 71 | TR_CommManagerPoll this = _this; |
72 | 72 | |
73 | - this->fds[endpoint->transport->handle].fd = endpoint->transport->handle; | |
73 | + this->fds[endpoint->transport->handle].fd = endpoint->transport->handle; | |
74 | 74 | this->fds[endpoint->transport->handle].events = 0; |
75 | + | |
76 | + return TR_EVENT_DONE; | |
75 | 77 | } |
76 | - | |
78 | + | |
77 | 79 | static |
78 | -void | |
80 | +TR_EventDone | |
79 | 81 | TR_commManagerPollSelect(void * _this, TR_Event event, unsigned long timeout) |
80 | 82 | { |
81 | 83 | TR_CommManagerPoll this = _this; |
... | ... | @@ -126,10 +128,12 @@ TR_commManagerPollSelect(void * _this, TR_Event event, unsigned long timeout) |
126 | 128 | } |
127 | 129 | } |
128 | 130 | } |
131 | + | |
132 | + return TR_EVENT_DONE; | |
129 | 133 | } |
130 | 134 | |
131 | 135 | static |
132 | -void | |
136 | +TR_EventDone | |
133 | 137 | TR_commManagerPollEnableWrite(void * _this, TR_Event event) |
134 | 138 | { |
135 | 139 | TR_CommManagerPoll this = _this; |
... | ... | @@ -138,10 +142,12 @@ TR_commManagerPollEnableWrite(void * _this, TR_Event event) |
138 | 142 | if (! TR_socketFinWr(endpoint->transport)) { |
139 | 143 | this->fds[endpoint->transport->handle].events |= POLLOUT|POLLHUP; |
140 | 144 | } |
145 | + | |
146 | + return TR_EVENT_DONE; | |
141 | 147 | } |
142 | 148 | |
143 | 149 | static |
144 | -void | |
150 | +TR_EventDone | |
145 | 151 | TR_commManagerPollEnableRead(void * _this, TR_Event event) |
146 | 152 | { |
147 | 153 | TR_CommManagerPoll this = _this; |
... | ... | @@ -150,30 +156,36 @@ TR_commManagerPollEnableRead(void * _this, TR_Event event) |
150 | 156 | if (! TR_socketFinRd(endpoint->transport)) { |
151 | 157 | this->fds[endpoint->transport->handle].events |= POLLIN; |
152 | 158 | } |
159 | + | |
160 | + return TR_EVENT_DONE; | |
153 | 161 | } |
154 | 162 | |
155 | 163 | static |
156 | -void | |
164 | +TR_EventDone | |
157 | 165 | TR_commManagerPollDisableWrite(void * _this, TR_Event event) |
158 | 166 | { |
159 | 167 | TR_CommManagerPoll this = _this; |
160 | 168 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
161 | 169 | |
162 | 170 | this->fds[endpoint->transport->handle].events &= ~(POLLOUT|POLLHUP); |
171 | + | |
172 | + return TR_EVENT_DONE; | |
163 | 173 | } |
164 | 174 | |
165 | 175 | static |
166 | -void | |
176 | +TR_EventDone | |
167 | 177 | TR_commManagerPollDisableRead(void * _this, TR_Event event) |
168 | 178 | { |
169 | 179 | TR_CommManagerPoll this = _this; |
170 | 180 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
171 | 181 | |
172 | 182 | this->fds[endpoint->transport->handle].events &= ~POLLIN; |
183 | + | |
184 | + return TR_EVENT_DONE; | |
173 | 185 | } |
174 | 186 | |
175 | 187 | static |
176 | -void | |
188 | +TR_EventDone | |
177 | 189 | TR_commManagerPollClose(void * _this, TR_Event event) |
178 | 190 | { |
179 | 191 | TR_CommManagerPoll this = _this; |
... | ... | @@ -181,6 +193,8 @@ TR_commManagerPollClose(void * _this, TR_Event event) |
181 | 193 | |
182 | 194 | this->fds[endpoint->transport->handle].events = 0; |
183 | 195 | this->fds[endpoint->transport->handle].fd = -1; |
196 | + | |
197 | + return TR_EVENT_DONE; | |
184 | 198 | } |
185 | 199 | |
186 | 200 | static | ... | ... |
... | ... | @@ -30,8 +30,9 @@ |
30 | 30 | #include "tr/_comm_manager.h" |
31 | 31 | |
32 | 32 | TR_EventDone |
33 | -TR_commManagerShutdown(TR_CommManager this, TR_Event event) | |
33 | +TR_commManagerShutdown(void * _this, TR_Event event) | |
34 | 34 | { |
35 | + TR_CommManager this = _this; | |
35 | 36 | nfds_t i; |
36 | 37 | |
37 | 38 | for (i=0; i<=this->max_handle; i++) { | ... | ... |
... | ... | @@ -29,8 +29,9 @@ |
29 | 29 | #include "tr/_comm_manager.h" |
30 | 30 | |
31 | 31 | TR_EventDone |
32 | -TR_commManagerShutdownRead(TR_CommManager this, TR_Event event) | |
32 | +TR_commManagerShutdownRead(void * _this, TR_Event event) | |
33 | 33 | { |
34 | + TR_CommManager this = _this; | |
34 | 35 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
35 | 36 | |
36 | 37 | if (! TR_socketFinRd(endpoint->transport)) { | ... | ... |
... | ... | @@ -28,8 +28,9 @@ |
28 | 28 | #include "tr/_comm_manager.h" |
29 | 29 | |
30 | 30 | TR_EventDone |
31 | -TR_commManagerShutdownWrite(TR_CommManager this, TR_Event event) | |
31 | +TR_commManagerShutdownWrite(void * _this, TR_Event event) | |
32 | 32 | { |
33 | + TR_CommManager this = _this; | |
33 | 34 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
34 | 35 | |
35 | 36 | if (! TR_socketFinWr(endpoint->transport)) { | ... | ... |
... | ... | @@ -31,10 +31,10 @@ |
31 | 31 | TR_CREATE_INTERFACE(TR_Protocol, 5); |
32 | 32 | |
33 | 33 | TR_ProtoMessage |
34 | -TR_protoCreateMessage(void * _this, TR_Socket remote) | |
34 | +TR_vprotoCreateMessage(void * _this, TR_Socket remote, va_list * params) | |
35 | 35 | { |
36 | 36 | TR_ProtoMessage callret; |
37 | - TR_RETCALL(_this, TR_Protocol, createMessage, callret); | |
37 | + TR_RETCALL(_this, TR_Protocol, createMessage, callret, params); | |
38 | 38 | if (callret != NULL) { |
39 | 39 | callret->remote = remote; |
40 | 40 | } |
... | ... | @@ -42,6 +42,17 @@ TR_protoCreateMessage(void * _this, TR_Socket remote) |
42 | 42 | } |
43 | 43 | |
44 | 44 | TR_ProtoMessage |
45 | +TR_protoCreateMessage(void * _this, TR_Socket remote, ...) | |
46 | +{ | |
47 | + TR_ProtoMessage callret; | |
48 | + va_list params; | |
49 | + va_start(params, remote); | |
50 | + callret = TR_vprotoCreateMessage(_this, remote, ¶ms); | |
51 | + va_end(params); | |
52 | + return callret; | |
53 | +} | |
54 | + | |
55 | +TR_ProtoMessage | |
45 | 56 | TR_vprotoCreateRequest(void * _this, TR_Socket remote, va_list * params) |
46 | 57 | { |
47 | 58 | TR_ProtoMessage callret; |
... | ... | @@ -67,7 +78,7 @@ TR_ProtoMessage |
67 | 78 | TR_vprotoCreateResponse(void * _this, TR_Socket remote, va_list * params) |
68 | 79 | { |
69 | 80 | TR_ProtoMessage callret; |
70 | - TR_RETCALL(_this, TR_Protocol, createResponse, callret, ¶ms); | |
81 | + TR_RETCALL(_this, TR_Protocol, createResponse, callret, params); | |
71 | 82 | if (callret != NULL) { |
72 | 83 | callret->remote = remote; |
73 | 84 | } | ... | ... |
... | ... | @@ -45,9 +45,9 @@ static void protocolRawDtor(void * _this) {} |
45 | 45 | |
46 | 46 | static |
47 | 47 | TR_ProtoMessage |
48 | -protocolRawCreateMessage(void * _this, TR_Socket remote) | |
48 | +protocolRawCreateMessage(void * _this, va_list * args) | |
49 | 49 | { |
50 | - return (TR_ProtoMessage)TR_new(TR_ProtoMessageRaw, remote); | |
50 | + return (TR_ProtoMessage)TR_new(TR_ProtoMessageRaw); | |
51 | 51 | } |
52 | 52 | |
53 | 53 | static |
... | ... | @@ -110,9 +110,9 @@ protocolRawCompose(void * _this, TR_ProtoMessage _message) |
110 | 110 | { |
111 | 111 | TR_ProtoMessageRaw message = (TR_ProtoMessageRaw)_message; |
112 | 112 | TR_SizedData data; |
113 | - | |
113 | + | |
114 | 114 | data = (TR_SizedData)TR_new(TR_RemoteData, NULL, 0, _message->remote); |
115 | - | |
115 | + | |
116 | 116 | data->size = message->size + 2; |
117 | 117 | data->data = TR_malloc(data->size); |
118 | 118 | *(uint16_t *)data->data = htons(message->size); | ... | ... |
Please
register
or
login
to post a comment