ACE+TAO-7_0_8
[ACE_TAO.git] / ACE / tests / Proactor_Test.h
blob02bd4a407967cfad598cc389870cd2d22218ef9f
2 //=============================================================================
3 /**
4 * @file Proactor_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 @author Alexander Libman <alibman@baltimore.com>
11 //=============================================================================
14 #ifndef ACE_TESTS_PROACTOR_TEST_H
15 #define ACE_TESTS_PROACTOR_TEST_H
17 #include "ace/Synch_Traits.h"
18 #include "ace/Thread_Mutex.h"
20 // forward declaration
21 class TestData;
23 class Server : public ACE_Service_Handler
25 public:
26 Server ();
27 Server (TestData *tester, int id);
28 ~Server (void);
30 int id (void) { return this->id_; }
31 size_t get_total_snd (void) { return this->total_snd_; }
32 size_t get_total_rcv (void) { return this->total_rcv_; }
33 long get_total_w (void) { return this->total_w_; }
34 long get_total_r (void) { return this->total_r_; }
36 // This is called to pass the new connection's addresses.
37 virtual void addresses (const ACE_INET_Addr& peer,
38 const ACE_INET_Addr& local);
40 /// This is called after the new connection has been accepted.
41 virtual void open (ACE_HANDLE handle,
42 ACE_Message_Block &message_block);
43 void cancel ();
45 protected:
46 //// This is called when asynchronous <read> operation from the
47 //// socket completes.
48 /**
49 * @name AIO callback handling
51 * These methods are called by the framework
53 virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result);
55 /// This is called when an asynchronous <write> to the socket
56 /// completes.
57 virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result);
59 private:
60 int initiate_read_stream (void);
61 int initiate_write_stream (ACE_Message_Block &mb, size_t nbytes);
63 TestData *tester_;
64 int id_;
66 ACE_Asynch_Read_Stream rs_;
67 ACE_Asynch_Write_Stream ws_;
68 ACE_HANDLE handle_;
69 ACE_SYNCH_MUTEX lock_;
71 int io_count_; // Number of currently outstanding I/O requests
72 int flg_cancel_;
73 size_t total_snd_; // Number of bytes successfully sent
74 size_t total_rcv_; // Number of bytes successfully received
75 int total_w_; // Number of write operations
76 int total_r_; // Number of read operations
79 // *******************************************
80 // Client
81 // *******************************************
83 class Client : public ACE_Service_Handler
85 public:
87 /// This is called after the new connection has been established.
88 virtual void open (ACE_HANDLE handle,
89 ACE_Message_Block &message_block);
91 Client ();
92 Client (TestData *tester, int id);
93 ~Client (void);
95 int id (void) { return this->id_; }
96 size_t get_total_snd (void) { return this->total_snd_; }
97 size_t get_total_rcv (void) { return this->total_rcv_; }
98 int get_total_w (void) { return this->total_w_; }
99 int get_total_r (void) { return this->total_r_; }
101 // This is called to pass the new connection's addresses.
102 virtual void addresses (const ACE_INET_Addr& peer,
103 const ACE_INET_Addr& local);
105 /// This is called when asynchronous reads from the socket complete
106 virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result);
108 /// This is called when asynchronous writes from the socket complete
109 virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result);
111 void cancel (void);
113 private:
114 int initiate_read_stream (void);
115 int initiate_write_stream (void);
116 void close (void);
118 TestData *tester_;
119 int id_;
121 ACE_Asynch_Read_Stream rs_;
122 ACE_Asynch_Write_Stream ws_;
123 ACE_HANDLE handle_;
125 ACE_SYNCH_MUTEX lock_;
127 int io_count_;
128 int stop_writing_; // Writes are shut down; just read.
129 int flg_cancel_;
130 size_t total_snd_;
131 size_t total_rcv_;
132 int total_w_;
133 int total_r_;
136 #endif /* ACE_TESTS_PROACTOR_TEST_H */