Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / protocols / ace / INet / StreamHandler.h
blobf2314122f114ce0017348b4491d4a543d5b2bd9d
1 /**
2 * @file StreamHandler.h
4 * @author Martin Corino <mcorino@remedy.nl>
5 */
7 #ifndef ACE_IOS_STREAM_HANDLER_H
8 #define ACE_IOS_STREAM_HANDLER_H
10 #include /**/ "ace/pre.h"
12 #include /**/ "ace/config-all.h"
14 #if !defined (ACE_LACKS_PRAGMA_ONCE)
15 # pragma once
16 #endif /* ACE_LACKS_PRAGMA_ONCE */
18 #include "ace/Svc_Handler.h"
19 #include "ace/Reactor_Notification_Strategy.h"
21 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
23 namespace ACE
25 namespace IOS
27 /**
28 * @class ACE_IOS_StreamHandler
30 * @brief Encapsulates streamed connection.
32 * This class provides the connection point for the
33 * ACE Acceptor and Connector based patterns and the
34 * ACE Reactor framework to C++ standard streams
35 * based classes.
37 template <ACE_PEER_STREAM_1, ACE_SYNCH_DECL>
38 class StreamHandler
39 : public ACE_Svc_Handler<ACE_PEER_STREAM, ACE_SYNCH_USE>
41 public:
42 // useful traits
43 typedef StreamHandler<ACE_PEER_STREAM, ACE_SYNCH_USE> this_type;
44 typedef ACE_Svc_Handler<ACE_PEER_STREAM, ACE_SYNCH_USE> base_type;
45 typedef ACE_Message_Queue<ACE_SYNCH_USE> mq_type;
47 /// Constructor
48 StreamHandler (const ACE_Synch_Options &synch_options = ACE_Synch_Options::defaults,
49 ACE_Thread_Manager *thr_mgr = 0,
50 mq_type *mq = 0,
51 ACE_Reactor *reactor = ACE_Reactor::instance ());
53 /// Destructor
54 virtual ~StreamHandler ();
56 /// Activate the connection
57 virtual int open (void * = 0);
59 /// Close the connection
60 virtual int close (u_long flags = 0);
62 /// Called to handle incoming data when using StreamHandler in
63 /// reactive mode
64 virtual int handle_input (ACE_HANDLE);
66 /// Called to handle outgoing data when using StreamHandler in
67 /// reactive mode
68 virtual int handle_output (ACE_HANDLE);
70 /// Called by streambuffer to read/receive new data from peer
71 int read_from_stream (void * buf, size_t length, size_t char_size);
73 /// Called by streambuffer to send new data to peer
74 int write_to_stream (const void * buf, size_t length, size_t char_size);
76 /// Returns true as long as the connection to peer is active
77 bool is_connected () const;
79 /// Returns true if StreamHandler has been configured for reactive mode
80 bool using_reactor () const;
82 private:
83 enum
85 MAX_INPUT_SIZE = 4096
88 /// Attempts to receive data from peer and queue it.
89 /// Called either from handle_input in reactive mode or
90 /// directly from read_from_stream when non-reactive.
91 int handle_output_i (ACE_Time_Value* timeout = 0);
93 /// Attempts to send queued data to peer.
94 /// Called either from handle_output in reactive mode
95 /// or directly from write_to_stream when non-reactive.
96 int handle_input_i (size_t rdlen, ACE_Time_Value* timeout = 0);
98 /// processes queued input
99 int process_input (char* buf,
100 size_t& char_length,
101 size_t char_size,
102 ACE_Time_Value* timeout);
104 /// Returns true if a timeout is to be used on IO operations.
105 bool use_timeout () const;
107 /// Returns true is the queued data contains at least char_size bytes.
108 bool char_in_queue (size_t char_size);
110 bool connected_;
111 ACE_Synch_Options sync_opt_;
112 bool send_timeout_;
113 bool receive_timeout_;
114 ACE_Reactor_Notification_Strategy notification_strategy_;
116 class NotificationStrategyGuard
118 public:
119 NotificationStrategyGuard (this_type& queue_owner,
120 ACE_Reactor_Notification_Strategy* ns)
121 : queue_owner_ (queue_owner)
123 this->queue_owner_.msg_queue ()->notification_strategy (ns);
125 ~NotificationStrategyGuard ()
127 this->queue_owner_.msg_queue ()->notification_strategy (0);
129 private:
130 this_type& queue_owner_;
134 typedef StreamHandler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> SockStreamHandler;
138 ACE_END_VERSIONED_NAMESPACE_DECL
140 #include "ace/INet/StreamHandler.cpp"
142 #include /**/ "ace/post.h"
143 #endif /* ACE_IOS_STREAM_HANDLER_H */