Browse Source

add io handler

1.0.0
Georg Hopp 11 years ago
parent
commit
449041ae1f
  1. 1
      include/Makefile.am
  2. 1
      include/trcomm.h
  3. 1
      src/Makefile.am
  4. 44
      src/io_handler.c
  5. 6
      src/protocol_handler.c

1
include/Makefile.am

@ -4,6 +4,7 @@ nobase_include_HEADERS = tr/comm_end_point.h \
tr/connect_entry_point.h \
tr/connection.h \
tr/connector.h \
tr/io_handler.h \
tr/proto_message.h \
tr/protocol.h \
tr/protocol_handler.h \

1
include/trcomm.h

@ -7,6 +7,7 @@
#include "tr/connect_entry_point.h"
#include "tr/connection.h"
#include "tr/connector.h"
#include "tr/io_handler.h"
#include "tr/proto_message.h"
#include "tr/protocol.h"
#include "tr/protocol_handler.h"

1
src/Makefile.am

@ -17,6 +17,7 @@ TRCOMM = cep_append_read_data.c \
conn_entry_point.c \
connection.c \
connector.c \
io_handler.c \
proto_message.c \
protocol.c \
protocol_handler.c \

44
src/io_handler.c

@ -25,10 +25,7 @@
#include "trbase.h"
#include "trevent.h"
#include "tr/protocol.h"
#include "tr/connection.h"
#include "tr/protocol_handler.h"
#include "tr/proto_message.h"
#include "tr/io_handler.h"
#include "tr/comm_end_point.h"
#include "tr/interface/comm_end_point.h"
@ -47,11 +44,15 @@ static
int
ioHandlerRead(void * _this, TR_Event event)
{
/**
* TODO No upgrade for now. Add it later on.
*/
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
TR_ProtoMessage message = TR_cepNextMessage(endpoint);
if (TR_cepBufferRead(endpoint)) {
TR_eventHandlerIssueEvent(
(TR_EventHandler)_this,
event->subject,
TR_CEP_EVENT_NEW_DATA,
NULL);
}
return TRUE;
}
@ -61,12 +62,21 @@ int
ioHandlerWrite(void * _this, TR_Event event)
{
TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject;
TR_ProtoMessage message = (TR_ProtoMessage)event->data;
if (message->close) {
// also check that we are a response. Well this is how it is done
// in the python code...
TR_cepSetClose(endpoint);
if (TR_cepWriteBuffered(endpoint)) {
if (TR_cepHasPendingData(endpoint)) {
TR_eventHandlerIssueEvent(
(TR_EventHandler)_this,
event->subject,
TR_CEP_EVENT_PENDING_DATA,
NULL);
} else {
TR_eventHandlerIssueEvent(
(TR_EventHandler)_this,
event->subject,
TR_CEP_EVENT_END_DATA,
NULL);
}
}
return TRUE;
@ -74,17 +84,17 @@ ioHandlerWrite(void * _this, TR_Event event)
static
void
protocolHandlerCvInit(TR_class_ptr cls)
ioHandlerCvInit(TR_class_ptr cls)
{
TR_EVENT_HANDLER_SET_METHOD(
cls,
TR_Connection,
TR_CommEndPoint,
TR_CEP_EVENT_READ_READY,
ioHandlerRead);
TR_EVENT_HANDLER_SET_METHOD(
cls,
TR_Connection,
TR_CommEndPoint,
TR_CEP_EVENT_WRITE_READY,
ioHandlerWrite);
}
@ -92,7 +102,7 @@ protocolHandlerCvInit(TR_class_ptr cls)
TR_INSTANCE(TR_Hash, ioHandlerEventMethods);
TR_INIT_IFACE(TR_Class, ioHandlerCtor, ioHandlerDtor, NULL);
TR_CREATE_CLASS(
TR_ProtocolHandler,
TR_IoHandler,
TR_EventHandler,
ioHandlerCvInit,
TR_IF(TR_Class)) = {

6
src/protocol_handler.c

@ -108,19 +108,19 @@ protocolHandlerCvInit(TR_class_ptr cls)
{
TR_EVENT_HANDLER_SET_METHOD(
cls,
TR_Connection,
TR_CommEndPoint,
TR_CEP_EVENT_NEW_DATA,
protocolHandlerParse);
TR_EVENT_HANDLER_SET_METHOD(
cls,
TR_Connection,
TR_CommEndPoint,
TR_CEP_EVENT_SEND_MSG,
protocolHandlerCompose);
TR_EVENT_HANDLER_SET_METHOD(
cls,
TR_Connection,
TR_CommEndPoint,
TR_CEP_EVENT_UPGRADE,
protocolHandlerUpgrade);
}

Loading…
Cancel
Save