Browse Source

fixes to make the code compile

1.0.0
Georg Hopp 11 years ago
parent
commit
d738e59156
  1. 12
      include/Makefile.am
  2. 2
      include/tr/comm_manager.h
  3. 16
      include/tr/interface/comm_manager.h
  4. 8
      include/trcomm.h
  5. 10
      src/Makefile.am
  6. 13
      src/comm_manager.c
  7. 71
      src/comm_manager_poll.c
  8. 6
      src/comm_manager_shutdown.c
  9. 4
      src/connector.c
  10. 10
      src/i_comm_manager.c

12
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/connection.h \
tr/connector.h \ tr/connector.h \
tr/protocol.h \
tr/proto_message.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_end_point.h \
tr/interface/comm_manager.h \
tr/interface/protocol.h tr/interface/protocol.h

2
include/tr/comm_manager.h

@ -28,6 +28,8 @@
#include "trbase.h" #include "trbase.h"
#include "trevent.h" #include "trevent.h"
#include "tr/comm_end_point.h"
TR_CLASS(TR_CommManager) { TR_CLASS(TR_CommManager) {
TR_EXTENDS(TR_EventHandler); TR_EXTENDS(TR_EventHandler);

16
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_commManagerDisableWrite)(void *, TR_Event);
typedef void (* fptr_TR_commManagerClose)(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_commManagerShutdownRead)(void *, TR_Event);
typedef void (* fptr_TR_commManagerShutdownWrite)(void *, TR_Event);
TR_INTERFACE(TR_CommManager) { TR_INTERFACE(TR_CommManager) {
TR_IFID; 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); void TR_commManagerAddEndpoint(void *, TR_CommEndPoint);

8
include/trcomm.h

@ -2,13 +2,15 @@
#define __TR_COMM_H__ #define __TR_COMM_H__
#include "tr/comm_end_point.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/connection.h"
#include "tr/connector.h" #include "tr/connector.h"
#include "tr/protocol.h"
#include "tr/proto_message.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_end_point.h"
#include "tr/interface/comm_manager.h"
#include "tr/interface/protocol.h" #include "tr/interface/protocol.h"
#endif // __TR_COMM_H__ #endif // __TR_COMM_H__

10
src/Makefile.am

@ -7,16 +7,20 @@ TRCOMM = cep_append_read_data.c \
cep_append_write_data.c \ cep_append_write_data.c \
cet_accept.c \ cet_accept.c \
comm_end_point.c \ comm_end_point.c \
comm_manager.c \
comm_manager_poll.c \
comm_manager_shutdown.c \
con_compose.c \ con_compose.c \
con_next_message.c \
conn_entry_point.c \
connection.c \ connection.c \
connector.c \ connector.c \
conn_entry_point.c \
con_next_message.c \
proto_message.c \
protocol.c \ protocol.c \
protocol_message_raw.c \ protocol_message_raw.c \
protocol_raw.c \ protocol_raw.c \
proto_message.c \
i_comm_end_point.c \ i_comm_end_point.c \
i_comm_manager.c \
i_protocol.c i_protocol.c
lib_LTLIBRARIES = libtrcomm.la lib_LTLIBRARIES = libtrcomm.la

13
src/comm_manager.c

@ -21,6 +21,7 @@
*/ */
#include <unistd.h> #include <unistd.h>
#include <poll.h>
#include "trbase.h" #include "trbase.h"
#include "trevent.h" #include "trevent.h"
@ -58,7 +59,7 @@ commManagerDtor(void * _this)
static static
int int
TR__commManagerAddEndpoint(void * _this, Event event)
TR__commManagerAddEndpoint(void * _this, TR_Event event)
{ {
TR_commManagerAddEndpoint( TR_commManagerAddEndpoint(
(TR_CommManager)_this, (TR_CommManager)_this,
@ -71,7 +72,7 @@ void TR_commManagerEnableWrite(void *, TR_Event);
void TR_commManagerDisableWrite(void *, TR_Event); void TR_commManagerDisableWrite(void *, TR_Event);
void TR_commManagerClose(void *, TR_Event); void TR_commManagerClose(void *, TR_Event);
void TR_commManagerShutdownRead(void *, TR_Event); void TR_commManagerShutdownRead(void *, TR_Event);
void TR_commManagerShutdownRead(void *, TR_Event);
void TR_commManagerShutdownWrite(void *, TR_Event);
static static
void void
@ -98,13 +99,13 @@ commManagerCvInit(TR_class_ptr cls)
TR_EVENT_HANDLER_SET_METHOD( TR_EVENT_HANDLER_SET_METHOD(
cls, cls,
TR_Connection, TR_Connection,
TR_CON_EVENT_PENDING_DATA,
TR_CEP_EVENT_PENDING_DATA,
TR_commManagerEnableWrite); TR_commManagerEnableWrite);
TR_EVENT_HANDLER_SET_METHOD( TR_EVENT_HANDLER_SET_METHOD(
cls, cls,
TR_Connection, TR_Connection,
TR_CON_EVENT_END_DATA,
TR_CEP_EVENT_END_DATA,
TR_commManagerDisableWrite); TR_commManagerDisableWrite);
TR_EVENT_HANDLER_SET_METHOD( TR_EVENT_HANDLER_SET_METHOD(
@ -126,7 +127,7 @@ commManagerCvInit(TR_class_ptr cls)
TR_commManagerShutdownWrite); 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_Class, commManagerCtor, commManagerDtor, NULL);
TR_INIT_IFACE(TR_CommManager, NULL, NULL, NULL, NULL, NULL, NULL, NULL); TR_INIT_IFACE(TR_CommManager, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
TR_CREATE_CLASS( TR_CREATE_CLASS(
@ -135,7 +136,7 @@ TR_CREATE_CLASS(
commManagerCvInit, commManagerCvInit,
TR_IF(TR_Class), TR_IF(TR_Class),
TR_IF(TR_CommManager)) = { TR_IF(TR_CommManager)) = {
{ &(__event_methods.data) }
{ &(_commManagerEventMethods.data) }
}; };
// vim: set ts=4 sw=4: // vim: set ts=4 sw=4:

71
src/comm_manager_poll.c

@ -21,14 +21,17 @@
*/ */
#include <unistd.h> #include <unistd.h>
#include <poll.h>
#include "trbase.h" #include "trbase.h"
#include "trevent.h" #include "trevent.h"
#include "tr/comm_end_point.h"
#include "tr/connection.h"
#include "tr/comm_manager.h" #include "tr/comm_manager.h"
#include "tr/comm_manager_poll.h"
#include "tr/interface/comm_manager.h" #include "tr/interface/comm_manager.h"
#include "tr/comm_end_point.h"
#include "tr/connection.h"
#include "tr/connect_entry_point.h"
static static
int int
@ -41,7 +44,9 @@ commManagerPollCtor(void * _this, va_list * params)
TR_PARENTCALL(_this, TR_Class, ctor, params); TR_PARENTCALL(_this, TR_Class, ctor, params);
this->fds = TR_malloc(sizeof(struct pollfd) * cmgr->n_endpoints); this->fds = TR_malloc(sizeof(struct pollfd) * cmgr->n_endpoints);
for (i = 0; i < cmgr->n_endpoints; i++) { 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; return 0;
@ -59,7 +64,7 @@ commManagerPollDtor(void * _this)
static static
void void
TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint)
TR_commManagerPollAddEndpoint(void * _this, TR_CommEndPoint endpoint)
{ {
TR_CommManagerPoll this = _this; TR_CommManagerPoll this = _this;
this->fds[endpoint->transport->handle].fd = endpoint->transport->handle; this->fds[endpoint->transport->handle].fd = endpoint->transport->handle;
@ -68,7 +73,7 @@ TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint)
static static
void void
TR_commManagerSelect(void * _this, TR_Event event, int timeout)
TR_commManagerPollSelect(void * _this, TR_Event event, int timeout)
{ {
TR_CommManagerPoll this = _this; TR_CommManagerPoll this = _this;
TR_CommManager cmgr = _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); 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--; nevents--;
if (TR_INSTANCE_OF(TR_TcpSocket, endpoints->transport)
if (TR_INSTANCE_OF(TR_TcpSocket, endpoint->transport)
&& ((TR_TcpSocket)endpoint->transport)->listen) { && ((TR_TcpSocket)endpoint->transport)->listen) {
TR_eventHandlerIssueEvent( TR_eventHandlerIssueEvent(
(TR_EventHandler)this, (TR_EventHandler)this,
(TR_Connection)endpoint,
TR_CON_EVENT_ACC_READY,
(TR_EventSubject)endpoint,
TR_CET_EVENT_ACC_READY,
NULL); NULL);
} else { } else {
TR_eventHandlerIssueEvent( TR_eventHandlerIssueEvent(
(TR_EventHandler)this, (TR_EventHandler)this,
endpoint,
TR_CET_EVENT_READ_READY,
(TR_EventSubject)endpoint,
TR_CEP_EVENT_READ_READY,
NULL); NULL);
} }
} }
if (this->fds[i].revents & POLLOUT == POLLOUT) {
if ((this->fds[i].revents & POLLOUT) == POLLOUT) {
nevents--; nevents--;
TR_eventHandlerIssueEvent( TR_eventHandlerIssueEvent(
(TR_EventHandler)this, (TR_EventHandler)this,
endpoint,
TR_CET_EVENT_WRITE_READY,
(TR_EventSubject)endpoint,
TR_CEP_EVENT_WRITE_READY,
NULL); NULL);
} }
@ -113,56 +118,50 @@ TR_commManagerSelect(void * _this, TR_Event event, int timeout)
static static
void void
TR_commManagerEnableWrite(void * _this, TR_Event event)
TR_commManagerPollEnableWrite(void * _this, TR_Event event)
{ {
TR_CommManagerPoll this = _this; TR_CommManagerPoll this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
if (! TR_socketFinWr(endpoint->transport)) { if (! TR_socketFinWr(endpoint->transport)) {
this->fds[endpoint->transport->handle].event |= POLLOUT;
this->fds[endpoint->transport->handle].events |= POLLOUT;
} }
} }
static static
int
TR_commManagerDisableWrite(void * _this, TR_Event event)
void
TR_commManagerPollDisableWrite(void * _this, TR_Event event)
{ {
TR_CommManagerPoll this = _this; TR_CommManagerPoll this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
this->fds[endpoint->transport->handle].event &= ~POLLOUT;
this->fds[endpoint->transport->handle].events &= ~POLLOUT;
} }
static static
int
TR_commManagerClose(void * _this, TR_Event event)
void
TR_commManagerPollClose(void * _this, TR_Event event)
{ {
TR_CommManagerPoll this = _this; TR_CommManagerPoll this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; 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 static
int
TR_commManagerDisableRead(void * _this, TR_Event event)
void
TR_commManagerPollDisableRead(void * _this, TR_Event event)
{ {
TR_CommManagerPoll this = _this; TR_CommManagerPoll this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; 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 static
void void
commManagerPollCvInit(TR_class_ptr cls) {
TR_commManagerPollCvInit(TR_class_ptr cls) {
TR_INHERIT_CLASSVARS(TR_CommManagerPoll, TR_CommManager); TR_INHERIT_CLASSVARS(TR_CommManagerPoll, TR_CommManager);
} }
@ -179,7 +178,7 @@ TR_INIT_IFACE(
TR_CREATE_CLASS( TR_CREATE_CLASS(
TR_CommManagerPoll, TR_CommManagerPoll,
TR_CommManager, TR_CommManager,
TR_CommManagerPollCvInit,
TR_commManagerPollCvInit,
TR_IF(TR_Class)); TR_IF(TR_Class));
// vim: set ts=4 sw=4: // vim: set ts=4 sw=4:

6
src/comm_manager_shutdown.c

@ -20,6 +20,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <poll.h>
#include "trbase.h" #include "trbase.h"
#include "trio.h" #include "trio.h"
#include "trevent.h" #include "trevent.h"
@ -33,10 +35,10 @@ TR_commManagerShutdown(void * _this, TR_Event event)
nfds_t i; nfds_t i;
for (i=0; i<this->n_endpoints; i++) { for (i=0; i<this->n_endpoints; i++) {
if (this->endpoints[handle]) {
if (this->endpoints[i]) {
TR_eventHandlerIssueEvent( TR_eventHandlerIssueEvent(
(TR_EventHandler)_this, (TR_EventHandler)_this,
(TR_EventSubject)this->endpoints[handle],
(TR_EventSubject)this->endpoints[i],
TR_CEP_EVENT_CLOSE, TR_CEP_EVENT_CLOSE,
NULL); NULL);
} }

4
src/connector.c

@ -89,14 +89,14 @@ connectorCvInit(TR_class_ptr cls)
connectorAccept); connectorAccept);
} }
TR_INSTANCE(TR_Hash, _event_methods);
TR_INSTANCE(TR_Hash, connectorEventMethods);
TR_INIT_IFACE(TR_Class, connectorCtor, connectorDtor, NULL); TR_INIT_IFACE(TR_Class, connectorCtor, connectorDtor, NULL);
TR_CREATE_CLASS( TR_CREATE_CLASS(
TR_Connector, TR_Connector,
TR_EventHandler, TR_EventHandler,
connectorCvInit, connectorCvInit,
TR_IF(TR_Class)) = { TR_IF(TR_Class)) = {
{ &(__event_methods.data) }
{ &(_connectorEventMethods.data) }
}; };
// vim: set ts=4 sw=4: // vim: set ts=4 sw=4:

10
src/i_comm_manager.c

@ -21,19 +21,21 @@
*/ */
#include <errno.h> #include <errno.h>
#include <poll.h>
#include "trbase.h" #include "trbase.h"
#include "trevent.h" #include "trevent.h"
#include "tr/interface/comm_manager.h" #include "tr/interface/comm_manager.h"
#include "tr/comm_end_point.h" #include "tr/comm_end_point.h"
#include "tr/comm_manager.h"
TR_CREATE_INTERFACE(TR_CommManager, 7); TR_CREATE_INTERFACE(TR_CommManager, 7);
void void
TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint) TR_commManagerAddEndpoint(void * _this, TR_CommEndPoint endpoint)
{ {
TR_ConnManager this = _this;
TR_CommManager this = _this;
if (this->endpoints[endpoint->transport->handle]) { if (this->endpoints[endpoint->transport->handle]) {
// this should never happen, but if so we assume this is a leftover // 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 int
TR_commManagerClose(void * _this, TR_Event event) TR_commManagerClose(void * _this, TR_Event event)
{ {
TR_ConnManager this = _this;
TR_CommManager this = _this;
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
TR_socketShutdown(endpoint->transport); TR_socketShutdown(endpoint->transport);
@ -114,7 +116,7 @@ TR_commManagerShutdownRead(void * _this, TR_Event event)
event->subject, event->subject,
TR_CEP_EVENT_CLOSE, TR_CEP_EVENT_CLOSE,
NULL); NULL);
} else if (TR_cepHasPendingData(endpoint)) {
} else if (TR_cepHasPendingData((TR_CommEndPoint)event->subject)) {
// handle pending data... close is issued from disableWrite // handle pending data... close is issued from disableWrite
TR_eventHandlerIssueEvent( TR_eventHandlerIssueEvent(
(TR_EventHandler)_this, (TR_EventHandler)_this,
@ -122,7 +124,7 @@ TR_commManagerShutdownRead(void * _this, TR_Event event)
TR_CEP_EVENT_CLOSE, TR_CEP_EVENT_CLOSE,
NULL); NULL);
} else { } else {
TR_cepSetClose(endpoint);
TR_cepSetClose((TR_CommEndPoint)event->subject);
} }
return 0; return 0;

Loading…
Cancel
Save