00001
00002
00003
00004
00005
00006 #include "orbsvcs/PortableGroup/UIPMC_Connection_Handler.h"
00007 #include "orbsvcs/PortableGroup/UIPMC_Transport.h"
00008 #include "orbsvcs/PortableGroup/UIPMC_Endpoint.h"
00009
00010 #include "tao/Timeprobe.h"
00011 #include "tao/debug.h"
00012 #include "tao/ORB_Core.h"
00013 #include "tao/ORB.h"
00014 #include "tao/CDR.h"
00015 #include "tao/Server_Strategy_Factory.h"
00016 #include "tao/Transport_Cache_Manager.h"
00017 #include "tao/Thread_Lane_Resources.h"
00018 #include "tao/Base_Transport_Property.h"
00019 #include "tao/Resume_Handle.h"
00020
00021
00022 ACE_RCSID(PortableGroup,
00023 UIPMC_Connection_Handler,
00024 "UIPMC_Connection_Handler.cpp,v 1.30 2006/03/14 06:14:34 jtc Exp")
00025
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027
00028 TAO_UIPMC_Connection_Handler::TAO_UIPMC_Connection_Handler (ACE_Thread_Manager *t)
00029 : TAO_UIPMC_SVC_HANDLER (t, 0 , 0),
00030 TAO_Connection_Handler (0),
00031 udp_socket_ (ACE_sap_any_cast (ACE_INET_Addr &)),
00032 mcast_socket_ (),
00033 using_mcast_ (0)
00034 {
00035
00036
00037
00038
00039
00040 ACE_ASSERT (0);
00041 }
00042
00043
00044 TAO_UIPMC_Connection_Handler::TAO_UIPMC_Connection_Handler (TAO_ORB_Core *orb_core)
00045 : TAO_UIPMC_SVC_HANDLER (orb_core->thr_mgr (), 0, 0),
00046 TAO_Connection_Handler (orb_core),
00047 udp_socket_ (ACE_sap_any_cast (ACE_INET_Addr &)),
00048 mcast_socket_ (),
00049 using_mcast_ (0)
00050 {
00051 TAO_UIPMC_Transport* specific_transport = 0;
00052 ACE_NEW(specific_transport,
00053 TAO_UIPMC_Transport(this, orb_core, 0));
00054
00055
00056 this->transport (specific_transport);
00057 }
00058
00059
00060 TAO_UIPMC_Connection_Handler::~TAO_UIPMC_Connection_Handler (void)
00061 {
00062 if (this->using_mcast_)
00063 {
00064
00065
00066 this->mcast_socket_.close ();
00067 }
00068 else
00069 this->udp_socket_.close ();
00070
00071 delete this->transport ();
00072 }
00073
00074 ACE_HANDLE
00075 TAO_UIPMC_Connection_Handler::get_handle (void) const
00076 {
00077 if (this->using_mcast_)
00078 return this->mcast_socket_.get_handle ();
00079 else
00080 return this->udp_socket_.get_handle ();
00081 }
00082
00083 const ACE_INET_Addr &
00084 TAO_UIPMC_Connection_Handler::addr (void)
00085 {
00086 return this->addr_;
00087 }
00088
00089
00090 void
00091 TAO_UIPMC_Connection_Handler::addr (const ACE_INET_Addr &addr)
00092 {
00093 this->addr_ = addr;
00094 }
00095
00096
00097 const ACE_INET_Addr &
00098 TAO_UIPMC_Connection_Handler::local_addr (void)
00099 {
00100 return local_addr_;
00101 }
00102
00103
00104 void
00105 TAO_UIPMC_Connection_Handler::local_addr (const ACE_INET_Addr &addr)
00106 {
00107 local_addr_ = addr;
00108 }
00109
00110
00111 const ACE_SOCK_Dgram &
00112 TAO_UIPMC_Connection_Handler::dgram (void)
00113 {
00114 return this->udp_socket_;
00115 }
00116
00117 const ACE_SOCK_Dgram_Mcast &
00118 TAO_UIPMC_Connection_Handler::mcast_dgram (void)
00119 {
00120 return this->mcast_socket_;
00121 }
00122
00123
00124 int
00125 TAO_UIPMC_Connection_Handler::open_handler (void *v)
00126 {
00127 return this->open (v);
00128 }
00129
00130 int
00131 TAO_UIPMC_Connection_Handler::open (void*)
00132 {
00133 this->udp_socket_.open (this->local_addr_);
00134
00135 if(TAO_debug_level > 5)
00136 {
00137 ACE_DEBUG ((LM_DEBUG,
00138 ACE_TEXT("TAO (%P|%t) TAO_UIPMC_Connection_Handler::open, ")
00139 ACE_TEXT("listening on: <%s:%u>\n"),
00140 this->local_addr_.get_host_addr (),
00141 this->local_addr_.get_port_number ()));
00142 }
00143
00144 this->using_mcast_ = 0;
00145
00146
00147
00148
00149 if (!this->transport ()->post_open ((size_t) this->udp_socket_.get_handle ()))
00150 return -1;
00151
00152 return 0;
00153 }
00154
00155 int
00156 TAO_UIPMC_Connection_Handler::open_server (void)
00157 {
00158 this->mcast_socket_.join (this->local_addr_);
00159 if( TAO_debug_level > 5)
00160 {
00161 ACE_DEBUG ((LM_DEBUG,
00162 ACE_TEXT("TAO (%P|%t) TAO_UIPMC_Connection_Handler::open_server, ")
00163 ACE_TEXT("subcribed to multicast group at %s:%d\n"),
00164 this->local_addr_.get_host_addr (),
00165 this->local_addr_.get_port_number ()
00166 ));
00167 }
00168
00169 this->transport ()->id ((size_t) this->mcast_socket_.get_handle ());
00170 this->using_mcast_ = 1;
00171
00172 return 0;
00173 }
00174
00175 int
00176 TAO_UIPMC_Connection_Handler::resume_handler (void)
00177 {
00178 return ACE_Event_Handler::ACE_APPLICATION_RESUMES_HANDLER;
00179 }
00180
00181 int
00182 TAO_UIPMC_Connection_Handler::close_connection (void)
00183 {
00184 return this->close_connection_eh (this);
00185 }
00186
00187 int
00188 TAO_UIPMC_Connection_Handler::handle_input (ACE_HANDLE h)
00189 {
00190 return this->handle_input_eh (h, this);
00191 }
00192
00193 int
00194 TAO_UIPMC_Connection_Handler::handle_output (ACE_HANDLE handle)
00195 {
00196 int result =
00197 this->handle_output_eh (handle, this);
00198
00199 if (result == -1)
00200 {
00201 this->close_connection ();
00202 return 0;
00203 }
00204
00205 return result;
00206 }
00207
00208 int
00209 TAO_UIPMC_Connection_Handler::handle_timeout (const ACE_Time_Value &,
00210 const void *)
00211 {
00212
00213
00214
00215 return this->close ();
00216 }
00217
00218 int
00219 TAO_UIPMC_Connection_Handler::handle_close (ACE_HANDLE,
00220 ACE_Reactor_Mask)
00221 {
00222
00223
00224
00225
00226
00227 return 0;
00228 }
00229
00230 int
00231 TAO_UIPMC_Connection_Handler::close (u_long)
00232 {
00233 this->state_changed (TAO_LF_Event::LFS_CONNECTION_CLOSED,
00234 this->orb_core ()->leader_follower ());
00235 this->transport ()->remove_reference ();
00236 return 0;
00237 }
00238
00239 int
00240 TAO_UIPMC_Connection_Handler::release_os_resources (void)
00241 {
00242 return this->peer().close ();
00243 }
00244
00245 int
00246 TAO_UIPMC_Connection_Handler::add_transport_to_cache (void)
00247 {
00248 ACE_INET_Addr addr;
00249
00250
00251
00252
00253
00254
00255
00256 TAO_UIPMC_Endpoint endpoint (addr);
00257
00258
00259 TAO_Base_Transport_Property prop (&endpoint);
00260
00261
00262 return this->orb_core ()->lane_resources ()
00263 .transport_cache ().cache_transport (&prop,
00264 this->transport ());
00265 }
00266
00267 TAO_END_VERSIONED_NAMESPACE_DECL