summaryrefslogtreecommitdiff
path: root/TAO/tao/Connection_Handler.h
blob: 7009d08b9631ef2a787400500b3aa8462f573293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// -*- C++ -*-

//=============================================================================
/**
 *  @file   Connection_Handler.h
 *
 *  @author Balachandran Natarajan  <bala@cs.wustl.edu>
 */
//=============================================================================

#ifndef TAO_CONNECTION_HANDLER_H
#define TAO_CONNECTION_HANDLER_H

#include /**/ "ace/pre.h"

#include "tao/LF_CH_Event.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "tao/Basic_Types.h"
#include "ace/Event_Handler.h"
#include "ace/Copy_Disabled.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL
class ACE_SOCK;
class ACE_Event_Handler;
ACE_END_VERSIONED_NAMESPACE_DECL

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

class TAO_ORB_Core;
class TAO_Transport;

/*
 * Hook to specialize the connection handler with the
 * concrete connection handler implementation.
 */
//@@ CONNECTION_HANDLER_SPL_INCLUDE_FORWARD_DECL_ADD_HOOK

/**
 * @class TAO_Connection_Handler
 *
 * @brief TAO_Connection_Handler
 *
 * This class is an abstraction for the connection handlers. The
 * connections handler in every protocol can derive from this
 * class as well as the ACE_Svc_Handler specialised for the
 * right protocol. This way, most of the common code for the
 * different protocols would be in this implementation.
 */
class TAO_Export TAO_Connection_Handler : public TAO_LF_CH_Event
{
public:

  /// Constructor
  explicit TAO_Connection_Handler (TAO_ORB_Core *orb_core);

  /// Destructor
  virtual ~TAO_Connection_Handler (void);

  /// Return the underlying transport object
  TAO_Transport *transport (void);

  /// Set the underlying transport object
  void transport (TAO_Transport* transport);

  /// Is the handler closed or timed out?
  bool is_closed (void) const;

  /// Is the handler open?
  bool is_open (void) const;

  /// Closed due to timeout?
  bool is_timeout (void) const;

  /// Is the handler in the process of being connected?
  bool is_connecting (void) const;

  /// Close the underlying connection.
  /**
   * Used by the ORB to actively close connections that are idle,
   * stale or somehow are determined to be broken before the Reactor
   * does.
   *
   * @return Return 0 if the connection was already closed, non-zero
   * otherwise.
   */
  virtual int close_connection (void) = 0;

  /// The event handler calls, here so that other objects who hold a
  /// reference to this object can call the event handler methods.
  virtual int handle_input (ACE_HANDLE fd) = 0;

  /// This method is invoked from the svc () method of the Svc_Handler
  /// Object.
  int svc_i (void);

  /// A open () hook
  /**
   * See Thread_Per_Connection_Handler for a use case
   */
  virtual int open_handler (void *) = 0;

  /// A close() hook, called by the Transport Connector when they want to close
  /// this handler
  virtual int close_handler (u_long flags = 0);

  /// When waiting for an asynchronous connection to complete an
  /// additional reference must be maintained, related to bugzilla
  /// #2417. However once the connection is successfully established,
  /// this reference must be removed. Using connection_pending allows
  /// the connection handler to know that it is opening as a result of
  /// a delayed asynch connection rather than an immediate synch
  /// connection, which has no additional reference needs.
  void connection_pending (void);

  /// A pending connection may be canceled due to an error detected
  /// while the initiating thread is still in the Connector.
  void cancel_pending_connection (void);

  /// Set the Diff-Serv codepoint on outgoing packets.  Only has
  /// effect for remote protocols (e.g., IIOP); no effect for local
  /// protocols (UIOP).  Default implementation is for local
  /// protocols.  Remote protocols must overwrite implementation.
  virtual int set_dscp_codepoint (CORBA::Boolean set_network_priority);
  virtual int set_dscp_codepoint (CORBA::Long dscp_codepoint);

  /// Release the OS resources related to this handler.
  virtual int release_os_resources (void);

