2 //=============================================================================
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
23 class Server
: public ACE_Service_Handler
27 Server (TestData
*tester
, int id
);
30 int id () { return this->id_
; }
31 size_t get_total_snd () { return this->total_snd_
; }
32 size_t get_total_rcv () { return this->total_rcv_
; }
33 long get_total_w () { return this->total_w_
; }
34 long get_total_r () { 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
);
46 //// This is called when asynchronous <read> operation from the
47 //// socket completes.
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
57 virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result
&result
);
60 int initiate_read_stream ();
61 int initiate_write_stream (ACE_Message_Block
&mb
, size_t nbytes
);
66 ACE_Asynch_Read_Stream rs_
;
67 ACE_Asynch_Write_Stream ws_
;
69 ACE_SYNCH_MUTEX lock_
;
71 int io_count_
; // Number of currently outstanding I/O requests
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 // *******************************************
81 // *******************************************
83 class Client
: public ACE_Service_Handler
86 /// This is called after the new connection has been established.
87 virtual void open (ACE_HANDLE handle
,
88 ACE_Message_Block
&message_block
);
91 Client (TestData
*tester
, int id
);
94 int id () { return this->id_
; }
95 size_t get_total_snd () { return this->total_snd_
; }
96 size_t get_total_rcv () { return this->total_rcv_
; }
97 int get_total_w () { return this->total_w_
; }
98 int get_total_r () { return this->total_r_
; }
100 // This is called to pass the new connection's addresses.
101 virtual void addresses (const ACE_INET_Addr
& peer
,
102 const ACE_INET_Addr
& local
);
104 /// This is called when asynchronous reads from the socket complete
105 virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result
&result
);
107 /// This is called when asynchronous writes from the socket complete
108 virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result
&result
);
113 int initiate_read_stream ();
114 int initiate_write_stream ();
120 ACE_Asynch_Read_Stream rs_
;
121 ACE_Asynch_Write_Stream ws_
;
124 ACE_SYNCH_MUTEX lock_
;
127 int stop_writing_
; // Writes are shut down; just read.
135 #endif /* ACE_TESTS_PROACTOR_TEST_H */