Showing
10 changed files
with
83 additions
and
69 deletions
| 1 | -nobase_include_HEADERS = trcomm.h \ | |
| 2 | - tr/comm_end_point.h \ | |
| 1 | +nobase_include_HEADERS = tr/comm_end_point.h \ | |
| 2 | + tr/comm_manager.h \ | |
| 3 | + tr/comm_manager_poll.h \ | |
| 4 | + tr/connect_entry_point.h \ | |
| 3 | 5 | tr/connection.h \ |
| 4 | 6 | tr/connector.h \ |
| 5 | - tr/protocol.h \ | |
| 6 | 7 | tr/proto_message.h \ |
| 7 | - tr/protocol/raw.h \ | |
| 8 | - tr/protocol/message_raw.h \ | |
| 8 | + tr/protocol.h \ | |
| 9 | 9 | tr/interface/comm_end_point.h \ |
| 10 | + tr/interface/comm_manager.h \ | |
| 10 | 11 | tr/interface/protocol.h |
| 12 | + | ... | ... |
| ... | ... | @@ -36,17 +36,17 @@ typedef void (* fptr_TR_commManagerEnableWrite)(void *, TR_Event); |
| 36 | 36 | typedef void (* fptr_TR_commManagerDisableWrite)(void *, TR_Event); |
| 37 | 37 | typedef void (* fptr_TR_commManagerClose)(void *, TR_Event); |
| 38 | 38 | typedef void (* fptr_TR_commManagerShutdownRead)(void *, TR_Event); |
| 39 | -typedef void (* fptr_TR_commManagerShutdownRead)(void *, TR_Event); | |
| 39 | +typedef void (* fptr_TR_commManagerShutdownWrite)(void *, TR_Event); | |
| 40 | 40 | |
| 41 | 41 | TR_INTERFACE(TR_CommManager) { |
| 42 | 42 | TR_IFID; |
| 43 | - fptr_TR_commManagerAddEndpoint addEndpoint; | |
| 44 | - fptr_TR_commManagerSelect select; | |
| 45 | - fptr_TR_commManagerEnableWrite enableWrite; | |
| 46 | - fptr_TR_commManagerDisableWrite disableWrite; | |
| 47 | - fptr_TR_commManagerClose close; | |
| 48 | - fptr_TR_commManagerShutdownRead shutdownWrite; | |
| 49 | - fptr_TR_commManagerShutdownRead shutdownRead; | |
| 43 | + fptr_TR_commManagerAddEndpoint addEndpoint; | |
| 44 | + fptr_TR_commManagerSelect select; | |
| 45 | + fptr_TR_commManagerEnableWrite enableWrite; | |
| 46 | + fptr_TR_commManagerDisableWrite disableWrite; | |
| 47 | + fptr_TR_commManagerClose close; | |
| 48 | + fptr_TR_commManagerShutdownRead shutdownWrite; | |
| 49 | + fptr_TR_commManagerShutdownWrite shutdownRead; | |
| 50 | 50 | }; |
| 51 | 51 | |
| 52 | 52 | void TR_commManagerAddEndpoint(void *, TR_CommEndPoint); | ... | ... |
| ... | ... | @@ -2,13 +2,15 @@ |
| 2 | 2 | #define __TR_COMM_H__ |
| 3 | 3 | |
| 4 | 4 | #include "tr/comm_end_point.h" |
| 5 | +#include "tr/comm_manager.h" | |
| 6 | +#include "tr/comm_manager_poll.h" | |
| 7 | +#include "tr/connect_entry_point.h" | |
| 5 | 8 | #include "tr/connection.h" |
| 6 | 9 | #include "tr/connector.h" |
| 7 | -#include "tr/protocol.h" | |
| 8 | 10 | #include "tr/proto_message.h" |
| 9 | -#include "tr/protocol/raw.h" | |
| 10 | -#include "tr/protocol/message_raw.h" | |
| 11 | +#include "tr/protocol.h" | |
| 11 | 12 | #include "tr/interface/comm_end_point.h" |
| 13 | +#include "tr/interface/comm_manager.h" | |
| 12 | 14 | #include "tr/interface/protocol.h" |
| 13 | 15 | |
| 14 | 16 | #endif // __TR_COMM_H__ | ... | ... |
| ... | ... | @@ -7,16 +7,20 @@ TRCOMM = cep_append_read_data.c \ |
| 7 | 7 | cep_append_write_data.c \ |
| 8 | 8 | cet_accept.c \ |
| 9 | 9 | comm_end_point.c \ |
| 10 | + comm_manager.c \ | |
| 11 | + comm_manager_poll.c \ | |
| 12 | + comm_manager_shutdown.c \ | |
| 10 | 13 | con_compose.c \ |
| 14 | + con_next_message.c \ | |
| 15 | + conn_entry_point.c \ | |
| 11 | 16 | connection.c \ |
| 12 | 17 | connector.c \ |
| 13 | - conn_entry_point.c \ | |
| 14 | - con_next_message.c \ | |
| 18 | + proto_message.c \ | |
| 15 | 19 | protocol.c \ |
| 16 | 20 | protocol_message_raw.c \ |
| 17 | 21 | protocol_raw.c \ |
| 18 | - proto_message.c \ | |
| 19 | 22 | i_comm_end_point.c \ |
| 23 | + i_comm_manager.c \ | |
| 20 | 24 | i_protocol.c |
| 21 | 25 | |
| 22 | 26 | lib_LTLIBRARIES = libtrcomm.la | ... | ... |
| ... | ... | @@ -21,6 +21,7 @@ |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | #include <unistd.h> |
| 24 | +#include <poll.h> | |
| 24 | 25 | |
| 25 | 26 | #include "trbase.h" |
| 26 | 27 | #include "trevent.h" |
| ... | ... | @@ -58,7 +59,7 @@ commManagerDtor(void * _this) |
| 58 | 59 | |
| 59 | 60 | static |
| 60 | 61 | int |
| 61 | -TR__commManagerAddEndpoint(void * _this, Event event) | |
| 62 | +TR__commManagerAddEndpoint(void * _this, TR_Event event) | |
| 62 | 63 | { |
| 63 | 64 | TR_commManagerAddEndpoint( |
| 64 | 65 | (TR_CommManager)_this, |
| ... | ... | @@ -71,7 +72,7 @@ void TR_commManagerEnableWrite(void *, TR_Event); |
| 71 | 72 | void TR_commManagerDisableWrite(void *, TR_Event); |
| 72 | 73 | void TR_commManagerClose(void *, TR_Event); |
| 73 | 74 | void TR_commManagerShutdownRead(void *, TR_Event); |
| 74 | -void TR_commManagerShutdownRead(void *, TR_Event); | |
| 75 | +void TR_commManagerShutdownWrite(void *, TR_Event); | |
| 75 | 76 | |
| 76 | 77 | static |
| 77 | 78 | void |
| ... | ... | @@ -98,13 +99,13 @@ commManagerCvInit(TR_class_ptr cls) |
| 98 | 99 | TR_EVENT_HANDLER_SET_METHOD( |
| 99 | 100 | cls, |
| 100 | 101 | TR_Connection, |
| 101 | - TR_CON_EVENT_PENDING_DATA, | |
| 102 | + TR_CEP_EVENT_PENDING_DATA, | |
| 102 | 103 | TR_commManagerEnableWrite); |
| 103 | 104 | |
| 104 | 105 | TR_EVENT_HANDLER_SET_METHOD( |
| 105 | 106 | cls, |
| 106 | 107 | TR_Connection, |
| 107 | - TR_CON_EVENT_END_DATA, | |
| 108 | + TR_CEP_EVENT_END_DATA, | |
| 108 | 109 | TR_commManagerDisableWrite); |
| 109 | 110 | |
| 110 | 111 | TR_EVENT_HANDLER_SET_METHOD( |
| ... | ... | @@ -126,7 +127,7 @@ commManagerCvInit(TR_class_ptr cls) |
| 126 | 127 | TR_commManagerShutdownWrite); |
| 127 | 128 | } |
| 128 | 129 | |
| 129 | -TR_INSTANCE(TR_Hash, _event_methods); | |
| 130 | +TR_INSTANCE(TR_Hash, commManagerEventMethods); | |
| 130 | 131 | TR_INIT_IFACE(TR_Class, commManagerCtor, commManagerDtor, NULL); |
| 131 | 132 | TR_INIT_IFACE(TR_CommManager, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
| 132 | 133 | TR_CREATE_CLASS( |
| ... | ... | @@ -135,7 +136,7 @@ TR_CREATE_CLASS( |
| 135 | 136 | commManagerCvInit, |
| 136 | 137 | TR_IF(TR_Class), |
| 137 | 138 | TR_IF(TR_CommManager)) = { |
| 138 | - { &(__event_methods.data) } | |
| 139 | + { &(_commManagerEventMethods.data) } | |
| 139 | 140 | }; |
| 140 | 141 | |
| 141 | 142 | // vim: set ts=4 sw=4: | ... | ... |
| ... | ... | @@ -21,14 +21,17 @@ |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | #include <unistd.h> |
| 24 | +#include <poll.h> | |
| 24 | 25 | |
| 25 | 26 | #include "trbase.h" |
| 26 | 27 | #include "trevent.h" |
| 27 | 28 | |
| 28 | -#include "tr/comm_end_point.h" | |
| 29 | -#include "tr/connection.h" | |
| 30 | 29 | #include "tr/comm_manager.h" |
| 30 | +#include "tr/comm_manager_poll.h" | |
| 31 | 31 | #include "tr/interface/comm_manager.h" |
| 32 | +#include "tr/comm_end_point.h" | |
| 33 | +#include "tr/connection.h" | |
| 34 | +#include "tr/connect_entry_point.h" | |
| 32 | 35 | |
| 33 | 36 | static |
| 34 | 37 | int |
| ... | ... | @@ -41,7 +44,9 @@ commManagerPollCtor(void * _this, va_list * params) |
| 41 | 44 | TR_PARENTCALL(_this, TR_Class, ctor, params); |
| 42 | 45 | this->fds = TR_malloc(sizeof(struct pollfd) * cmgr->n_endpoints); |
| 43 | 46 | for (i = 0; i < cmgr->n_endpoints; i++) { |
| 44 | - this->fds[i] = {-1, 0, 0}; | |
| 47 | + this->fds[i].fd = -1; | |
| 48 | + this->fds[i].events = 0; | |
| 49 | + this->fds[i].revents = 0; | |
| 45 | 50 | } |
| 46 | 51 | |
| 47 | 52 | return 0; |
| ... | ... | @@ -59,7 +64,7 @@ commManagerPollDtor(void * _this) |
| 59 | 64 | |
| 60 | 65 | static |
| 61 | 66 | void |
| 62 | -TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) | |
| 67 | +TR_commManagerPollAddEndpoint(void * _this, TR_CommEndPoint endpoint) | |
| 63 | 68 | { |
| 64 | 69 | TR_CommManagerPoll this = _this; |
| 65 | 70 | this->fds[endpoint->transport->handle].fd = endpoint->transport->handle; |
| ... | ... | @@ -68,7 +73,7 @@ TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
| 68 | 73 | |
| 69 | 74 | static |
| 70 | 75 | void |
| 71 | -TR_commManagerSelect(void * _this, TR_Event event, int timeout) | |
| 76 | +TR_commManagerPollSelect(void * _this, TR_Event event, int timeout) | |
| 72 | 77 | { |
| 73 | 78 | TR_CommManagerPoll this = _this; |
| 74 | 79 | TR_CommManager cmgr = _this; |
| ... | ... | @@ -77,33 +82,33 @@ TR_commManagerSelect(void * _this, TR_Event event, int timeout) |
| 77 | 82 | |
| 78 | 83 | nevents = poll(this->fds, cmgr->n_endpoints, timeout); |
| 79 | 84 | |
| 80 | - for (i = 0; i < cmgr->n_endpoints, i++) { | |
| 81 | - TR_CommEndPoint endpoint = this->endpoints[i]; | |
| 85 | + for (i = 0; i < cmgr->n_endpoints; i++) { | |
| 86 | + TR_CommEndPoint endpoint = cmgr->endpoints[i]; | |
| 82 | 87 | |
| 83 | - if (this->fds[i].revents & POLLIN == POLLIN) { | |
| 88 | + if ((this->fds[i].revents & POLLIN) == POLLIN) { | |
| 84 | 89 | nevents--; |
| 85 | - if (TR_INSTANCE_OF(TR_TcpSocket, endpoints->transport) | |
| 90 | + if (TR_INSTANCE_OF(TR_TcpSocket, endpoint->transport) | |
| 86 | 91 | && ((TR_TcpSocket)endpoint->transport)->listen) { |
| 87 | 92 | TR_eventHandlerIssueEvent( |
| 88 | 93 | (TR_EventHandler)this, |
| 89 | - (TR_Connection)endpoint, | |
| 90 | - TR_CON_EVENT_ACC_READY, | |
| 94 | + (TR_EventSubject)endpoint, | |
| 95 | + TR_CET_EVENT_ACC_READY, | |
| 91 | 96 | NULL); |
| 92 | 97 | } else { |
| 93 | 98 | TR_eventHandlerIssueEvent( |
| 94 | 99 | (TR_EventHandler)this, |
| 95 | - endpoint, | |
| 96 | - TR_CET_EVENT_READ_READY, | |
| 100 | + (TR_EventSubject)endpoint, | |
| 101 | + TR_CEP_EVENT_READ_READY, | |
| 97 | 102 | NULL); |
| 98 | 103 | } |
| 99 | 104 | } |
| 100 | 105 | |
| 101 | - if (this->fds[i].revents & POLLOUT == POLLOUT) { | |
| 106 | + if ((this->fds[i].revents & POLLOUT) == POLLOUT) { | |
| 102 | 107 | nevents--; |
| 103 | 108 | TR_eventHandlerIssueEvent( |
| 104 | 109 | (TR_EventHandler)this, |
| 105 | - endpoint, | |
| 106 | - TR_CET_EVENT_WRITE_READY, | |
| 110 | + (TR_EventSubject)endpoint, | |
| 111 | + TR_CEP_EVENT_WRITE_READY, | |
| 107 | 112 | NULL); |
| 108 | 113 | } |
| 109 | 114 | |
| ... | ... | @@ -113,56 +118,50 @@ TR_commManagerSelect(void * _this, TR_Event event, int timeout) |
| 113 | 118 | |
| 114 | 119 | static |
| 115 | 120 | void |
| 116 | -TR_commManagerEnableWrite(void * _this, TR_Event event) | |
| 121 | +TR_commManagerPollEnableWrite(void * _this, TR_Event event) | |
| 117 | 122 | { |
| 118 | 123 | TR_CommManagerPoll this = _this; |
| 119 | 124 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
| 120 | 125 | |
| 121 | 126 | if (! TR_socketFinWr(endpoint->transport)) { |
| 122 | - this->fds[endpoint->transport->handle].event |= POLLOUT; | |
| 127 | + this->fds[endpoint->transport->handle].events |= POLLOUT; | |
| 123 | 128 | } |
| 124 | 129 | } |
| 125 | 130 | |
| 126 | 131 | static |
| 127 | -int | |
| 128 | -TR_commManagerDisableWrite(void * _this, TR_Event event) | |
| 132 | +void | |
| 133 | +TR_commManagerPollDisableWrite(void * _this, TR_Event event) | |
| 129 | 134 | { |
| 130 | 135 | TR_CommManagerPoll this = _this; |
| 131 | 136 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
| 132 | 137 | |
| 133 | - this->fds[endpoint->transport->handle].event &= ~POLLOUT; | |
| 138 | + this->fds[endpoint->transport->handle].events &= ~POLLOUT; | |
| 134 | 139 | } |
| 135 | 140 | |
| 136 | 141 | static |
| 137 | -int | |
| 138 | -TR_commManagerClose(void * _this, TR_Event event) | |
| 142 | +void | |
| 143 | +TR_commManagerPollClose(void * _this, TR_Event event) | |
| 139 | 144 | { |
| 140 | 145 | TR_CommManagerPoll this = _this; |
| 141 | 146 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
| 142 | 147 | |
| 143 | - this->fds[endpoint->transport->handle].event = 0; | |
| 144 | - this->fds[endpoint->transport->handle].fs = -1; | |
| 148 | + this->fds[endpoint->transport->handle].events = 0; | |
| 149 | + this->fds[endpoint->transport->handle].fd = -1; | |
| 145 | 150 | } |
| 146 | 151 | |
| 147 | 152 | static |
| 148 | -int | |
| 149 | -TR_commManagerDisableRead(void * _this, TR_Event event) | |
| 153 | +void | |
| 154 | +TR_commManagerPollDisableRead(void * _this, TR_Event event) | |
| 150 | 155 | { |
| 151 | 156 | TR_CommManagerPoll this = _this; |
| 152 | 157 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
| 153 | 158 | |
| 154 | - this->fds[endpoint->transport->handle].event &= ~POLLIN; | |
| 155 | -} | |
| 156 | - | |
| 157 | -static | |
| 158 | -int | |
| 159 | -TR_commManagerShutdownRead(void * _this, TR_Event event) | |
| 160 | -{ | |
| 159 | + this->fds[endpoint->transport->handle].events &= ~POLLIN; | |
| 161 | 160 | } |
| 162 | 161 | |
| 163 | 162 | static |
| 164 | 163 | void |
| 165 | -commManagerPollCvInit(TR_class_ptr cls) { | |
| 164 | +TR_commManagerPollCvInit(TR_class_ptr cls) { | |
| 166 | 165 | TR_INHERIT_CLASSVARS(TR_CommManagerPoll, TR_CommManager); |
| 167 | 166 | } |
| 168 | 167 | |
| ... | ... | @@ -179,7 +178,7 @@ TR_INIT_IFACE( |
| 179 | 178 | TR_CREATE_CLASS( |
| 180 | 179 | TR_CommManagerPoll, |
| 181 | 180 | TR_CommManager, |
| 182 | - TR_CommManagerPollCvInit, | |
| 181 | + TR_commManagerPollCvInit, | |
| 183 | 182 | TR_IF(TR_Class)); |
| 184 | 183 | |
| 185 | 184 | // vim: set ts=4 sw=4: | ... | ... |
| ... | ... | @@ -20,6 +20,8 @@ |
| 20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | +#include <poll.h> | |
| 24 | + | |
| 23 | 25 | #include "trbase.h" |
| 24 | 26 | #include "trio.h" |
| 25 | 27 | #include "trevent.h" |
| ... | ... | @@ -33,10 +35,10 @@ TR_commManagerShutdown(void * _this, TR_Event event) |
| 33 | 35 | nfds_t i; |
| 34 | 36 | |
| 35 | 37 | for (i=0; i<this->n_endpoints; i++) { |
| 36 | - if (this->endpoints[handle]) { | |
| 38 | + if (this->endpoints[i]) { | |
| 37 | 39 | TR_eventHandlerIssueEvent( |
| 38 | 40 | (TR_EventHandler)_this, |
| 39 | - (TR_EventSubject)this->endpoints[handle], | |
| 41 | + (TR_EventSubject)this->endpoints[i], | |
| 40 | 42 | TR_CEP_EVENT_CLOSE, |
| 41 | 43 | NULL); |
| 42 | 44 | } | ... | ... |
| ... | ... | @@ -89,14 +89,14 @@ connectorCvInit(TR_class_ptr cls) |
| 89 | 89 | connectorAccept); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | -TR_INSTANCE(TR_Hash, _event_methods); | |
| 92 | +TR_INSTANCE(TR_Hash, connectorEventMethods); | |
| 93 | 93 | TR_INIT_IFACE(TR_Class, connectorCtor, connectorDtor, NULL); |
| 94 | 94 | TR_CREATE_CLASS( |
| 95 | 95 | TR_Connector, |
| 96 | 96 | TR_EventHandler, |
| 97 | 97 | connectorCvInit, |
| 98 | 98 | TR_IF(TR_Class)) = { |
| 99 | - { &(__event_methods.data) } | |
| 99 | + { &(_connectorEventMethods.data) } | |
| 100 | 100 | }; |
| 101 | 101 | |
| 102 | 102 | // vim: set ts=4 sw=4: | ... | ... |
| ... | ... | @@ -21,19 +21,21 @@ |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | #include <errno.h> |
| 24 | +#include <poll.h> | |
| 24 | 25 | |
| 25 | 26 | #include "trbase.h" |
| 26 | 27 | #include "trevent.h" |
| 27 | 28 | |
| 28 | 29 | #include "tr/interface/comm_manager.h" |
| 29 | 30 | #include "tr/comm_end_point.h" |
| 31 | +#include "tr/comm_manager.h" | |
| 30 | 32 | |
| 31 | 33 | TR_CREATE_INTERFACE(TR_CommManager, 7); |
| 32 | 34 | |
| 33 | 35 | void |
| 34 | 36 | TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) |
| 35 | 37 | { |
| 36 | - TR_ConnManager this = _this; | |
| 38 | + TR_CommManager this = _this; | |
| 37 | 39 | |
| 38 | 40 | if (this->endpoints[endpoint->transport->handle]) { |
| 39 | 41 | // this should never happen, but if so we assume this is a leftover |
| ... | ... | @@ -92,7 +94,7 @@ TR_commManagerDisableWrite(void * _this, TR_Event event) |
| 92 | 94 | int |
| 93 | 95 | TR_commManagerClose(void * _this, TR_Event event) |
| 94 | 96 | { |
| 95 | - TR_ConnManager this = _this; | |
| 97 | + TR_CommManager this = _this; | |
| 96 | 98 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
| 97 | 99 | |
| 98 | 100 | TR_socketShutdown(endpoint->transport); |
| ... | ... | @@ -114,7 +116,7 @@ TR_commManagerShutdownRead(void * _this, TR_Event event) |
| 114 | 116 | event->subject, |
| 115 | 117 | TR_CEP_EVENT_CLOSE, |
| 116 | 118 | NULL); |
| 117 | - } else if (TR_cepHasPendingData(endpoint)) { | |
| 119 | + } else if (TR_cepHasPendingData((TR_CommEndPoint)event->subject)) { | |
| 118 | 120 | // handle pending data... close is issued from disableWrite |
| 119 | 121 | TR_eventHandlerIssueEvent( |
| 120 | 122 | (TR_EventHandler)_this, |
| ... | ... | @@ -122,7 +124,7 @@ TR_commManagerShutdownRead(void * _this, TR_Event event) |
| 122 | 124 | TR_CEP_EVENT_CLOSE, |
| 123 | 125 | NULL); |
| 124 | 126 | } else { |
| 125 | - TR_cepSetClose(endpoint); | |
| 127 | + TR_cepSetClose((TR_CommEndPoint)event->subject); | |
| 126 | 128 | } |
| 127 | 129 | |
| 128 | 130 | return 0; | ... | ... |
Please
register
or
login
to post a comment