Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / tests / TP_Reactor_Test.h
blobb5f7e66cd3c97253fbc8ac9858aa3032359a37a9
2 //=============================================================================
3 /**
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
34 class Acceptor;
36 class Receiver : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>
38 friend class Acceptor;
39 public:
40 Receiver (Acceptor * acceptor=0, size_t index=MAX_RECEIVERS+1);
42 ~Receiver ();
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);
57 private:
58 int terminate_io (ACE_Reactor_Mask mask);
59 int initiate_io (ACE_Reactor_Mask mask);
60 int check_destroy ();
62 Acceptor * acceptor_;
63 size_t index_;
64 int flg_mask_;
66 ACE_Recursive_Thread_Mutex mutex_;
67 long total_snd_;
68 long total_rcv_;
69 long total_w_;
70 long total_r_;
73 // *************************************************************
75 class Acceptor : public ACE_Acceptor<Receiver,ACE_SOCK_ACCEPTOR>
77 friend class Receiver;
78 public:
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_; }
85 Acceptor ();
86 virtual ~Acceptor ();
88 void stop ();
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);
94 private:
95 ACE_Recursive_Thread_Mutex mutex_;
96 size_t sessions_;
97 Receiver *list_receivers_[MAX_RECEIVERS];
98 long total_snd_;
99 long total_rcv_;
100 long total_w_;
101 long total_r_;
103 void on_new_receiver (Receiver & rcvr);
104 void on_delete_receiver (Receiver & rcvr);
108 // *******************************************
109 // Sender
110 // *******************************************
112 class Connector;
114 class Sender : public ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_MT_SYNCH>
116 friend class Connector;
118 public:
119 Sender (Connector * connector=0, size_t index=MAX_SENDERS+1);
121 ~Sender ();
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);
136 private:
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_;
143 size_t index_;
144 int flg_mask_;
146 ACE_Recursive_Thread_Mutex mutex_;
148 char send_buf_ [1024];
149 long total_snd_;
150 long total_rcv_;
151 long total_w_;
152 long total_r_;
155 // *************************************************************
157 class Connector: public ACE_Connector<Sender,ACE_SOCK_CONNECTOR>
159 friend class Sender;
160 public:
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_; }
168 Connector ();
169 virtual ~Connector ();
171 void stop ();
172 int start (const ACE_INET_Addr & addr , int num);
174 // virtual from ACE_Connector<>
175 virtual int make_svc_handler (Sender * & sh);
177 private:
178 ACE_Recursive_Thread_Mutex mutex_;
179 size_t sessions_;
180 Sender * list_senders_ [MAX_SENDERS];
181 long total_snd_;
182 long total_rcv_;
183 long total_w_;
184 long total_r_;
186 void on_new_sender (Sender & sndr);
187 void on_delete_sender (Sender & sndr);
191 #endif /* ACE_TESTS_TP_REACTOR_TEST_H */