Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Connection_Handler.h
blobecc2a877c11808134e59c48cc6f3936c51f0decf
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Connection_Handler.h
7 * @author Balachandran Natarajan <bala@cs.wustl.edu>
8 */
9 //=============================================================================
11 #ifndef TAO_CONNECTION_HANDLER_H
12 #define TAO_CONNECTION_HANDLER_H
14 #include /**/ "ace/pre.h"
16 #include "tao/LF_CH_Event.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "tao/Basic_Types.h"
23 #include "ace/Event_Handler.h"
24 #include "ace/Copy_Disabled.h"
26 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
27 class ACE_SOCK;
28 class ACE_Event_Handler;
29 ACE_END_VERSIONED_NAMESPACE_DECL
31 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
33 class TAO_ORB_Core;
34 class TAO_Transport;
36 /**
37 * @class TAO_Connection_Handler
39 * @brief TAO_Connection_Handler
41 * This class is an abstraction for the connection handlers. The
42 * connections handler in every protocol can derive from this
43 * class as well as the ACE_Svc_Handler specialised for the
44 * right protocol. This way, most of the common code for the
45 * different protocols would be in this implementation.
47 class TAO_Export TAO_Connection_Handler : public TAO_LF_CH_Event
49 public:
50 /// Constructor
51 explicit TAO_Connection_Handler (TAO_ORB_Core *orb_core);
53 /// Destructor
54 virtual ~TAO_Connection_Handler ();
56 /// Return the underlying transport object
57 TAO_Transport *transport ();
59 /// Set the underlying transport object
60 void transport (TAO_Transport* transport);
62 /// Is the handler closed or timed out?
63 bool is_closed () const;
65 /// Is the handler open?
66 bool is_open () const;
68 /// Closed due to timeout?
69 bool is_timeout () const;
71 /// Is the handler in the process of being connected?
72 bool is_connecting () const;
74 /// Close the underlying connection.
75 /**
76 * Used by the ORB to actively close connections that are idle,
77 * stale or somehow are determined to be broken before the Reactor
78 * does.
80 * @return Return 0 if the connection was already closed, non-zero
81 * otherwise.
83 virtual int close_connection () = 0;
85 /// The event handler calls, here so that other objects who hold a
86 /// reference to this object can call the event handler methods.
87 virtual int handle_input (ACE_HANDLE fd) = 0;
89 /// This method is invoked from the svc () method of the Svc_Handler
90 /// Object.
91 int svc_i ();
93 /// A open () hook
94 /**
95 * See Thread_Per_Connection_Handler for a use case
97 virtual int open_handler (void *) = 0;
99 /// A close() hook, called by the Transport Connector when they want to close
100 /// this handler
101 virtual int close_handler (u_long flags = 0);
103 /// When waiting for an asynchronous connection to complete an
104 /// additional reference must be maintained, related to bugzilla
105 /// #2417. However once the connection is successfully established,
106 /// this reference must be removed. Using connection_pending allows
107 /// the connection handler to know that it is opening as a result of
108 /// a delayed asynch connection rather than an immediate synch
109 /// connection, which has no additional reference needs.
110 void connection_pending ();
112 /// A pending connection may be canceled due to an error detected
113 /// while the initiating thread is still in the Connector.
114 void cancel_pending_connection ();
116 /// Set the Diff-Serv codepoint on outgoing packets. Only has
117 /// effect for remote protocols (e.g., IIOP); no effect for local
118 /// protocols (UIOP). Default implementation is for local
119 /// protocols. Remote protocols must overwrite implementation.
120 virtual int set_dscp_codepoint (CORBA::Boolean set_network_priority);
121 virtual int set_dscp_codepoint (CORBA::Long dscp_codepoint);
123 /// Release the OS resources related to this handler.
124 virtual int release_os_resources ();
126 virtual int handle_write_ready (const ACE_Time_Value *timeout);
128 protected:
129 /// Return our TAO_ORB_Core pointer
130 TAO_ORB_Core *orb_core ();
132 /// A common function called at the start of any protocol-specific
133 /// open. Returns -1 on a failure (although no failure mode is
134 /// currently defined).
135 int shared_open ();
137 /// Set options on the socket
138 int set_socket_option (ACE_SOCK &sock, int snd_size, int rcv_size);
140 //@{
142 * @name Helper methods for Event_Handler-based derived classes.
144 * Many (actually all so far) implementations of
145 * TAO_Connection_Handler are a mixin of TAO_Connection_Handler and
146 * some form of ACE_Event_Handler. The following methods simplify
147 * such implementations by capturing the common code in a single
148 * place.
151 /// Implement the handle_output() callback
152 int handle_output_eh (ACE_HANDLE h, ACE_Event_Handler * eh);
154 /// Implement the handle_input() callback
155 // We're actually going to pull the code from the protocol-specific
156 // handlers back into this class, because they ALL look exactly the same.
157 // If some other protocol comes along and needs to do something different,
158 // it is always free to override handle_input() as it sees fit.
159 int handle_input_eh (ACE_HANDLE h, ACE_Event_Handler * eh);
160 int handle_input_internal (ACE_HANDLE h, ACE_Event_Handler *eh);
162 /// Implement close_connection() for Connection_Handlers that are
163 /// also Event_Handlers.
164 int close_connection_eh (ACE_Event_Handler * eh);
166 /// Pre-invocation hook for I/O operations (handle_input() &
167 /// handle_output())
169 * See the SSLIOP protocol for an interesting use-case
171 virtual void pre_io_hook (int & return_value);
173 /// Post-invocation hook for I/O operations (handle_input() &
174 /// handle_output())
176 * See the SSLIOP protocol for an interesting use-case
178 virtual void pos_io_hook (int & return_value);
179 //@}
181 private:
182 TAO_Connection_Handler (const TAO_Connection_Handler &) = delete;
183 TAO_Connection_Handler &operator= (const TAO_Connection_Handler &) = delete;
185 /// Pointer to the TAO_ORB_Core
186 TAO_ORB_Core * const orb_core_;
188 /// Transport object reference
189 TAO_Transport* transport_;
191 /// Stores the connection pending state
192 bool connection_pending_;
194 /// Once closed make sure the transport is not added back to the cache.
195 /// This is distinct from the leader-follower state so it cannot be reset.
196 bool is_closed_;
200 * @class TAO_Auto_Reference
202 * @brief TAO_Auto_Reference acts as a "smart pointer" for
203 * reference-countable instances.
205 * It increments the refrence count in the constructor and decrements
206 * it in the destructor. The only requiement for the template
207 * parameter is to be a class that provides add_reference() and
208 * remove_reference().
210 template <class T> class TAO_Auto_Reference
211 : private ACE_Copy_Disabled
213 public:
214 TAO_Auto_Reference (T& r): ref_ (r)
216 ref_.add_reference ();
219 ~TAO_Auto_Reference ()
221 ref_.remove_reference ();
224 private:
225 T& ref_;
229 TAO_END_VERSIONED_NAMESPACE_DECL
231 #if defined (__ACE_INLINE__)
232 #include "tao/Connection_Handler.inl"
233 #endif /* __ACE_INLINE__ */
235 #include /**/ "ace/post.h"
237 #endif /*TAO_CONNECTION_HANDLER_H*/