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 | 45 | }; |
| 46 | 46 | |
| 47 | 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 | 59 | #define TR_CEP_EVENT_MAX ((size_t)TR_CEP_EVENT_CLOSE) |
| 59 | 60 | |
| 60 | 61 | #define TR_cepSetClose(ep) ((ep)->do_close = 1) | ... | ... |
| ... | ... | @@ -34,6 +34,7 @@ typedef TR_EventDone (* fptr_TR_commManagerAddEndpoint)(void *, TR_CommEndPoint) |
| 34 | 34 | typedef TR_EventDone (* fptr_TR_commManagerSelect)(void *, TR_Event, int); |
| 35 | 35 | typedef TR_EventDone (* fptr_TR_commManagerEnableWrite)(void *, TR_Event); |
| 36 | 36 | typedef TR_EventDone (* fptr_TR_commManagerDisableWrite)(void *, TR_Event); |
| 37 | +typedef TR_EventDone (* fptr_TR_commManagerEnableRead)(void *, TR_Event); | |
| 37 | 38 | typedef TR_EventDone (* fptr_TR_commManagerClose)(void *, TR_Event); |
| 38 | 39 | typedef TR_EventDone (* fptr_TR_commManagerShutdownRead)(void *, TR_Event); |
| 39 | 40 | typedef TR_EventDone (* fptr_TR_commManagerShutdownWrite)(void *, TR_Event); |
| ... | ... | @@ -44,6 +45,7 @@ TR_INTERFACE(TR_CommManager) { |
| 44 | 45 | fptr_TR_commManagerSelect select; |
| 45 | 46 | fptr_TR_commManagerEnableWrite enableWrite; |
| 46 | 47 | fptr_TR_commManagerDisableWrite disableWrite; |
| 48 | + fptr_TR_commManagerEnableRead enableRead; | |
| 47 | 49 | fptr_TR_commManagerClose close; |
| 48 | 50 | fptr_TR_commManagerShutdownRead shutdownWrite; |
| 49 | 51 | fptr_TR_commManagerShutdownWrite shutdownRead; | ... | ... |
| ... | ... | @@ -29,19 +29,19 @@ int |
| 29 | 29 | TR_cepWriteBuffered(TR_CommEndPoint this) |
| 30 | 30 | { |
| 31 | 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 | 47 | // vim: set ts=4 sw=4: | ... | ... |
| ... | ... | @@ -64,6 +64,7 @@ void |
| 64 | 64 | commEndPointCvInit(TR_class_ptr cls) |
| 65 | 65 | { |
| 66 | 66 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_READ_READY); |
| 67 | + TR_EVENT_CREATE(cls, TR_CEP_EVENT_READ_BLOCK); | |
| 67 | 68 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_WRITE_READY); |
| 68 | 69 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_UPGRADE); |
| 69 | 70 | TR_EVENT_CREATE(cls, TR_CEP_EVENT_NEW_DATA); | ... | ... |
| ... | ... | @@ -72,6 +72,7 @@ TR__commManagerAddEndpoint(void * _this, TR_Event event) |
| 72 | 72 | TR_EventDone TR_commManagerSelect(void *, TR_Event, int); |
| 73 | 73 | TR_EventDone TR_commManagerEnableWrite(void *, TR_Event); |
| 74 | 74 | TR_EventDone TR_commManagerDisableWrite(void *, TR_Event); |
| 75 | +TR_EventDone TR_commManagerEnableRead(void *, TR_Event); | |
| 75 | 76 | TR_EventDone TR_commManagerClose(void *, TR_Event); |
| 76 | 77 | TR_EventDone TR_commManagerShutdownRead(void *, TR_Event); |
| 77 | 78 | TR_EventDone TR_commManagerShutdownWrite(void *, TR_Event); |
| ... | ... | @@ -108,6 +109,11 @@ commManagerCvInit(TR_class_ptr cls) |
| 108 | 109 | TR_EVENT_HANDLER_SET_METHOD( |
| 109 | 110 | cls, |
| 110 | 111 | TR_CommEndPoint, |
| 112 | + TR_CEP_EVENT_READ_BLOCK, | |
| 113 | + TR_commManagerEnableRead); | |
| 114 | + TR_EVENT_HANDLER_SET_METHOD( | |
| 115 | + cls, | |
| 116 | + TR_CommEndPoint, | |
| 111 | 117 | TR_CEP_EVENT_CLOSE, |
| 112 | 118 | TR_commManagerClose); |
| 113 | 119 | TR_EVENT_HANDLER_SET_METHOD( |
| ... | ... | @@ -124,7 +130,7 @@ commManagerCvInit(TR_class_ptr cls) |
| 124 | 130 | |
| 125 | 131 | TR_INSTANCE(TR_Hash, commManagerEventMethods); |
| 126 | 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 | 134 | TR_CREATE_CLASS( |
| 129 | 135 | TR_CommManager, |
| 130 | 136 | TR_EventHandler, | ... | ... |
| ... | ... | @@ -104,6 +104,7 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout) |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | TR_eventHandlerIssueEvent((TR_EventHandler)this, event); |
| 107 | + this->fds[i].fd = -1; // this deactivates poll... | |
| 107 | 108 | } |
| 108 | 109 | |
| 109 | 110 | if ((this->fds[i].revents & POLLOUT) == POLLOUT) { |
| ... | ... | @@ -114,6 +115,8 @@ TR_commManagerPollSelect(void * _this, TR_Event event, int timeout) |
| 114 | 115 | (TR_EventSubject)endpoint, |
| 115 | 116 | TR_CEP_EVENT_WRITE_READY, |
| 116 | 117 | NULL)); |
| 118 | + // deactivate write poll... | |
| 119 | + this->fds[endpoint->transport->handle].events &= ~POLLOUT; | |
| 117 | 120 | } |
| 118 | 121 | |
| 119 | 122 | if (nevents <= 0) break; |
| ... | ... | @@ -145,6 +148,16 @@ TR_commManagerPollDisableWrite(void * _this, TR_Event event) |
| 145 | 148 | |
| 146 | 149 | static |
| 147 | 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 | 161 | TR_commManagerPollClose(void * _this, TR_Event event) |
| 149 | 162 | { |
| 150 | 163 | TR_CommManagerPoll this = _this; |
| ... | ... | @@ -177,6 +190,7 @@ TR_INIT_IFACE( |
| 177 | 190 | TR_commManagerPollSelect, |
| 178 | 191 | TR_commManagerPollEnableWrite, |
| 179 | 192 | TR_commManagerPollDisableWrite, |
| 193 | + TR_commManagerPollEnableRead, | |
| 180 | 194 | TR_commManagerPollClose, |
| 181 | 195 | TR_commManagerPollDisableRead, |
| 182 | 196 | TR_commManagerPollDisableWrite); | ... | ... |
| ... | ... | @@ -74,6 +74,15 @@ connectorAccept(void * _this, TR_Event event) |
| 74 | 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 | 87 | * TODO we need to identify socket failures and close socket then. |
| 79 | 88 | */ | ... | ... |
| ... | ... | @@ -30,7 +30,7 @@ |
| 30 | 30 | #include "tr/comm_end_point.h" |
| 31 | 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 | 35 | void |
| 36 | 36 | TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
| ... | ... | @@ -98,6 +98,14 @@ TR_commManagerDisableWrite(void * _this, TR_Event event) |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 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 | 109 | TR_commManagerClose(void * _this, TR_Event event) |
| 102 | 110 | { |
| 103 | 111 | TR_CommManager this = _this; | ... | ... |
| ... | ... | @@ -44,75 +44,98 @@ static |
| 44 | 44 | TR_EventDone |
| 45 | 45 | ioHandlerRead(void * _this, TR_Event event) |
| 46 | 46 | { |
| 47 | + TR_Event revent; | |
| 48 | + TR_EventDone done = TR_EVENT_DONE; | |
| 49 | + | |
| 47 | 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 | 56 | break; |
| 51 | 57 | |
| 52 | 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 | 63 | break; |
| 60 | 64 | |
| 65 | + default: | |
| 61 | 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 | 71 | break; |
| 69 | 72 | |
| 70 | 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 | 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 | 87 | static |
| 84 | 88 | TR_EventDone |
| 85 | 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 | 121 | event->subject, |
| 102 | 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 | 127 | event->subject, |
| 109 | 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 | 141 | static | ... | ... |
Please
register
or
login
to post a comment