diff --git a/include/Makefile.am b/include/Makefile.am index 49a1500..da5c874 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,10 +1,12 @@ -nobase_include_HEADERS = trcomm.h \ - tr/comm_end_point.h \ +nobase_include_HEADERS = tr/comm_end_point.h \ + tr/comm_manager.h \ + tr/comm_manager_poll.h \ + tr/connect_entry_point.h \ tr/connection.h \ tr/connector.h \ - tr/protocol.h \ tr/proto_message.h \ - tr/protocol/raw.h \ - tr/protocol/message_raw.h \ + tr/protocol.h \ tr/interface/comm_end_point.h \ + tr/interface/comm_manager.h \ tr/interface/protocol.h + diff --git a/include/tr/comm_manager.h b/include/tr/comm_manager.h index e1027f7..9e98816 100644 --- a/include/tr/comm_manager.h +++ b/include/tr/comm_manager.h @@ -28,6 +28,8 @@ #include "trbase.h" #include "trevent.h" +#include "tr/comm_end_point.h" + TR_CLASS(TR_CommManager) { TR_EXTENDS(TR_EventHandler); diff --git a/include/tr/interface/comm_manager.h b/include/tr/interface/comm_manager.h index c440c1e..50cc755 100644 --- a/include/tr/interface/comm_manager.h +++ b/include/tr/interface/comm_manager.h @@ -36,17 +36,17 @@ typedef void (* fptr_TR_commManagerEnableWrite)(void *, TR_Event); typedef void (* fptr_TR_commManagerDisableWrite)(void *, TR_Event); typedef void (* fptr_TR_commManagerClose)(void *, TR_Event); typedef void (* fptr_TR_commManagerShutdownRead)(void *, TR_Event); -typedef void (* fptr_TR_commManagerShutdownRead)(void *, TR_Event); +typedef void (* fptr_TR_commManagerShutdownWrite)(void *, TR_Event); TR_INTERFACE(TR_CommManager) { TR_IFID; - fptr_TR_commManagerAddEndpoint addEndpoint; - fptr_TR_commManagerSelect select; - fptr_TR_commManagerEnableWrite enableWrite; - fptr_TR_commManagerDisableWrite disableWrite; - fptr_TR_commManagerClose close; - fptr_TR_commManagerShutdownRead shutdownWrite; - fptr_TR_commManagerShutdownRead shutdownRead; + fptr_TR_commManagerAddEndpoint addEndpoint; + fptr_TR_commManagerSelect select; + fptr_TR_commManagerEnableWrite enableWrite; + fptr_TR_commManagerDisableWrite disableWrite; + fptr_TR_commManagerClose close; + fptr_TR_commManagerShutdownRead shutdownWrite; + fptr_TR_commManagerShutdownWrite shutdownRead; }; void TR_commManagerAddEndpoint(void *, TR_CommEndPoint); diff --git a/include/trcomm.h b/include/trcomm.h index 368d82a..fd8b44d 100644 --- a/include/trcomm.h +++ b/include/trcomm.h @@ -2,13 +2,15 @@ #define __TR_COMM_H__ #include "tr/comm_end_point.h" +#include "tr/comm_manager.h" +#include "tr/comm_manager_poll.h" +#include "tr/connect_entry_point.h" #include "tr/connection.h" #include "tr/connector.h" -#include "tr/protocol.h" #include "tr/proto_message.h" -#include "tr/protocol/raw.h" -#include "tr/protocol/message_raw.h" +#include "tr/protocol.h" #include "tr/interface/comm_end_point.h" +#include "tr/interface/comm_manager.h" #include "tr/interface/protocol.h" #endif // __TR_COMM_H__ diff --git a/src/Makefile.am b/src/Makefile.am index 79edbcd..0d991be 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,16 +7,20 @@ TRCOMM = cep_append_read_data.c \ cep_append_write_data.c \ cet_accept.c \ comm_end_point.c \ + comm_manager.c \ + comm_manager_poll.c \ + comm_manager_shutdown.c \ con_compose.c \ + con_next_message.c \ + conn_entry_point.c \ connection.c \ connector.c \ - conn_entry_point.c \ - con_next_message.c \ + proto_message.c \ protocol.c \ protocol_message_raw.c \ protocol_raw.c \ - proto_message.c \ i_comm_end_point.c \ + i_comm_manager.c \ i_protocol.c lib_LTLIBRARIES = libtrcomm.la diff --git a/src/comm_manager.c b/src/comm_manager.c index bf245b5..a9b903b 100644 --- a/src/comm_manager.c +++ b/src/comm_manager.c @@ -21,6 +21,7 @@ */ #include +#include #include "trbase.h" #include "trevent.h" @@ -58,7 +59,7 @@ commManagerDtor(void * _this) static int -TR__commManagerAddEndpoint(void * _this, Event event) +TR__commManagerAddEndpoint(void * _this, TR_Event event) { TR_commManagerAddEndpoint( (TR_CommManager)_this, @@ -71,7 +72,7 @@ void TR_commManagerEnableWrite(void *, TR_Event); void TR_commManagerDisableWrite(void *, TR_Event); void TR_commManagerClose(void *, TR_Event); void TR_commManagerShutdownRead(void *, TR_Event); -void TR_commManagerShutdownRead(void *, TR_Event); +void TR_commManagerShutdownWrite(void *, TR_Event); static void @@ -98,13 +99,13 @@ commManagerCvInit(TR_class_ptr cls) TR_EVENT_HANDLER_SET_METHOD( cls, TR_Connection, - TR_CON_EVENT_PENDING_DATA, + TR_CEP_EVENT_PENDING_DATA, TR_commManagerEnableWrite); TR_EVENT_HANDLER_SET_METHOD( cls, TR_Connection, - TR_CON_EVENT_END_DATA, + TR_CEP_EVENT_END_DATA, TR_commManagerDisableWrite); TR_EVENT_HANDLER_SET_METHOD( @@ -126,7 +127,7 @@ commManagerCvInit(TR_class_ptr cls) TR_commManagerShutdownWrite); } -TR_INSTANCE(TR_Hash, _event_methods); +TR_INSTANCE(TR_Hash, commManagerEventMethods); TR_INIT_IFACE(TR_Class, commManagerCtor, commManagerDtor, NULL); TR_INIT_IFACE(TR_CommManager, NULL, NULL, NULL, NULL, NULL, NULL, NULL); TR_CREATE_CLASS( @@ -135,7 +136,7 @@ TR_CREATE_CLASS( commManagerCvInit, TR_IF(TR_Class), TR_IF(TR_CommManager)) = { - { &(__event_methods.data) } + { &(_commManagerEventMethods.data) } }; // vim: set ts=4 sw=4: diff --git a/src/comm_manager_poll.c b/src/comm_manager_poll.c index bbaad41..154e790 100644 --- a/src/comm_manager_poll.c +++ b/src/comm_manager_poll.c @@ -21,14 +21,17 @@ */ #include +#include #include "trbase.h" #include "trevent.h" -#include "tr/comm_end_point.h" -#include "tr/connection.h" #include "tr/comm_manager.h" +#include "tr/comm_manager_poll.h" #include "tr/interface/comm_manager.h" +#include "tr/comm_end_point.h" +#include "tr/connection.h" +#include "tr/connect_entry_point.h" static int @@ -41,7 +44,9 @@ commManagerPollCtor(void * _this, va_list * params) TR_PARENTCALL(_this, TR_Class, ctor, params); this->fds = TR_malloc(sizeof(struct pollfd) * cmgr->n_endpoints); for (i = 0; i < cmgr->n_endpoints; i++) { - this->fds[i] = {-1, 0, 0}; + this->fds[i].fd = -1; + this->fds[i].events = 0; + this->fds[i].revents = 0; } return 0; @@ -59,7 +64,7 @@ commManagerPollDtor(void * _this) static void -TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) +TR_commManagerPollAddEndpoint(void * _this, TR_CommEndPoint endpoint) { TR_CommManagerPoll this = _this; this->fds[endpoint->transport->handle].fd = endpoint->transport->handle; @@ -68,7 +73,7 @@ TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) static void -TR_commManagerSelect(void * _this, TR_Event event, int timeout) +TR_commManagerPollSelect(void * _this, TR_Event event, int timeout) { TR_CommManagerPoll this = _this; TR_CommManager cmgr = _this; @@ -77,33 +82,33 @@ TR_commManagerSelect(void * _this, TR_Event event, int timeout) nevents = poll(this->fds, cmgr->n_endpoints, timeout); - for (i = 0; i < cmgr->n_endpoints, i++) { - TR_CommEndPoint endpoint = this->endpoints[i]; + for (i = 0; i < cmgr->n_endpoints; i++) { + TR_CommEndPoint endpoint = cmgr->endpoints[i]; - if (this->fds[i].revents & POLLIN == POLLIN) { + if ((this->fds[i].revents & POLLIN) == POLLIN) { nevents--; - if (TR_INSTANCE_OF(TR_TcpSocket, endpoints->transport) + if (TR_INSTANCE_OF(TR_TcpSocket, endpoint->transport) && ((TR_TcpSocket)endpoint->transport)->listen) { TR_eventHandlerIssueEvent( (TR_EventHandler)this, - (TR_Connection)endpoint, - TR_CON_EVENT_ACC_READY, + (TR_EventSubject)endpoint, + TR_CET_EVENT_ACC_READY, NULL); } else { TR_eventHandlerIssueEvent( (TR_EventHandler)this, - endpoint, - TR_CET_EVENT_READ_READY, + (TR_EventSubject)endpoint, + TR_CEP_EVENT_READ_READY, NULL); } } - if (this->fds[i].revents & POLLOUT == POLLOUT) { + if ((this->fds[i].revents & POLLOUT) == POLLOUT) { nevents--; TR_eventHandlerIssueEvent( (TR_EventHandler)this, - endpoint, - TR_CET_EVENT_WRITE_READY, + (TR_EventSubject)endpoint, + TR_CEP_EVENT_WRITE_READY, NULL); } @@ -113,56 +118,50 @@ TR_commManagerSelect(void * _this, TR_Event event, int timeout) static void -TR_commManagerEnableWrite(void * _this, TR_Event event) +TR_commManagerPollEnableWrite(void * _this, TR_Event event) { TR_CommManagerPoll this = _this; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; if (! TR_socketFinWr(endpoint->transport)) { - this->fds[endpoint->transport->handle].event |= POLLOUT; + this->fds[endpoint->transport->handle].events |= POLLOUT; } } static -int -TR_commManagerDisableWrite(void * _this, TR_Event event) +void +TR_commManagerPollDisableWrite(void * _this, TR_Event event) { TR_CommManagerPoll this = _this; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; - this->fds[endpoint->transport->handle].event &= ~POLLOUT; + this->fds[endpoint->transport->handle].events &= ~POLLOUT; } static -int -TR_commManagerClose(void * _this, TR_Event event) +void +TR_commManagerPollClose(void * _this, TR_Event event) { TR_CommManagerPoll this = _this; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; - this->fds[endpoint->transport->handle].event = 0; - this->fds[endpoint->transport->handle].fs = -1; + this->fds[endpoint->transport->handle].events = 0; + this->fds[endpoint->transport->handle].fd = -1; } static -int -TR_commManagerDisableRead(void * _this, TR_Event event) +void +TR_commManagerPollDisableRead(void * _this, TR_Event event) { TR_CommManagerPoll this = _this; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; - this->fds[endpoint->transport->handle].event &= ~POLLIN; -} - -static -int -TR_commManagerShutdownRead(void * _this, TR_Event event) -{ + this->fds[endpoint->transport->handle].events &= ~POLLIN; } static void -commManagerPollCvInit(TR_class_ptr cls) { +TR_commManagerPollCvInit(TR_class_ptr cls) { TR_INHERIT_CLASSVARS(TR_CommManagerPoll, TR_CommManager); } @@ -179,7 +178,7 @@ TR_INIT_IFACE( TR_CREATE_CLASS( TR_CommManagerPoll, TR_CommManager, - TR_CommManagerPollCvInit, + TR_commManagerPollCvInit, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/comm_manager_shutdown.c b/src/comm_manager_shutdown.c index 741352f..474dde5 100644 --- a/src/comm_manager_shutdown.c +++ b/src/comm_manager_shutdown.c @@ -20,6 +20,8 @@ * along with this program. If not, see . */ +#include + #include "trbase.h" #include "trio.h" #include "trevent.h" @@ -33,10 +35,10 @@ TR_commManagerShutdown(void * _this, TR_Event event) nfds_t i; for (i=0; in_endpoints; i++) { - if (this->endpoints[handle]) { + if (this->endpoints[i]) { TR_eventHandlerIssueEvent( (TR_EventHandler)_this, - (TR_EventSubject)this->endpoints[handle], + (TR_EventSubject)this->endpoints[i], TR_CEP_EVENT_CLOSE, NULL); } diff --git a/src/connector.c b/src/connector.c index 8e0a273..93dbbdf 100644 --- a/src/connector.c +++ b/src/connector.c @@ -89,14 +89,14 @@ connectorCvInit(TR_class_ptr cls) connectorAccept); } -TR_INSTANCE(TR_Hash, _event_methods); +TR_INSTANCE(TR_Hash, connectorEventMethods); TR_INIT_IFACE(TR_Class, connectorCtor, connectorDtor, NULL); TR_CREATE_CLASS( TR_Connector, TR_EventHandler, connectorCvInit, TR_IF(TR_Class)) = { - { &(__event_methods.data) } + { &(_connectorEventMethods.data) } }; // vim: set ts=4 sw=4: diff --git a/src/i_comm_manager.c b/src/i_comm_manager.c index 1f56f8e..76e49be 100644 --- a/src/i_comm_manager.c +++ b/src/i_comm_manager.c @@ -21,19 +21,21 @@ */ #include +#include #include "trbase.h" #include "trevent.h" #include "tr/interface/comm_manager.h" #include "tr/comm_end_point.h" +#include "tr/comm_manager.h" TR_CREATE_INTERFACE(TR_CommManager, 7); void TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) { - TR_ConnManager this = _this; + TR_CommManager this = _this; if (this->endpoints[endpoint->transport->handle]) { // this should never happen, but if so we assume this is a leftover @@ -92,7 +94,7 @@ TR_commManagerDisableWrite(void * _this, TR_Event event) int TR_commManagerClose(void * _this, TR_Event event) { - TR_ConnManager this = _this; + TR_CommManager this = _this; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; TR_socketShutdown(endpoint->transport); @@ -114,7 +116,7 @@ TR_commManagerShutdownRead(void * _this, TR_Event event) event->subject, TR_CEP_EVENT_CLOSE, NULL); - } else if (TR_cepHasPendingData(endpoint)) { + } else if (TR_cepHasPendingData((TR_CommEndPoint)event->subject)) { // handle pending data... close is issued from disableWrite TR_eventHandlerIssueEvent( (TR_EventHandler)_this, @@ -122,7 +124,7 @@ TR_commManagerShutdownRead(void * _this, TR_Event event) TR_CEP_EVENT_CLOSE, NULL); } else { - TR_cepSetClose(endpoint); + TR_cepSetClose((TR_CommEndPoint)event->subject); } return 0;