...
|
...
|
@@ -47,12 +47,8 @@ commManagerEpollCtor(void * _this, va_list * params) |
47
|
47
|
TR_CommManager cmgr = _this;
|
48
|
48
|
|
49
|
49
|
TR_PARENTCALL(TR_CommManagerEpoll, _this, TR_Class, ctor, params);
|
50
|
|
- this->handle = epoll_create(cmgr->n_endpoints);
|
51
|
|
- this->read_ready = TR_new(TR_Queue);
|
52
|
|
- this->write_ready = TR_new(TR_Queue);
|
53
|
|
-
|
54
|
|
- this->read_ready->free_msgs = 0;
|
55
|
|
- this->write_ready->free_msgs = 0;
|
|
50
|
+ this->handle = epoll_create(cmgr->n_endpoints);
|
|
51
|
+ this->events = TR_calloc(cmgr->n_endpoints, sizeof(uint32_t));
|
56
|
52
|
|
57
|
53
|
return 0;
|
58
|
54
|
}
|
...
|
...
|
@@ -63,9 +59,7 @@ commManagerEpollDtor(void * _this) |
63
|
59
|
{
|
64
|
60
|
TR_CommManagerEpoll this = _this;
|
65
|
61
|
|
66
|
|
- TR_delete(this->read_ready);
|
67
|
|
- TR_delete(this->write_ready);
|
68
|
|
-
|
|
62
|
+ TR_MEM_FREE(this->events);
|
69
|
63
|
close(this->handle);
|
70
|
64
|
TR_PARENTCALL(TR_CommManagerEpoll, _this, TR_Class, dtor);
|
71
|
65
|
}
|
...
|
...
|
@@ -78,8 +72,9 @@ TR_commManagerEpollAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
78
|
72
|
int handle = endpoint->transport->handle;
|
79
|
73
|
struct epoll_event event;
|
80
|
74
|
|
81
|
|
- event.data.ptr = endpoint;
|
82
|
|
- event.events = EPOLLIN | EPOLLOUT | EPOLLET;
|
|
75
|
+ this->events[handle] = EPOLLIN;
|
|
76
|
+ event.data.ptr = endpoint;
|
|
77
|
+ event.events = this->events[handle];
|
83
|
78
|
|
84
|
79
|
epoll_ctl(this->handle, EPOLL_CTL_ADD, handle, &event);
|
85
|
80
|
}
|
...
|
...
|
@@ -90,11 +85,6 @@ TR_commManagerEpollSelect(void * _this, TR_Event event, int timeout) |
90
|
85
|
{
|
91
|
86
|
TR_CommManagerEpoll this = _this;
|
92
|
87
|
int i, nevents;
|
93
|
|
- TR_Queue node;
|
94
|
|
-
|
95
|
|
- if (0 != (this->read_ready->nmsg & this->write_ready->nmsg)) {
|
96
|
|
- timeout = 0;
|
97
|
|
- }
|
98
|
88
|
|
99
|
89
|
nevents = epoll_wait(this->handle, events, MAXEVENTS, timeout);
|
100
|
90
|
|
...
|
...
|
@@ -110,40 +100,16 @@ TR_commManagerEpollSelect(void * _this, TR_Event event, int timeout) |
110
|
100
|
TR_CET_EVENT_ACC_READY,
|
111
|
101
|
NULL));
|
112
|
102
|
} else {
|
113
|
|
- if (! ((TR_EventSubject)endpoint)->fin) {
|
114
|
|
- TR_queuePut(this->read_ready, endpoint);
|
115
|
|
- }
|
|
103
|
+ TR_eventHandlerIssueEvent((TR_EventHandler)this,
|
|
104
|
+ TR_eventSubjectEmit(
|
|
105
|
+ (TR_EventSubject)endpoint,
|
|
106
|
+ TR_CEP_EVENT_READ_READY,
|
|
107
|
+ NULL));
|
116
|
108
|
}
|
117
|
109
|
}
|
118
|
110
|
|
119
|
111
|
if ((events[i].events & EPOLLOUT) == EPOLLOUT) {
|
120
|
|
- if (TR_cepHasPendingData(endpoint) &&
|
121
|
|
- ! ((TR_EventSubject)endpoint)->fin) {
|
122
|
|
- TR_queuePut(this->write_ready, endpoint);
|
123
|
|
- }
|
124
|
|
- }
|
125
|
|
- }
|
126
|
|
-
|
127
|
|
- /* now issue reads and write events */
|
128
|
|
- for (node=this->read_ready->first; node; node=node->next) {
|
129
|
|
- TR_CommEndPoint endpoint = (TR_CommEndPoint)node->msg;
|
130
|
|
-
|
131
|
|
- if (! TR_socketFinRd(endpoint->transport)) {
|
132
|
|
- TR_eventHandlerIssueEvent(
|
133
|
|
- (TR_EventHandler)this,
|
134
|
|
- TR_eventSubjectEmit(
|
135
|
|
- (TR_EventSubject)endpoint,
|
136
|
|
- TR_CEP_EVENT_READ_READY,
|
137
|
|
- NULL));
|
138
|
|
- }
|
139
|
|
- }
|
140
|
|
-
|
141
|
|
- for (node=this->write_ready->first; node; node=node->next) {
|
142
|
|
- TR_CommEndPoint endpoint = (TR_CommEndPoint)node->msg;
|
143
|
|
-
|
144
|
|
- if (! TR_socketFinWr(endpoint->transport)) {
|
145
|
|
- TR_eventHandlerIssueEvent(
|
146
|
|
- (TR_EventHandler)this,
|
|
112
|
+ TR_eventHandlerIssueEvent((TR_EventHandler)this,
|
147
|
113
|
TR_eventSubjectEmit(
|
148
|
114
|
(TR_EventSubject)endpoint,
|
149
|
115
|
TR_CEP_EVENT_WRITE_READY,
|
...
|
...
|
@@ -154,80 +120,84 @@ TR_commManagerEpollSelect(void * _this, TR_Event event, int timeout) |
154
|
120
|
|
155
|
121
|
static
|
156
|
122
|
void
|
157
|
|
-TR_commManagerEpollRemoveWrite(void * _this, TR_Event event)
|
|
123
|
+TR_commManagerEpollEnableWrite(void * _this, TR_Event event)
|
158
|
124
|
{
|
159
|
125
|
TR_CommManagerEpoll this = _this;
|
160
|
126
|
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
|
161
|
127
|
|
162
|
|
- TR_queueDelete(this->write_ready, endpoint);
|
|
128
|
+ if (! TR_socketFinWr(endpoint->transport)) {
|
|
129
|
+ int handle = endpoint->transport->handle;
|
|
130
|
+ struct epoll_event _event;
|
|
131
|
+
|
|
132
|
+ this->events[handle] |= EPOLLOUT;
|
|
133
|
+ _event.data.ptr = endpoint;
|
|
134
|
+ _event.events = this->events[handle];
|
|
135
|
+
|
|
136
|
+ epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &_event);
|
|
137
|
+ }
|
163
|
138
|
}
|
164
|
139
|
|
165
|
140
|
static
|
166
|
141
|
void
|
167
|
|
-TR_commManagerEpollRemoveRead(void * _this, TR_Event event)
|
|
142
|
+TR_commManagerEpollDisableWrite(void * _this, TR_Event event)
|
168
|
143
|
{
|
169
|
144
|
TR_CommManagerEpoll this = _this;
|
170
|
145
|
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
|
|
146
|
+ int handle = endpoint->transport->handle;
|
|
147
|
+ struct epoll_event _event;
|
|
148
|
+
|
|
149
|
+ this->events[handle] &= ~EPOLLOUT;
|
|
150
|
+ _event.data.ptr = endpoint;
|
|
151
|
+ _event.events = this->events[handle];
|
171
|
152
|
|
172
|
|
- TR_queueDelete(this->read_ready, endpoint);
|
|
153
|
+ epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &_event);
|
173
|
154
|
}
|
174
|
155
|
|
175
|
156
|
static
|
176
|
157
|
void
|
177
|
|
-TR_commManagerEpollClose(void * _this, TR_Event event)
|
|
158
|
+TR_commManagerEpollEnableRead(void * _this, TR_Event event)
|
178
|
159
|
{
|
179
|
160
|
TR_CommManagerEpoll this = _this;
|
180
|
161
|
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
|
181
|
162
|
|
182
|
|
- TR_queueDelete(this->read_ready, endpoint);
|
183
|
|
- TR_queueDelete(this->write_ready, endpoint);
|
|
163
|
+ if (! TR_socketFinRd(endpoint->transport)) {
|
|
164
|
+ int handle = endpoint->transport->handle;
|
|
165
|
+ struct epoll_event _event;
|
184
|
166
|
|
185
|
|
- epoll_ctl(this->handle, EPOLL_CTL_DEL, endpoint->transport->handle, NULL);
|
|
167
|
+ this->events[handle] |= EPOLLIN;
|
|
168
|
+ _event.data.ptr = endpoint;
|
|
169
|
+ _event.events = this->events[handle];
|
|
170
|
+
|
|
171
|
+ epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &_event);
|
|
172
|
+ }
|
186
|
173
|
}
|
187
|
174
|
|
188
|
175
|
static
|
189
|
176
|
void
|
190
|
|
-TR_commManagerEpollShutRead(void * _this, TR_Event event)
|
|
177
|
+TR_commManagerEpollDisableRead(void * _this, TR_Event event)
|
191
|
178
|
{
|
192
|
179
|
TR_CommManagerEpoll this = _this;
|
193
|
180
|
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
|
|
181
|
+ int handle = endpoint->transport->handle;
|
194
|
182
|
struct epoll_event _event;
|
195
|
183
|
|
196
|
|
- TR_queueDelete(this->read_ready, endpoint);
|
197
|
|
-
|
|
184
|
+ this->events[handle] &= ~EPOLLIN;
|
198
|
185
|
_event.data.ptr = endpoint;
|
199
|
|
- _event.events = EPOLLOUT | EPOLLET;
|
|
186
|
+ _event.events = this->events[handle];
|
200
|
187
|
|
201
|
|
- epoll_ctl(
|
202
|
|
- this->handle,
|
203
|
|
- EPOLL_CTL_MOD,
|
204
|
|
- endpoint->transport->handle,
|
205
|
|
- &_event);
|
|
188
|
+ epoll_ctl(this->handle, EPOLL_CTL_MOD, handle, &_event);
|
206
|
189
|
}
|
207
|
190
|
|
208
|
191
|
static
|
209
|
192
|
void
|
210
|
|
-TR_commManagerEpollShutWrite(void * _this, TR_Event event)
|
|
193
|
+TR_commManagerEpollClose(void * _this, TR_Event event)
|
211
|
194
|
{
|
212
|
195
|
TR_CommManagerEpoll this = _this;
|
213
|
196
|
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
|
214
|
|
- struct epoll_event _event;
|
215
|
|
-
|
216
|
|
- TR_queueDelete(this->write_ready, endpoint);
|
217
|
197
|
|
218
|
|
- _event.data.ptr = endpoint;
|
219
|
|
- _event.events = EPOLLIN | EPOLLET;
|
220
|
|
-
|
221
|
|
- epoll_ctl(
|
222
|
|
- this->handle,
|
223
|
|
- EPOLL_CTL_MOD,
|
224
|
|
- endpoint->transport->handle,
|
225
|
|
- &_event);
|
|
198
|
+ epoll_ctl(this->handle, EPOLL_CTL_DEL, endpoint->transport->handle, NULL);
|
226
|
199
|
}
|
227
|
200
|
|
228
|
|
-
|
229
|
|
-static void TR_commManagerEpollNoop(void * _this, TR_Event event) {}
|
230
|
|
-
|
231
|
201
|
static
|
232
|
202
|
void
|
233
|
203
|
TR_commManagerEpollCvInit(TR_class_ptr cls) {
|
...
|
...
|
@@ -237,14 +207,14 @@ TR_commManagerEpollCvInit(TR_class_ptr cls) { |
237
|
207
|
TR_INIT_IFACE(TR_Class, commManagerEpollCtor, commManagerEpollDtor, NULL);
|
238
|
208
|
TR_INIT_IFACE(
|
239
|
209
|
TR_CommManager,
|
240
|
|
- TR_commManagerEpollAddEndpoint, // TR_CON_EVENT_NEW_CON
|
241
|
|
- TR_commManagerEpollSelect, // TR_DISPATCHER_EVENT_DATA_WAIT
|
242
|
|
- TR_commManagerEpollRemoveWrite, // TR_CEP_EVENT_PENDING_DATA => WRITE_BLOCK
|
243
|
|
- TR_commManagerEpollNoop, // TR_CEP_EVENT_END_DATA
|
244
|
|
- TR_commManagerEpollRemoveRead, // TR_CEP_EVENT_READ_BLOCK
|
245
|
|
- TR_commManagerEpollClose, // TR_CEP_EVENT_CLOSE
|
246
|
|
- TR_commManagerEpollShutWrite, // TR_CEP_EVENT_SHUT_READ
|
247
|
|
- TR_commManagerEpollShutRead); // TR_CEP_EVENT_SHUT_WRITE
|
|
210
|
+ TR_commManagerEpollAddEndpoint, // TR_CON_EVENT_NEW_CON
|
|
211
|
+ TR_commManagerEpollSelect, // TR_DISPATCHER_EVENT_DATA_WAIT
|
|
212
|
+ TR_commManagerEpollEnableWrite, // TR_CEP_EVENT_PENDING_DATA => WRITE_BLOCK
|
|
213
|
+ TR_commManagerEpollDisableWrite, // TR_CEP_EVENT_END_DATA
|
|
214
|
+ TR_commManagerEpollEnableRead, // TR_CEP_EVENT_READ_BLOCK
|
|
215
|
+ TR_commManagerEpollClose, // TR_CEP_EVENT_CLOSE
|
|
216
|
+ TR_commManagerEpollDisableWrite, // TR_CEP_EVENT_SHUT_READ
|
|
217
|
+ TR_commManagerEpollEnableRead); // TR_CEP_EVENT_SHUT_WRITE
|
248
|
218
|
TR_CREATE_CLASS(
|
249
|
219
|
TR_CommManagerEpoll,
|
250
|
220
|
TR_CommManager,
|
...
|
...
|
|