  virtual int handle_write_ready (const ACE_Time_Value *timeout);

  /*
   * Hook to add public methods from concrete connection handler
   * implementation onto the base connection handler.
   */

   //@@ CONNECTION_HANDLER_SPL_PUBLIC_METHODS_ADD_HOOK

protected:

  /// Return our TAO_ORB_Core pointer
  TAO_ORB_Core *orb_core (void);

  /// A common function called at the start of any protocol-specific
  /// open. Returns -1 on a failure (although no failure mode is
  /// currently defined).
  int shared_open (void);

  /// Set options on the socket
  int set_socket_option (ACE_SOCK &sock, int snd_size, int rcv_size);

  //@{
  /**
   * @name Helper methods for Event_Handler-based derived classes.
   *
   * Many (actually all so far) implementations of
   * TAO_Connection_Handler are a mixin of TAO_Connection_Handler and
   * some form of ACE_Event_Handler.  The following methods simplify
   * such implementations by capturing the common code in a single
   * place.
   */

  /// Implement the handle_output() callback
  int handle_output_eh (ACE_HANDLE h, ACE_Event_Handler * eh);

  /// Implement the handle_input() callback
  // We're actually going to pull the code from the protocol-specific
  // handlers back into this class, because they ALL look exactly the same.
  // If some other protocol comes along and needs to do something different,
  // it is always free to override handle_input() as it sees fit.
  int handle_input_eh (ACE_HANDLE h, ACE_Event_Handler * eh);
  int handle_input_internal (ACE_HANDLE h, ACE_Event_Handler *eh);

  /// Implement close_connection() for Connection_Handlers that are
  /// also Event_Handlers.
  int close_connection_eh (ACE_Event_Handler * eh);

  /// Pre-invocation hook for I/O operations (handle_input() &
  /// handle_output())
  /**
   * See the SSLIOP protocol for an interesting use-case
   */
  virtual void pre_io_hook (int & return_value);

  /// Post-invocation hook for I/O operations (handle_input() &
  /// handle_output())
  /**
   * See the SSLIOP protocol for an interesting use-case
   */
  virtual void pos_io_hook (int & return_value);
  //@}

private:
  ACE_UNIMPLEMENTED_FUNC (TAO_Connection_Handler (const TAO_Connection_Handler &))
  ACE_UNIMPLEMENTED_FUNC (TAO_Connection_Handler &operator= (const TAO_Connection_Handler &))

  /// Pointer to the TAO_ORB_Core
  TAO_ORB_Core * const orb_core_;

  /// Transport object reference
  TAO_Transport* transport_;

  /// Stores the connection pending state
  bool connection_pending_;

  /// Once closed make sure the transport is not added back to the cache.
  /// This is distinct from the leader-follower state so it cannot be reset.
  bool is_closed_;

  /*
   * Hook to add instance members from derived class
   * onto base Connection_Handler class. Any further
   * additions to this class should go before this
   * hook.
   */
  //@@ CONNECTION_HANDLER_SPL_PRIVATE_DATA_ADD_HOOK
};

//@@ CONNECTION_HANDLER_SPL_EXTERN_ADD_HOOK


/**
 * @class TAO_Auto_Reference
 *
 * @brief TAO_Auto_Reference acts as a "smart pointer" for
 * reference-countable instances.
 *
 * It increments the refrence count in the constructor and decrements
 * it in the destructor. The only requiement for the template
 * parameter is to be a class that provides add_reference() and
 * remove_reference().
 */
template <class T> class TAO_Auto_Reference
  : private ACE_Copy_Disabled
{
public:
  TAO_Auto_Reference (T& r): ref_ (r)
  {
    ref_.add_reference ();
  }

  ~TAO_Auto_Reference ()
  {
    ref_.remove_reference ();
  }

private:
  T& ref_;
};


TAO_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
#include "tao/Connection_Handler.inl"
#endif /* __ACE_INLINE__ */

#include /**/ "ace/post.h"

#endif /*TAO_CONNECTION_HANDLER_H*/