Showing
5 changed files
with
33 additions
and
20 deletions
... | ... | @@ -25,10 +25,7 @@ |
25 | 25 | #include "trbase.h" |
26 | 26 | #include "trevent.h" |
27 | 27 | |
28 | -#include "tr/protocol.h" | |
29 | -#include "tr/connection.h" | |
30 | -#include "tr/protocol_handler.h" | |
31 | -#include "tr/proto_message.h" | |
28 | +#include "tr/io_handler.h" | |
32 | 29 | #include "tr/comm_end_point.h" |
33 | 30 | #include "tr/interface/comm_end_point.h" |
34 | 31 | |
... | ... | @@ -47,11 +44,15 @@ static |
47 | 44 | int |
48 | 45 | ioHandlerRead(void * _this, TR_Event event) |
49 | 46 | { |
50 | - /** | |
51 | - * TODO No upgrade for now. Add it later on. | |
52 | - */ | |
53 | 47 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
54 | - TR_ProtoMessage message = TR_cepNextMessage(endpoint); | |
48 | + | |
49 | + if (TR_cepBufferRead(endpoint)) { | |
50 | + TR_eventHandlerIssueEvent( | |
51 | + (TR_EventHandler)_this, | |
52 | + event->subject, | |
53 | + TR_CEP_EVENT_NEW_DATA, | |
54 | + NULL); | |
55 | + } | |
55 | 56 | |
56 | 57 | return TRUE; |
57 | 58 | } |
... | ... | @@ -61,12 +62,21 @@ int |
61 | 62 | ioHandlerWrite(void * _this, TR_Event event) |
62 | 63 | { |
63 | 64 | TR_CommEndPoint endpoint = (TR_CommEndPoint)event->subject; |
64 | - TR_ProtoMessage message = (TR_ProtoMessage)event->data; | |
65 | 65 | |
66 | - if (message->close) { | |
67 | - // also check that we are a response. Well this is how it is done | |
68 | - // in the python code... | |
69 | - TR_cepSetClose(endpoint); | |
66 | + if (TR_cepWriteBuffered(endpoint)) { | |
67 | + if (TR_cepHasPendingData(endpoint)) { | |
68 | + TR_eventHandlerIssueEvent( | |
69 | + (TR_EventHandler)_this, | |
70 | + event->subject, | |
71 | + TR_CEP_EVENT_PENDING_DATA, | |
72 | + NULL); | |
73 | + } else { | |
74 | + TR_eventHandlerIssueEvent( | |
75 | + (TR_EventHandler)_this, | |
76 | + event->subject, | |
77 | + TR_CEP_EVENT_END_DATA, | |
78 | + NULL); | |
79 | + } | |
70 | 80 | } |
71 | 81 | |
72 | 82 | return TRUE; |
... | ... | @@ -74,17 +84,17 @@ ioHandlerWrite(void * _this, TR_Event event) |
74 | 84 | |
75 | 85 | static |
76 | 86 | void |
77 | -protocolHandlerCvInit(TR_class_ptr cls) | |
87 | +ioHandlerCvInit(TR_class_ptr cls) | |
78 | 88 | { |
79 | 89 | TR_EVENT_HANDLER_SET_METHOD( |
80 | 90 | cls, |
81 | - TR_Connection, | |
91 | + TR_CommEndPoint, | |
82 | 92 | TR_CEP_EVENT_READ_READY, |
83 | 93 | ioHandlerRead); |
84 | 94 | |
85 | 95 | TR_EVENT_HANDLER_SET_METHOD( |
86 | 96 | cls, |
87 | - TR_Connection, | |
97 | + TR_CommEndPoint, | |
88 | 98 | TR_CEP_EVENT_WRITE_READY, |
89 | 99 | ioHandlerWrite); |
90 | 100 | } |
... | ... | @@ -92,7 +102,7 @@ protocolHandlerCvInit(TR_class_ptr cls) |
92 | 102 | TR_INSTANCE(TR_Hash, ioHandlerEventMethods); |
93 | 103 | TR_INIT_IFACE(TR_Class, ioHandlerCtor, ioHandlerDtor, NULL); |
94 | 104 | TR_CREATE_CLASS( |
95 | - TR_ProtocolHandler, | |
105 | + TR_IoHandler, | |
96 | 106 | TR_EventHandler, |
97 | 107 | ioHandlerCvInit, |
98 | 108 | TR_IF(TR_Class)) = { | ... | ... |
... | ... | @@ -108,19 +108,19 @@ protocolHandlerCvInit(TR_class_ptr cls) |
108 | 108 | { |
109 | 109 | TR_EVENT_HANDLER_SET_METHOD( |
110 | 110 | cls, |
111 | - TR_Connection, | |
111 | + TR_CommEndPoint, | |
112 | 112 | TR_CEP_EVENT_NEW_DATA, |
113 | 113 | protocolHandlerParse); |
114 | 114 | |
115 | 115 | TR_EVENT_HANDLER_SET_METHOD( |
116 | 116 | cls, |
117 | - TR_Connection, | |
117 | + TR_CommEndPoint, | |
118 | 118 | TR_CEP_EVENT_SEND_MSG, |
119 | 119 | protocolHandlerCompose); |
120 | 120 | |
121 | 121 | TR_EVENT_HANDLER_SET_METHOD( |
122 | 122 | cls, |
123 | - TR_Connection, | |
123 | + TR_CommEndPoint, | |
124 | 124 | TR_CEP_EVENT_UPGRADE, |
125 | 125 | protocolHandlerUpgrade); |
126 | 126 | } | ... | ... |
Please
register
or
login
to post a comment