2 #ifndef JAWS_REACTIVE_IO_HELPERS_H
3 #define JAWS_REACTIVE_IO_HELPERS_H
5 #include "ace/Event_Handler.h"
6 #include "ace/Message_Block.h"
7 #include "ace/Singleton.h"
8 #include "ace/Time_Value.h"
10 #include "jaws3/Export.h"
11 #include "jaws3/Jaws_IO.h"
12 #include "jaws3/Event_Result.h"
13 #include "jaws3/Event_Completer.h"
15 class JAWS_Reactive_IO
;
17 class JAWS_IO_Reactive_Handler
: public ACE_Event_Handler
19 friend class JAWS_IO_Reactive_Send
;
20 friend class JAWS_IO_Reactive_Recv
;
21 friend class JAWS_IO_Reactive_Transmit
;
26 int handle_timeout (const ACE_Time_Value
&, const void *);
28 int handle_close (ACE_HANDLE
, ACE_Reactor_Mask
);
30 int handle_exception (ACE_HANDLE
);
32 ACE_HANDLE
get_handle () const { return this->handle_
; }
34 void set_handle (ACE_HANDLE handle
) { this->handle_
= handle
; }
37 virtual void close (int result
);
40 JAWS_IO_Reactive_Handler ( ACE_HANDLE handle
41 , JAWS_Event_Completer
*completer
42 , const ACE_Time_Value
&tv
44 , ACE_Reactor_Mask mask
48 , completer_ (completer
)
55 if (ACE_Time_Value::zero
< this->tv_
)
57 ACE_Reactor::instance ()->schedule_timer (this, 0, this->tv_
);
60 public: // needed for destructor due to "aCC: HP ANSI C++ B3910B A.03.39" compiler bug
62 ~JAWS_IO_Reactive_Handler ()
64 if (this->timer_id_
!= -1)
65 ACE_Reactor::instance ()->cancel_timer (this->timer_id_
);
69 JAWS_Event_Result io_result_
;
73 JAWS_Event_Completer
*completer_
;
77 ACE_Reactor_Mask mask_
;
84 class JAWS_IO_Reactive_Send
: public JAWS_IO_Reactive_Handler
86 friend class JAWS_Reactive_IO
;
89 int handle_output (ACE_HANDLE handle
);
91 static JAWS_IO_Reactive_Send
* make ( ACE_HANDLE handle
92 , ACE_Message_Block
*mb
93 , JAWS_Event_Completer
*completer
97 return new JAWS_IO_Reactive_Send ( handle
100 , ACE_Time_Value::zero
102 , ACE_Event_Handler::WRITE_MASK
106 static JAWS_IO_Reactive_Send
* make ( ACE_HANDLE handle
107 , ACE_Message_Block
*mb
108 , JAWS_Event_Completer
*completer
109 , const ACE_Time_Value
&tv
113 return new JAWS_IO_Reactive_Send ( handle
118 , ACE_Event_Handler::WRITE_MASK
123 JAWS_IO_Reactive_Send ( ACE_HANDLE handle
124 , ACE_Message_Block
*mb
125 , JAWS_Event_Completer
*completer
126 , const ACE_Time_Value
&tv
128 , ACE_Reactor_Mask mask
130 : JAWS_IO_Reactive_Handler (handle
, completer
, tv
, act
, mask
)
136 ACE_Message_Block
*mb_
;
140 class JAWS_IO_Reactive_Recv
: public JAWS_IO_Reactive_Handler
142 friend class JAWS_Reactive_IO
;
145 int handle_input (ACE_HANDLE handle
);
147 static JAWS_IO_Reactive_Recv
* make ( ACE_HANDLE handle
148 , ACE_Message_Block
*mb
149 , JAWS_Event_Completer
*completer
153 return new JAWS_IO_Reactive_Recv ( handle
156 , ACE_Time_Value::zero
158 , ACE_Event_Handler::READ_MASK
162 static JAWS_IO_Reactive_Recv
* make ( ACE_HANDLE handle
163 , ACE_Message_Block
*mb
164 , JAWS_Event_Completer
*completer
165 , const ACE_Time_Value
&tv
169 return new JAWS_IO_Reactive_Recv ( handle
174 , ACE_Event_Handler::READ_MASK
179 JAWS_IO_Reactive_Recv ( ACE_HANDLE handle
180 , ACE_Message_Block
*mb
181 , JAWS_Event_Completer
*completer
182 , const ACE_Time_Value
&tv
184 , ACE_Reactor_Mask mask
186 : JAWS_IO_Reactive_Handler (handle
, completer
, tv
, act
, mask
)
192 ACE_Message_Block
*mb_
;
196 class JAWS_IO_Reactive_Transmit
: public JAWS_IO_Reactive_Handler
198 friend class JAWS_Reactive_IO
;
201 int handle_timeout (const ACE_Time_Value
&, const void *);
203 int handle_output (ACE_HANDLE handle
);
205 int handle_exception (ACE_HANDLE handle
);
207 static JAWS_IO_Reactive_Transmit
* make ( ACE_HANDLE handle
209 , JAWS_Event_Completer
*completer
210 , ACE_Message_Block
*header
211 , ACE_Message_Block
*trailer
215 return new JAWS_IO_Reactive_Transmit ( handle
218 , ACE_Time_Value::zero
222 , ACE_Event_Handler::WRITE_MASK
226 static JAWS_IO_Reactive_Transmit
* make ( ACE_HANDLE handle
228 , JAWS_Event_Completer
*completer
229 , const ACE_Time_Value
&tv
230 , ACE_Message_Block
*header
231 , ACE_Message_Block
*trailer
235 return new JAWS_IO_Reactive_Transmit ( handle
242 , ACE_Event_Handler::WRITE_MASK
247 void close (int result
);
249 int handle_output_header (ACE_HANDLE handle
);
251 int handle_output_source (ACE_HANDLE handle
);
253 int handle_output_trailer (ACE_HANDLE handle
);
255 int handle_output_mb (ACE_HANDLE handle
, ACE_Message_Block
*&mb
);
258 JAWS_IO_Reactive_Transmit ( ACE_HANDLE handle
260 , JAWS_Event_Completer
*completer
261 , const ACE_Time_Value
&tv
262 , ACE_Message_Block
*header
263 , ACE_Message_Block
*trailer
265 , ACE_Reactor_Mask mask
267 : JAWS_IO_Reactive_Handler (handle
, completer
, tv
, act
, mask
)
269 , source_mb_ (8 * 1024)
270 , source_buf_ (& this->source_mb_
)
278 ACE_Message_Block source_mb_
;
279 ACE_Message_Block
*source_buf_
;
280 ACE_Message_Block
*header_
;
281 ACE_Message_Block
*trailer_
;
284 #endif /* JAWS_REACTIVE_IO_HELPERS_H */