1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
/* -*- c++ -*- */
// $Id$
#ifndef JAWS_REACTIVE_IO_HELPERS_H
#define JAWS_REACTIVE_IO_HELPERS_H
#include "ace/Event_Handler.h"
#include "ace/Message_Block.h"
#include "ace/Singleton.h"
#include "ace/Time_Value.h"
#include "jaws3/Export.h"
#include "jaws3/IO.h"
#include "jaws3/Event_Result.h"
#include "jaws3/Event_Completer.h"
class JAWS_Reactive_IO;
class JAWS_IO_Reactive_Handler : public ACE_Event_Handler
{
friend class JAWS_IO_Reactive_Send;
friend class JAWS_IO_Reactive_Recv;
friend class JAWS_IO_Reactive_Transmit;
public:
virtual void open (void);
int handle_timeout (const ACE_Time_Value &, const void *);
int handle_close (ACE_HANDLE, ACE_Reactor_Mask);
int handle_exception (ACE_HANDLE);
ACE_HANDLE get_handle (void) const { return this->handle_; }
void set_handle (ACE_HANDLE handle) { this->handle_ = handle; }
protected:
virtual void close (int result);
private:
JAWS_IO_Reactive_Handler ( ACE_HANDLE handle
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, void *act
, ACE_Reactor_Mask mask
)
: bytes_ (0)
, handle_ (handle)
, completer_ (completer)
, tv_ (tv)
, act_ (act)
, mask_ (mask)
, timer_id_ (-1)
, was_active_ (0)
{
if (ACE_Time_Value::zero < this->tv_)
this->timer_id_ =
ACE_Reactor::instance ()->schedule_timer (this, 0, this->tv_);
}
public: // needed for destructor due to "aCC: HP ANSI C++ B3910B A.03.39" compiler bug
~JAWS_IO_Reactive_Handler (void)
{
if (this->timer_id_ != -1)
ACE_Reactor::instance ()->cancel_timer (this->timer_id_);
}
private:
JAWS_Event_Result io_result_;
size_t bytes_;
ACE_HANDLE handle_;
JAWS_Event_Completer *completer_;
ACE_Time_Value tv_;
void *act_;
ACE_Reactor_Mask mask_;
long timer_id_;
int was_active_;
};
class JAWS_IO_Reactive_Send : public JAWS_IO_Reactive_Handler
{
friend class JAWS_Reactive_IO;
public:
int handle_output (ACE_HANDLE handle);
static JAWS_IO_Reactive_Send * make ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, void *act
)
{
return new JAWS_IO_Reactive_Send ( handle
, mb
, completer
, ACE_Time_Value::zero
, act
, ACE_Event_Handler::WRITE_MASK
);
}
static JAWS_IO_Reactive_Send * make ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, void *act
)
{
return new JAWS_IO_Reactive_Send ( handle
, mb
, completer
, tv
, act
, ACE_Event_Handler::WRITE_MASK
);
}
private:
JAWS_IO_Reactive_Send ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, void *act
, ACE_Reactor_Mask mask
)
: JAWS_IO_Reactive_Handler (handle, completer, tv, act, mask)
, mb_ (mb)
{
}
private:
ACE_Message_Block *mb_;
};
class JAWS_IO_Reactive_Recv : public JAWS_IO_Reactive_Handler
{
friend class JAWS_Reactive_IO;
public:
int handle_input (ACE_HANDLE handle);
static JAWS_IO_Reactive_Recv * make ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, void *act
)
{
return new JAWS_IO_Reactive_Recv ( handle
, mb
, completer
, ACE_Time_Value::zero
, act
, ACE_Event_Handler::READ_MASK
);
}
static JAWS_IO_Reactive_Recv * make ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, void *act
)
{
return new JAWS_IO_Reactive_Recv ( handle
, mb
, completer
, tv
, act
, ACE_Event_Handler::READ_MASK
);
}
private:
JAWS_IO_Reactive_Recv ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, void *act
, ACE_Reactor_Mask mask
)
: JAWS_IO_Reactive_Handler (handle, completer, tv, act, mask)
, mb_ (mb)
{
}
private:
ACE_Message_Block *mb_;
};
class JAWS_IO_Reactive_Transmit : public JAWS_IO_Reactive_Handler
{
friend class JAWS_Reactive_IO;
public:
int handle_timeout (const ACE_Time_Value &, const void *);
int handle_output (ACE_HANDLE handle);
int handle_exception (ACE_HANDLE handle);
static JAWS_IO_Reactive_Transmit * make ( ACE_HANDLE handle
, ACE_HANDLE source
, JAWS_Event_Completer *completer
, ACE_Message_Block *header
, ACE_Message_Block *trailer
, void *act
)
{
return new JAWS_IO_Reactive_Transmit ( handle
, source
, completer
, ACE_Time_Value::zero
, header
, trailer
, act
, ACE_Event_Handler::WRITE_MASK
);
}
static JAWS_IO_Reactive_Transmit * make ( ACE_HANDLE handle
, ACE_HANDLE source
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, ACE_Message_Block *header
, ACE_Message_Block *trailer
, void *act
)
{
return new JAWS_IO_Reactive_Transmit ( handle
, source
, completer
, tv
, header
, trailer
, act
, ACE_Event_Handler::WRITE_MASK
);
}
protected:
void close (int result);
int handle_output_header (ACE_HANDLE handle);
int handle_output_source (ACE_HANDLE handle);
int handle_output_trailer (ACE_HANDLE handle);
int handle_output_mb (ACE_HANDLE handle, ACE_Message_Block *&mb);
private:
JAWS_IO_Reactive_Transmit ( ACE_HANDLE handle
, ACE_HANDLE source
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, ACE_Message_Block *header
, ACE_Message_Block *trailer
, void *act
, ACE_Reactor_Mask mask
)
: JAWS_IO_Reactive_Handler (handle, completer, tv, act, mask)
, source_ (source)
, source_mb_ (8 * 1024)
, source_buf_ (& this->source_mb_)
, header_ (header)
, trailer_ (trailer)
{
}
private:
ACE_HANDLE source_;
ACE_Message_Block source_mb_;
ACE_Message_Block *source_buf_;
ACE_Message_Block *header_;
ACE_Message_Block *trailer_;
};
#endif /* JAWS_REACTIVE_IO_HELPERS_H */
|