Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / TP_Reactor_Test.h
blob92fe33b074748f2265babf7437c8cf9a87a5e460
2 //=============================================================================
3 /**
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
35 class Acceptor;
37 class Receiver : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH>
39 friend class Acceptor;
40 public:
42 Receiver (Acceptor * acceptor=0, size_t index=MAX_RECEIVERS+1);
44 ~Receiver (void);
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);
59 private:
60 int terminate_io (ACE_Reactor_Mask mask);
61 int initiate_io (ACE_Reactor_Mask mask);
62 int check_destroy (void);
64 Acceptor * acceptor_;
65 size_t index_;
66 int flg_mask_;
68 ACE_Recursive_Thread_Mutex mutex_;
69 long total_snd_;
70 long total_rcv_;
71 long total_w_;
72 long total_r_;
75 // *************************************************************
77 class Acceptor : public ACE_Acceptor<Receiver,ACE_SOCK_ACCEPTOR>
79 friend class Receiver;
80 public:
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_; }
87 Acceptor (void);
88 virtual ~Acceptor (void);
90 void stop (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);
96 private:
98 ACE_Recursive_Thread_Mutex mutex_;
99 size_t sessions_;
100 Receiver *list_receivers_[MAX_RECEIVERS];
101 long total_snd_;
102 long total_rcv_;
103 long total_w_;
104 long total_r_;
106 void on_new_receiver (Receiver & rcvr);
107 void on_delete_receiver (Receiver & rcvr);
111 // *******************************************
112 // Sender
113 // *******************************************
115 class Connector;
117 class Sender : public ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_MT_SYNCH>
119 friend class Connector;
121 public:
122 Sender (Connector * connector=0, size_t index=MAX_SENDERS+1);
124 ~Sender (void);
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);
139 private:
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_;
146 size_t index_;
147 int flg_mask_;
149 ACE_Recursive_Thread_Mutex mutex_;
151 char send_buf_ [1024];
152 long total_snd_;
153 long total_rcv_;
154 long total_w_;
155 long total_r_;
158 // *************************************************************
160 class Connector: public ACE_Connector<Sender,ACE_SOCK_CONNECTOR>
162 friend class Sender;
163 public:
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_; }
171 Connector ();
172 virtual ~Connector ();
174 void stop ();
175 int start (const ACE_INET_Addr & addr , int num);
177 // virtual from ACE_Connector<>
178 virtual int make_svc_handler (Sender * & sh);
180 private:
182 ACE_Recursive_Thread_Mutex mutex_;
183 size_t sessions_;
184 Sender * list_senders_ [MAX_SENDERS];
185 long total_snd_;
186 long total_rcv_;
187 long total_w_;
188 long total_r_;
190 void on_new_sender (Sender & sndr);
191 void on_delete_sender (Sender & sndr);
195 #endif /* ACE_TESTS_TP_REACTOR_TEST_H */