2 //=============================================================================
4 * @file TP_Reactor_Test.h
6 * Define class needed for generating templates. IBM C++ requires this to
7 * be in its own file for auto template instantiation.
9 * @author Alexander Libman <alibman@ihug.com.au>
10 * @author <alexl@rumblgroup.com>
12 //=============================================================================
15 #ifndef ACE_TESTS_TP_REACTOR_TEST_H
16 #define ACE_TESTS_TP_REACTOR_TEST_H
18 #include "ace/INET_Addr.h"
19 #include "ace/SOCK_Acceptor.h"
20 #include "ace/SOCK_Connector.h"
21 #include "ace/SOCK_Stream.h"
22 #include "ace/Acceptor.h"
23 #include "ace/Connector.h"
24 #include "ace/Svc_Handler.h"
25 #include "ace/Recursive_Thread_Mutex.h"
27 const size_t MAX_SENDERS
= 1000;
28 const size_t MAX_RECEIVERS
= 1000;
31 // *************************************************************
32 // Receiver and Acceptor
33 // *************************************************************
34 // forward declaration
37 class Receiver
: public ACE_Svc_Handler
<ACE_SOCK_STREAM
, ACE_MT_SYNCH
>
39 friend class Acceptor
;
42 Receiver (Acceptor
* acceptor
=0, size_t index
=MAX_RECEIVERS
+1);
46 long get_total_snd (void) { return this->total_snd_
; }
47 long get_total_rcv (void) { return this->total_rcv_
; }
48 long get_total_w (void) { return this->total_w_
; }
49 long get_total_r (void) { return this->total_r_
; }
51 // virtual from ACE_Svc_Handler<>
52 virtual int open (void * pVoid
);
54 // virtual from ACE_Event_Handler
55 virtual int handle_input (ACE_HANDLE h
);
56 virtual int handle_output (ACE_HANDLE h
);
57 virtual int handle_close (ACE_HANDLE h
, ACE_Reactor_Mask mask
);
60 int terminate_io (ACE_Reactor_Mask mask
);
61 int initiate_io (ACE_Reactor_Mask mask
);
62 int check_destroy (void);
68 ACE_Recursive_Thread_Mutex mutex_
;
75 // *************************************************************
77 class Acceptor
: public ACE_Acceptor
<Receiver
,ACE_SOCK_ACCEPTOR
>
79 friend class Receiver
;
81 size_t get_number_sessions (void) { return sessions_
; }
82 long get_total_snd (void) { return this->total_snd_
; }
83 long get_total_rcv (void) { return this->total_rcv_
; }
84 long get_total_w (void) { return this->total_w_
; }
85 long get_total_r (void) { return this->total_r_
; }
88 virtual ~Acceptor (void);
91 int start (const ACE_INET_Addr
& addr
);
93 // virtual from ACE_Acceptor<Receiver,ACE_SOCK_ACCEPTOR>
94 virtual int make_svc_handler (Receiver
* & sh
);
98 ACE_Recursive_Thread_Mutex mutex_
;
100 Receiver
*list_receivers_
[MAX_RECEIVERS
];
106 void on_new_receiver (Receiver
& rcvr
);
107 void on_delete_receiver (Receiver
& rcvr
);
111 // *******************************************
113 // *******************************************
117 class Sender
: public ACE_Svc_Handler
<ACE_SOCK_STREAM
,ACE_MT_SYNCH
>
119 friend class Connector
;
122 Sender (Connector
* connector
=0, size_t index
=MAX_SENDERS
+1);
126 long get_total_snd (void) { return this->total_snd_
; }
127 long get_total_rcv (void) { return this->total_rcv_
; }
128 long get_total_w (void) { return this->total_w_
; }
129 long get_total_r (void) { return this->total_r_
; }
131 // virtual from ACE_Svc_Handler<>
132 virtual int open (void * pVoid
);
134 // virtual from ACE_Event_Handler
135 virtual int handle_input (ACE_HANDLE h
);
136 virtual int handle_output (ACE_HANDLE h
);
137 virtual int handle_close (ACE_HANDLE h
, ACE_Reactor_Mask mask
);
140 int terminate_io (ACE_Reactor_Mask mask
);
141 int initiate_io (ACE_Reactor_Mask mask
);
142 int initiate_write ();
143 int check_destroy (void);
145 Connector
* connector_
;
149 ACE_Recursive_Thread_Mutex mutex_
;
151 char send_buf_
[1024];
158 // *************************************************************
160 class Connector
: public ACE_Connector
<Sender
,ACE_SOCK_CONNECTOR
>
164 size_t get_number_sessions (void) { return sessions_
; }
165 long get_total_snd (void) { return this->total_snd_
; }
166 long get_total_rcv (void) { return this->total_rcv_
; }
167 long get_total_w (void) { return this->total_w_
; }
168 long get_total_r (void) { return this->total_r_
; }
172 virtual ~Connector ();
175 int start (const ACE_INET_Addr
& addr
, int num
);
177 // virtual from ACE_Connector<>
178 virtual int make_svc_handler (Sender
* & sh
);
182 ACE_Recursive_Thread_Mutex mutex_
;
184 Sender
* list_senders_
[MAX_SENDERS
];
190 void on_new_sender (Sender
& sndr
);
191 void on_delete_sender (Sender
& sndr
);
195 #endif /* ACE_TESTS_TP_REACTOR_TEST_H */