|
|
|
@ -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)) = { |
|
|
|
|