2 //=============================================================================
4 * @file TP_Reactor_Test.h
6 * Define class needed for generating templates.
8 * @author Alexander Libman <alibman@ihug.com.au>
9 * @author <alexl@rumblgroup.com>
11 //=============================================================================
14 #ifndef ACE_TESTS_TP_REACTOR_TEST_H
15 #define ACE_TESTS_TP_REACTOR_TEST_H
17 #include "ace/INET_Addr.h"
18 #include "ace/SOCK_Acceptor.h"
19 #include "ace/SOCK_Connector.h"
20 #include "ace/SOCK_Stream.h"
21 #include "ace/Acceptor.h"
22 #include "ace/Connector.h"
23 #include "ace/Svc_Handler.h"
24 #include "ace/Recursive_Thread_Mutex.h"
26 const size_t MAX_SENDERS
= 1000;
27 const size_t MAX_RECEIVERS
= 1000;
30 // *************************************************************
31 // Receiver and Acceptor
32 // *************************************************************
33 // forward declaration
36 class Receiver
: public ACE_Svc_Handler
<ACE_SOCK_STREAM
, ACE_MT_SYNCH
>
38 friend class Acceptor
;
40 Receiver (Acceptor
* acceptor
=0, size_t index
=MAX_RECEIVERS
+1);
44 long get_total_snd () { return this->total_snd_
; }
45 long get_total_rcv () { return this->total_rcv_
; }
46 long get_total_w () { return this->total_w_
; }
47 long get_total_r () { return this->total_r_
; }
49 // virtual from ACE_Svc_Handler<>
50 virtual int open (void * pVoid
);
52 // virtual from ACE_Event_Handler
53 virtual int handle_input (ACE_HANDLE h
);
54 virtual int handle_output (ACE_HANDLE h
);
55 virtual int handle_close (ACE_HANDLE h
, ACE_Reactor_Mask mask
);
58 int terminate_io (ACE_Reactor_Mask mask
);
59 int initiate_io (ACE_Reactor_Mask mask
);
66 ACE_Recursive_Thread_Mutex mutex_
;
73 // *************************************************************
75 class Acceptor
: public ACE_Acceptor
<Receiver
,ACE_SOCK_ACCEPTOR
>
77 friend class Receiver
;
79 size_t get_number_sessions () { return sessions_
; }
80 long get_total_snd () { return this->total_snd_
; }
81 long get_total_rcv () { return this->total_rcv_
; }
82 long get_total_w () { return this->total_w_
; }
83 long get_total_r () { return this->total_r_
; }
89 int start (const ACE_INET_Addr
& addr
);
91 // virtual from ACE_Acceptor<Receiver,ACE_SOCK_ACCEPTOR>
92 virtual int make_svc_handler (Receiver
* & sh
);
95 ACE_Recursive_Thread_Mutex mutex_
;
97 Receiver
*list_receivers_
[MAX_RECEIVERS
];
103 void on_new_receiver (Receiver
& rcvr
);
104 void on_delete_receiver (Receiver
& rcvr
);
108 // *******************************************
110 // *******************************************
114 class Sender
: public ACE_Svc_Handler
<ACE_SOCK_STREAM
,ACE_MT_SYNCH
>
116 friend class Connector
;
119 Sender (Connector
* connector
=0, size_t index
=MAX_SENDERS
+1);
123 long get_total_snd () { return this->total_snd_
; }
124 long get_total_rcv () { return this->total_rcv_
; }
125 long get_total_w () { return this->total_w_
; }
126 long get_total_r () { return this->total_r_
; }
128 // virtual from ACE_Svc_Handler<>
129 virtual int open (void * pVoid
);
131 // virtual from ACE_Event_Handler
132 virtual int handle_input (ACE_HANDLE h
);
133 virtual int handle_output (ACE_HANDLE h
);
134 virtual int handle_close (ACE_HANDLE h
, ACE_Reactor_Mask mask
);
137 int terminate_io (ACE_Reactor_Mask mask
);
138 int initiate_io (ACE_Reactor_Mask mask
);
139 int initiate_write ();
140 int check_destroy ();
142 Connector
* connector_
;
146 ACE_Recursive_Thread_Mutex mutex_
;
148 char send_buf_
[1024];
155 // *************************************************************
157 class Connector
: public ACE_Connector
<Sender
,ACE_SOCK_CONNECTOR
>
161 size_t get_number_sessions () { return sessions_
; }
162 long get_total_snd () { return this->total_snd_
; }
163 long get_total_rcv () { return this->total_rcv_
; }
164 long get_total_w () { return this->total_w_
; }
165 long get_total_r () { return this->total_r_
; }
169 virtual ~Connector ();
172 int start (const ACE_INET_Addr
& addr
, int num
);
174 // virtual from ACE_Connector<>
175 virtual int make_svc_handler (Sender
* & sh
);
178 ACE_Recursive_Thread_Mutex mutex_
;
180 Sender
* list_senders_
[MAX_SENDERS
];
186 void on_new_sender (Sender
& sndr
);
187 void on_delete_sender (Sender
& sndr
);
191 #endif /* ACE_TESTS_TP_REACTOR_TEST_H */