s/Uint/UInt/g
[ACE_TAO.git] / TAO / tao / Acceptor_Impl.cpp
blob0d1824c252b45aea5e8e4d702be16c52618900ec
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Acceptor_Impl.cpp
7 * @author Carlos O'Ryan <coryan@uci.edu> Ossama Othman <ossama@dre.vanderbilt.edu>
8 */
9 //=============================================================================
12 #ifndef TAO_ACCEPTOR_IMPL_CPP
13 #define TAO_ACCEPTOR_IMPL_CPP
15 #include "tao/Acceptor_Impl.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "tao/Thread_Per_Connection_Handler.h"
22 #include "tao/Server_Strategy_Factory.h"
23 #include "tao/ORB_Core.h"
24 #include "tao/Transport_Cache_Manager.h"
25 #include "tao/Thread_Lane_Resources.h"
26 #include "tao/Transport.h"
27 #include "tao/debug.h"
29 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
31 //////////////////////////////////////////////////////////////////////////////
33 template <class SVC_HANDLER>
34 TAO_Creation_Strategy<SVC_HANDLER>::TAO_Creation_Strategy (TAO_ORB_Core *orb_core)
35 : ACE_Creation_Strategy<SVC_HANDLER> (0, orb_core->reactor()),
36 orb_core_ (orb_core)
40 template <class SVC_HANDLER> int
41 TAO_Creation_Strategy<SVC_HANDLER>::make_svc_handler (SVC_HANDLER *&sh)
43 if (sh == 0)
45 // Purge connections (if necessary)
46 this->orb_core_->lane_resources ().transport_cache ().purge ();
48 ACE_NEW_RETURN (sh,
49 SVC_HANDLER (this->orb_core_),
50 -1);
53 return 0;
56 //////////////////////////////////////////////////////////////////////////////
58 template <class SVC_HANDLER>
59 TAO_Concurrency_Strategy<SVC_HANDLER>::TAO_Concurrency_Strategy (TAO_ORB_Core *orb_core)
60 : orb_core_ (orb_core)
64 template <class SVC_HANDLER> int
65 TAO_Concurrency_Strategy<SVC_HANDLER>::activate_svc_handler (SVC_HANDLER *sh,
66 void *arg)
68 sh->transport ()->opened_as (TAO::TAO_SERVER_ROLE);
70 // Indicate that this transport was opened in the server role
71 if (TAO_debug_level > 6)
72 TAOLIB_DEBUG ((LM_DEBUG,
73 "TAO (%P|%t) - Concurrency_Strategy::activate_svc_handler, "
74 "opened as TAO_SERVER_ROLE\n"));
76 // Here the service handler has been created and the new connection
77 // has been accepted. #REFCOUNT# is one at this point.
79 if (this->ACE_Concurrency_Strategy<SVC_HANDLER>::activate_svc_handler (sh,
80 arg) == -1)
82 // Activation fails, decrease reference.
83 sh->transport ()->remove_reference ();
85 // #REFCOUNT# is zero at this point.
87 return -1;
90 // The service handler has been activated. Now cache the handler.
91 if (sh->add_transport_to_cache () == -1)
93 // Adding to the cache fails, close the handler.
94 sh->close ();
96 // close() doesn't really decrease reference.
97 sh->transport ()->remove_reference ();
99 // #REFCOUNT# is zero at this point.
101 if (TAO_debug_level > 0)
103 TAOLIB_ERROR ((LM_ERROR,
104 ACE_TEXT ("TAO (%P|%t) - Concurrency_Strategy::activate_svc_handler, ")
105 ACE_TEXT ("could not add the handler to cache\n")));
108 return -1;
111 // Registration with cache is successful, #REFCOUNT# is two at this
112 // point.
113 TAO_Server_Strategy_Factory *f = this->orb_core_->server_factory ();
115 int result = 0;
117 // Do we need to create threads?
118 if (f->activate_server_connections ())
120 // Thread-per-connection concurrency model
121 TAO_Thread_Per_Connection_Handler *tpch = 0;
123 ACE_NEW_RETURN (tpch,
124 TAO_Thread_Per_Connection_Handler (sh,
125 this->orb_core_),
126 -1);
128 result =
129 tpch->activate (f->server_connection_thread_flags (),
130 f->server_connection_thread_count ());
132 else
134 // Otherwise, it is the reactive concurrency model. We may want
135 // to register ourselves with the reactor. Call the register
136 // handler on the transport.
137 result = sh->transport ()->register_handler ();
140 if (result != -1)
142 // Activation/registration successful: the handler has been
143 // registered with either the Reactor or the
144 // Thread-per-Connection_Handler, and the Transport Cache.
145 // #REFCOUNT# is three at this point.
147 // We can let go of our reference.
148 sh->transport ()->remove_reference ();
150 else
152 // Activation/registration failure. #REFCOUNT# is two at this
153 // point.
155 // Remove from cache.
156 sh->transport ()->purge_entry ();
158 // #REFCOUNT# is one at this point.
160 // Close handler.
161 sh->close ();
163 // close() doesn't really decrease reference.
164 sh->transport ()->remove_reference ();
166 // #REFCOUNT# is zero at this point.
168 if (TAO_debug_level > 0)
170 const ACE_TCHAR *error_message = 0;
171 if (f->activate_server_connections ())
172 error_message = ACE_TEXT("could not activate new connection");
173 else
174 error_message = ACE_TEXT("could not register new connection in the reactor");
176 TAOLIB_ERROR ((LM_ERROR,
177 ACE_TEXT("TAO (%P|%t) - Concurrency_Strategy::activate_svc_handler, ")
178 ACE_TEXT("%s\n"), error_message));
181 return -1;
184 // Success: #REFCOUNT# is two at this point.
185 return result;
188 //////////////////////////////////////////////////////////////////////////////
190 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1>
191 TAO_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::TAO_Accept_Strategy (TAO_ORB_Core *orb_core)
192 : ACCEPT_STRATEGY_BASE (orb_core->reactor ())
193 , orb_core_ (orb_core)
197 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> int
198 TAO_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::open (const ACE_PEER_ACCEPTOR_ADDR &local_addr,
199 bool restart)
201 return ACCEPT_STRATEGY_BASE::open (local_addr, restart);
204 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> int
205 TAO_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::accept_svc_handler (SVC_HANDLER *svc_handler)
207 int const result = ACCEPT_STRATEGY_BASE::accept_svc_handler (svc_handler);
208 if (result == -1)
210 svc_handler->transport ()->remove_reference ();
212 // #REFCOUNT# is zero at this point.
215 return result;
219 /////////////////////////////////////////////////////////////////////
221 TAO_END_VERSIONED_NAMESPACE_DECL
223 #endif /* TAO_ACCEPTOR_IMPL_CPP */