Commit 2885147eef0843edf109fe15a25989016128f35b
1 parent
2ee7035d
finish edge level trigger for socket notification
Showing
10 changed files
with
129 additions
and
65 deletions
@@ -45,16 +45,17 @@ TR_CLASSVARS_DECL(TR_CommEndPoint) { | @@ -45,16 +45,17 @@ TR_CLASSVARS_DECL(TR_CommEndPoint) { | ||
45 | }; | 45 | }; |
46 | 46 | ||
47 | #define TR_CEP_EVENT_READ_READY 0 | 47 | #define TR_CEP_EVENT_READ_READY 0 |
48 | -#define TR_CEP_EVENT_WRITE_READY 1 | ||
49 | -#define TR_CEP_EVENT_UPGRADE 2 | ||
50 | -#define TR_CEP_EVENT_NEW_DATA 3 | ||
51 | -#define TR_CEP_EVENT_PENDING_DATA 4 | ||
52 | -#define TR_CEP_EVENT_END_DATA 5 | ||
53 | -#define TR_CEP_EVENT_NEW_MSG 6 | ||
54 | -#define TR_CEP_EVENT_SEND_MSG 7 | ||
55 | -#define TR_CEP_EVENT_SHUT_READ 8 | ||
56 | -#define TR_CEP_EVENT_SHUT_WRITE 9 | ||
57 | -#define TR_CEP_EVENT_CLOSE 10 | 48 | +#define TR_CEP_EVENT_READ_BLOCK 1 |
49 | +#define TR_CEP_EVENT_WRITE_READY 2 | ||
50 | +#define TR_CEP_EVENT_UPGRADE 3 | ||
51 | +#define TR_CEP_EVENT_NEW_DATA 4 | ||
52 | +#define TR_CEP_EVENT_PENDING_DATA 5 | ||
53 | +#define TR_CEP_EVENT_END_DATA 6 | ||
54 | +#define TR_CEP_EVENT_NEW_MSG 7 | ||
55 | +#define TR_CEP_EVENT_SEND_MSG 8 | ||
56 | +#define TR_CEP_EVENT_SHUT_READ 9 | ||
57 | +#define TR_CEP_EVENT_SHUT_WRITE 10 | ||
58 | +#define TR_CEP_EVENT_CLOSE 11 | ||
58 | #define TR_CEP_EVENT_MAX ((size_t)TR_CEP_EVENT_CLOSE) | 59 | #define TR_CEP_EVENT_MAX ((size_t)TR_CEP_EVENT_CLOSE) |
59 | 60 | ||
60 | #define TR_cepSetClose(ep) ((ep)->do_close = 1) | 61 | #define TR_cepSetClose(ep) ((ep)->do_close = 1) |
@@ -34,6 +34,7 @@ typedef TR_EventDone (* fptr_TR_commManagerAddEndpoint)(void *, TR_CommEndPoint) | @@ -34,6 +34,7 @@ typedef TR_EventDone (* fptr_TR_commManagerAddEndpoint)(void *, TR_CommEndPoint) | ||
34 | typedef TR_EventDone (* fptr_TR_commManagerSelect)(void *, TR_Event, int); | 34 | typedef TR_EventDone (* fptr_TR_commManagerSelect)(void *, TR_Event, int); |
35 | typedef TR_EventDone (* fptr_TR_commManagerEnableWrite)(void *, TR_Event); | 35 | typedef TR_EventDone (* fptr_TR_commManagerEnableWrite)(void *, TR_Event); |
36 | typedef TR_EventDone (* fptr_TR_commManagerDisableWrite)(void *, TR_Event); | 36 | typedef TR_EventDone (* fptr_TR_commManagerDisableWrite)(void *, TR_Event); |
37 | +typedef TR_EventDone (* fptr_TR_commManagerEnableRead)(void *, TR_Event); | ||
37 | typedef TR_EventDone (* fptr_TR_commManagerClose)(void *, TR_Event); | 38 | typedef TR_EventDone (* fptr_TR_commManagerClose)(void *, TR_Event); |
38 | typedef TR_EventDone (* fptr_TR_commManagerShutdownRead)(void *, TR_Event); | 39 | typedef TR_EventDone (* fptr_TR_commManagerShutdownRead)(void *, TR_Event); |
39 | typedef TR_EventDone (* fptr_TR_commManagerShutdownWrite)(void *, TR_Event); | 40 | typedef TR_EventDone (* fptr_TR_commManagerShutdownWrite)(void *, TR_Event); |
@@ -44,6 +45,7 @@ TR_INTERFACE(TR_CommManager) { | @@ -44,6 +45,7 @@ TR_INTERFACE(TR_CommManager) { | ||
44 | fptr_TR_commManagerSelect select; | 45 | fptr_TR_commManagerSelect select; |
45 | fptr_TR_commManagerEnableWrite enableWrite; | 46 | fptr_TR_commManagerEnableWrite enableWrite; |
46 | fptr_TR_commManagerDisableWrite disableWrite; | 47 | fptr_TR_commManagerDisableWrite disableWrite; |
48 | + fptr_TR_commManagerEnableRead enableRead; | ||
47 | fptr_TR_commManagerClose close; | 49 | fptr_TR_commManagerClose close; |
48 | fptr_TR_commManagerShutdownRead shutdownWrite; | 50 | fptr_TR_commManagerShutdownRead shutdownWrite; |
49 | fptr_TR_commManagerShutdownWrite shutdownRead; | 51 | fptr_TR_commManagerShutdownWrite shutdownRead; |
@@ -29,19 +29,19 @@ int | @@ -29,19 +29,19 @@ int | ||
29 | TR_cepWriteBuffered(TR_CommEndPoint this) | 29 | TR_cepWriteBuffered(TR_CommEndPoint this) |
30 | { | 30 | { |
31 | TR_RemoteData data = TR_cepNextWriteData(this); | 31 | TR_RemoteData data = TR_cepNextWriteData(this); |
32 | - int send = 0; | 32 | + int send = TR_socketSend(this->transport, data); |
33 | 33 | ||
34 | - while (data) { | ||
35 | - int current_send = TR_socketSend(this->transport, data); | 34 | + switch (send) { |
35 | + case FALSE: // EAGAIN | ||
36 | + case -1: // FAILURE | ||
37 | + case -2: // remote close | ||
38 | + return send; | ||
36 | 39 | ||
37 | - send += current_send; | ||
38 | - // TODO if nothing was send put it back into the queue.. | ||
39 | - // and stop loop. (This was a close.) | ||
40 | - | ||
41 | - data = TR_cepNextWriteData(this); | 40 | + default: |
41 | + break; | ||
42 | } | 42 | } |
43 | 43 | ||
44 | - return TRUE; | 44 | + return send; |
45 | } | 45 | } |
46 | 46 | ||
47 | // vim: set ts=4 sw=4: | 47 | // vim: set ts=4 sw=4: |
@@ -64,6 +64,7 @@ void | @@ -64,6 +64,7 @@ void | ||
64 | commEndPointCvInit(TR_class_ptr cls) | 64 | commEndPointCvInit(TR_class_ptr cls) |
65 | { | 65 | { |
66 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_READ_READY); | 66 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_READ_READY); |
67 | + TR_EVENT_CREATE(cls, TR_CEP_EVENT_READ_BLOCK); | ||
67 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_WRITE_READY); | 68 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_WRITE_READY); |
68 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_UPGRADE); | 69 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_UPGRADE); |
69 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_NEW_DATA); | 70 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_NEW_DATA); |
@@ -72,6 +72,7 @@ TR__commManagerAddEndpoint(void * _this, TR_Event event) | @@ -72,6 +72,7 @@ TR__commManagerAddEndpoint(void * _this, TR_Event event) | ||
72 | TR_EventDone TR_commManagerSelect(void *, TR_Event, int); | 72 | TR_EventDone TR_commManagerSelect(void *, TR_Event, int); |
73 | TR_EventDone TR_commManagerEnableWrite(void *, TR_Event); | 73 | TR_EventDone TR_commManagerEnableWrite(void *, TR_Event); |
74 | TR_EventDone TR_commManagerDisableWrite(void *, TR_Event); | 74 | TR_EventDone TR_commManagerDisableWrite(void *, TR_Event); |
75 | +TR_EventDone TR_commManagerEnableRead(void *, TR_Event); | ||
75 | TR_EventDone TR_commManagerClose(void *, TR_Event); | 76 | TR_EventDone TR_commManagerClose(void *, TR_Event); |
76 | TR_EventDone TR_commManagerShutdownRead(void *, TR_Event); | 77 | TR_EventDone TR_commManagerShutdownRead(void *, TR_Event); |
77 | TR_EventDone TR_commManagerShutdownWrite(void *, TR_Event); | 78 | TR_EventDone TR_commManagerShutdownWrite(void *, TR_Event); |
@@ -108,6 +109,11 @@ commManagerCvInit(TR_class_ptr cls) | @@ -108,6 +109,11 @@ commManagerCvInit(TR_class_ptr cls) | ||
108 | TR_EVENT_HANDLER_SET_METHOD( | 109 | TR_EVENT_HANDLER_SET_METHOD( |
109 | cls, | 110 | cls, |
110 | TR_CommEndPoint, | 111 | TR_CommEndPoint, |
112 | + TR_CEP_EVENT_READ_BLOCK, | ||
113 | + TR_commManagerEnableRead); | ||
114 | + TR_EVENT_HANDLER_SET_METHOD( | ||
115 | + cls, | ||
116 | + TR_CommEndPoint, | ||
111 | TR_CEP_EVENT_CLOSE, | 117 | TR_CEP_EVENT_CLOSE, |
112 | TR_commManagerClose); | 118 | TR_commManagerClose); |
113 | TR_EVENT_HANDLER_SET_METHOD( | 119 | TR_EVENT_HANDLER_SET_METHOD( |
@@ -124,7 +130,7 @@ commManagerCvInit(TR_class_ptr cls) | @@ -124,7 +130,7 @@ commManagerCvInit(TR_class_ptr cls) | ||
124 | 130 | ||
125 | TR_INSTANCE(TR_Hash, commManagerEventMethods); | 131 | TR_INSTANCE(TR_Hash, commManagerEventMethods); |
126 | TR_INIT_IFACE(TR_Class, commManagerCtor, commManagerDtor, NULL); | 132 | TR_INIT_IFACE(TR_Class, commManagerCtor, commManagerDtor, NULL); |
127 | -TR_INIT_IFACE(TR_CommManager, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | 133 | +TR_INIT_IFACE(TR_CommManager, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
128 | TR_CREATE_CLASS( | 134 | TR_CREATE_CLASS( |
129 | TR_CommManager, | 135 | TR_CommManager, |
130 | TR_EventHandler, | 136 | TR_EventHandler, |
@@ -104,6 +104,7 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout) | @@ -104,6 +104,7 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout) | ||
104 | } | 104 | } |
105 | 105 | ||
106 | TR_eventHandlerIssueEvent((TR_EventHandler)this, event); | 106 | TR_eventHandlerIssueEvent((TR_EventHandler)this, event); |
107 | + this->fds[i].fd = -1; // this deactivates poll... | ||
107 | } | 108 | } |
108 | 109 | ||
109 | if ((this->fds[i].revents & POLLOUT) == POLLOUT) { | 110 | if ((this->fds[i].revents & POLLOUT) == POLLOUT) { |
@@ -114,6 +115,8 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout) | @@ -114,6 +115,8 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout) | ||
114 | (TR_EventSubject)endpoint, | 115 | (TR_EventSubject)endpoint, |
115 | TR_CEP_EVENT_WRITE_READY, | 116 | TR_CEP_EVENT_WRITE_READY, |
116 | NULL)); | 117 | NULL)); |
118 | + // deactivate write poll... | ||
119 | + this->fds[endpoint->transport->handle].events &= ~POLLOUT; | ||
117 | } | 120 | } |
118 | 121 | ||
119 | if (nevents <= 0) break; | 122 | if (nevents <= 0) break; |
@@ -145,6 +148,16 @@ TR_commManagerPollDisableWrite(void * _this, TR_Event event) | @@ -145,6 +148,16 @@ TR_commManagerPollDisableWrite(void * _this, TR_Event event) | ||
145 | 148 | ||
146 | static | 149 | static |
147 | void | 150 | void |
151 | +TR_commManagerPollEnableRead(void * _this, TR_Event event) | ||
152 | +{ | ||
153 | + TR_CommManagerPoll this = _this; | ||
154 | + TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; | ||
155 | + | ||
156 | + this->fds[endpoint->transport->handle].fd = endpoint->transport->handle; | ||
157 | +} | ||
158 | + | ||
159 | +static | ||
160 | +void | ||
148 | TR_commManagerPollClose(void * _this, TR_Event event) | 161 | TR_commManagerPollClose(void * _this, TR_Event event) |
149 | { | 162 | { |
150 | TR_CommManagerPoll this = _this; | 163 | TR_CommManagerPoll this = _this; |
@@ -177,6 +190,7 @@ TR_INIT_IFACE( | @@ -177,6 +190,7 @@ TR_INIT_IFACE( | ||
177 | TR_commManagerPollSelect, | 190 | TR_commManagerPollSelect, |
178 | TR_commManagerPollEnableWrite, | 191 | TR_commManagerPollEnableWrite, |
179 | TR_commManagerPollDisableWrite, | 192 | TR_commManagerPollDisableWrite, |
193 | + TR_commManagerPollEnableRead, | ||
180 | TR_commManagerPollClose, | 194 | TR_commManagerPollClose, |
181 | TR_commManagerPollDisableRead, | 195 | TR_commManagerPollDisableRead, |
182 | TR_commManagerPollDisableWrite); | 196 | TR_commManagerPollDisableWrite); |
@@ -74,6 +74,15 @@ connectorAccept(void * _this, TR_Event event) | @@ -74,6 +74,15 @@ connectorAccept(void * _this, TR_Event event) | ||
74 | socket = TR_socketAccept((TR_TcpSocket)connection->transport); | 74 | socket = TR_socketAccept((TR_TcpSocket)connection->transport); |
75 | } | 75 | } |
76 | 76 | ||
77 | + /* | ||
78 | + * reenable socket for poll | ||
79 | + */ | ||
80 | + TR_eventHandlerIssueEvent( | ||
81 | + (TR_EventHandler)_this, | ||
82 | + TR_eventSubjectEmit( | ||
83 | + (TR_EventSubject)connection, | ||
84 | + TR_CEP_EVENT_READ_BLOCK, | ||
85 | + NULL)); | ||
77 | /** | 86 | /** |
78 | * TODO we need to identify socket failures and close socket then. | 87 | * TODO we need to identify socket failures and close socket then. |
79 | */ | 88 | */ |
@@ -30,7 +30,7 @@ | @@ -30,7 +30,7 @@ | ||
30 | #include "tr/comm_end_point.h" | 30 | #include "tr/comm_end_point.h" |
31 | #include "tr/comm_manager.h" | 31 | #include "tr/comm_manager.h" |
32 | 32 | ||
33 | -TR_CREATE_INTERFACE(TR_CommManager, 7); | 33 | +TR_CREATE_INTERFACE(TR_CommManager, 8); |
34 | 34 | ||
35 | void | 35 | void |
36 | TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) | 36 | TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
@@ -98,6 +98,14 @@ TR_commManagerDisableWrite(void * _this, TR_Event event) | @@ -98,6 +98,14 @@ TR_commManagerDisableWrite(void * _this, TR_Event event) | ||
98 | } | 98 | } |
99 | 99 | ||
100 | TR_EventDone | 100 | TR_EventDone |
101 | +TR_commManagerEnableRead(void * _this, TR_Event event) | ||
102 | +{ | ||
103 | + TR_CALL(_this, TR_CommManager, enableRead, event); | ||
104 | + | ||
105 | + return TR_EVENT_DONE; | ||
106 | +} | ||
107 | + | ||
108 | +TR_EventDone | ||
101 | TR_commManagerClose(void * _this, TR_Event event) | 109 | TR_commManagerClose(void * _this, TR_Event event) |
102 | { | 110 | { |
103 | TR_CommManager this = _this; | 111 | TR_CommManager this = _this; |
@@ -44,75 +44,98 @@ static | @@ -44,75 +44,98 @@ static | ||
44 | TR_EventDone | 44 | TR_EventDone |
45 | ioHandlerRead(void * _this, TR_Event event) | 45 | ioHandlerRead(void * _this, TR_Event event) |
46 | { | 46 | { |
47 | + TR_Event revent; | ||
48 | + TR_EventDone done = TR_EVENT_DONE; | ||
49 | + | ||
47 | switch (TR_cepBufferRead((TR_CommEndPoint)event->subject)) { | 50 | switch (TR_cepBufferRead((TR_CommEndPoint)event->subject)) { |
48 | - default: | ||
49 | - case FALSE: | 51 | + case FALSE: // EAGAIN |
52 | + revent = TR_eventSubjectEmit( | ||
53 | + event->subject, | ||
54 | + TR_CEP_EVENT_READ_BLOCK, | ||
55 | + NULL); | ||
50 | break; | 56 | break; |
51 | 57 | ||
52 | case -1: // error | 58 | case -1: // error |
53 | - TR_eventHandlerIssueEvent( | ||
54 | - (TR_EventHandler)_this, | ||
55 | - TR_eventSubjectEmit( | ||
56 | - event->subject, | ||
57 | - TR_CEP_EVENT_CLOSE, | ||
58 | - NULL)); | 59 | + revent = TR_eventSubjectEmit( |
60 | + event->subject, | ||
61 | + TR_CEP_EVENT_CLOSE, | ||
62 | + NULL); | ||
59 | break; | 63 | break; |
60 | 64 | ||
65 | + default: | ||
61 | case -2: // remote close | 66 | case -2: // remote close |
62 | - TR_eventHandlerIssueEvent( | ||
63 | - (TR_EventHandler)_this, | ||
64 | - TR_eventSubjectEmit( | ||
65 | - event->subject, | ||
66 | - TR_CEP_EVENT_SHUT_READ, | ||
67 | - NULL)); | 67 | + revent = TR_eventSubjectEmit( |
68 | + event->subject, | ||
69 | + TR_CEP_EVENT_SHUT_READ, | ||
70 | + NULL); | ||
68 | break; | 71 | break; |
69 | 72 | ||
70 | case TRUE: | 73 | case TRUE: |
71 | - TR_eventHandlerIssueEvent( | ||
72 | - (TR_EventHandler)_this, | ||
73 | - TR_eventSubjectEmit( | ||
74 | - event->subject, | ||
75 | - TR_CEP_EVENT_NEW_DATA, | ||
76 | - NULL)); | 74 | + revent = TR_eventSubjectEmit( |
75 | + event->subject, | ||
76 | + TR_CEP_EVENT_NEW_DATA, | ||
77 | + NULL); | ||
78 | + | ||
79 | + done = TR_EVENT_PENDING; | ||
77 | break; | 80 | break; |
78 | } | 81 | } |
79 | 82 | ||
80 | - return TR_EVENT_DONE; | 83 | + TR_eventHandlerIssueEvent((TR_EventHandler)_this, revent); |
84 | + return done; | ||
81 | } | 85 | } |
82 | 86 | ||
83 | static | 87 | static |
84 | TR_EventDone | 88 | TR_EventDone |
85 | ioHandlerWrite(void * _this, TR_Event event) | 89 | ioHandlerWrite(void * _this, TR_Event event) |
86 | { | 90 | { |
87 | - TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; | 91 | + TR_Event revent, close_event = NULL; |
92 | + TR_EventDone done = TR_EVENT_DONE; | ||
93 | + | ||
94 | + switch (TR_cepWriteBuffered((TR_CommEndPoint)event->subject)) { | ||
95 | + case FALSE: // EAGAIN | ||
96 | + revent = TR_eventSubjectEmit( | ||
97 | + event->subject, | ||
98 | + TR_CEP_EVENT_PENDING_DATA, | ||
99 | + NULL); | ||
100 | + break; | ||
88 | 101 | ||
89 | - if (TR_cepWriteBuffered(endpoint)) { | ||
90 | - if (TR_cepHasPendingData(endpoint)) { | ||
91 | - TR_eventHandlerIssueEvent( | ||
92 | - (TR_EventHandler)_this, | ||
93 | - TR_eventSubjectEmit( | ||
94 | - event->subject, | ||
95 | - TR_CEP_EVENT_PENDING_DATA, | ||
96 | - NULL)); | ||
97 | - } else { | ||
98 | - TR_eventHandlerIssueEvent( | ||
99 | - (TR_EventHandler)_this, | ||
100 | - TR_eventSubjectEmit( | 102 | + case -1: // FAILURE |
103 | + revent = TR_eventSubjectEmit( | ||
104 | + event->subject, | ||
105 | + TR_CEP_EVENT_CLOSE, | ||
106 | + NULL); | ||
107 | + break; | ||
108 | + | ||
109 | + case -2: // remote close | ||
110 | + revent = TR_eventSubjectEmit( | ||
111 | + event->subject, | ||
112 | + TR_CEP_EVENT_SHUT_WRITE, | ||
113 | + NULL); | ||
114 | + break; | ||
115 | + | ||
116 | + default: | ||
117 | + if (TR_cepHasPendingData((TR_CommEndPoint)event->subject)) { | ||
118 | + done = TR_EVENT_PENDING; | ||
119 | + } else { | ||
120 | + revent = TR_eventSubjectEmit( | ||
101 | event->subject, | 121 | event->subject, |
102 | TR_CEP_EVENT_END_DATA, | 122 | TR_CEP_EVENT_END_DATA, |
103 | - NULL)); | ||
104 | - if (TRUE == endpoint->do_close) { | ||
105 | - TR_eventHandlerIssueEvent( | ||
106 | - (TR_EventHandler)_this, | ||
107 | - TR_eventSubjectEmit( | 123 | + NULL); |
124 | + | ||
125 | + if (TRUE == ((TR_CommEndPoint)event->subject)->do_close) { | ||
126 | + close_event = TR_eventSubjectEmit( | ||
108 | event->subject, | 127 | event->subject, |
109 | TR_CEP_EVENT_CLOSE, | 128 | TR_CEP_EVENT_CLOSE, |
110 | - NULL)); | 129 | + NULL); |
130 | + } | ||
111 | } | 131 | } |
112 | - } | ||
113 | } | 132 | } |
114 | 133 | ||
115 | - return TR_EVENT_DONE; | 134 | + TR_eventHandlerIssueEvent((TR_EventHandler)_this, revent); |
135 | + if (close_event) { | ||
136 | + TR_eventHandlerIssueEvent((TR_EventHandler)_this, close_event); | ||
137 | + } | ||
138 | + return done; | ||
116 | } | 139 | } |
117 | 140 | ||
118 | static | 141 | static |
@@ -2,9 +2,9 @@ | @@ -2,9 +2,9 @@ | ||
2 | 2 | ||
3 | pids="" | 3 | pids="" |
4 | i=0 | 4 | i=0 |
5 | -while [ $i -lt 400 ] | 5 | +while [ $i -lt 20 ] |
6 | do | 6 | do |
7 | - dd if=/dev/zero bs=8192 count=2500 | nc 192.168.2.13 5678 & | 7 | + dd if=/dev/zero bs=8192 count=25000 | nc -u localhost 5678 & |
8 | pids="${pids} $!" | 8 | pids="${pids} $!" |
9 | i=$((i + 1)) | 9 | i=$((i + 1)) |
10 | done | 10 | done |
Please
register
or
login
to post a comment