MCast.cpp

Go to the documentation of this file.
00001 // $Id: MCast.cpp 73791 2006-07-27 20:54:56Z wotte $
00002 
00003 #include "orbsvcs/AV/MCast.h"
00004 #include "orbsvcs/AV/AVStreams_i.h"
00005 #include "tao/debug.h"
00006 
00007 #if !defined (__ACE_INLINE__)
00008 #include "orbsvcs/AV/MCast.inl"
00009 #endif /* __ACE_INLINE__ */
00010 
00011 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 //------------------------------------------------------------
00014 //TAO_AV_UDP_MCast_Flow_Handler
00015 //------------------------------------------------------------
00016 
00017 TAO_AV_UDP_MCast_Flow_Handler::TAO_AV_UDP_MCast_Flow_Handler (void)
00018 {
00019   ACE_NEW (transport_,
00020            TAO_AV_UDP_MCast_Transport (this));
00021   ACE_NEW (dgram_mcast_,
00022            ACE_SOCK_Dgram_Mcast);
00023 }
00024 
00025 TAO_AV_UDP_MCast_Flow_Handler::~TAO_AV_UDP_MCast_Flow_Handler (void)
00026 {
00027   delete this->transport_;
00028   delete this->dgram_mcast_;
00029 }
00030 
00031 
00032 int
00033 TAO_AV_UDP_MCast_Flow_Handler::handle_input (ACE_HANDLE /*fd*/)
00034 {
00035   return this->protocol_object_->handle_input ();
00036 //  return 0;
00037 }
00038 
00039 int
00040 TAO_AV_UDP_MCast_Flow_Handler::handle_timeout (const ACE_Time_Value &tv,
00041                                                const void *arg)
00042 {
00043   return TAO_AV_Flow_Handler::handle_timeout (tv,arg);
00044 }
00045 
00046 ACE_HANDLE
00047 TAO_AV_UDP_MCast_Flow_Handler::get_handle (void) const
00048 {
00049   if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"TAO_AV_UDP_MCast_Flow_Handler::get_handle "));
00050   return this->get_mcast_socket ()->get_handle () ;
00051 }
00052 
00053 void
00054 TAO_AV_UDP_MCast_Flow_Handler::set_peer_addr (ACE_INET_Addr *peer_addr)
00055 {
00056   this->peer_addr_ = peer_addr;
00057 }
00058 
00059 //------------------------------------------------------------
00060 // TAO_AV_UDP_MCast_Transport
00061 //------------------------------------------------------------
00062 
00063 TAO_AV_UDP_MCast_Transport::TAO_AV_UDP_MCast_Transport (void)
00064   :handler_ (0)
00065 {
00066 }
00067 
00068 TAO_AV_UDP_MCast_Transport::TAO_AV_UDP_MCast_Transport (TAO_AV_UDP_MCast_Flow_Handler *handler)
00069   :handler_ (handler)
00070 {
00071 }
00072 
00073 TAO_AV_UDP_MCast_Transport::~TAO_AV_UDP_MCast_Transport (void)
00074 {
00075 }
00076 
00077 int
00078 TAO_AV_UDP_MCast_Transport::open (ACE_Addr * /*address*/)
00079 {
00080   return 0;
00081 }
00082 
00083 int
00084 TAO_AV_UDP_MCast_Transport::close (void)
00085 {
00086   return 0;
00087 }
00088 
00089 
00090 ACE_Addr*
00091 TAO_AV_UDP_MCast_Transport::get_peer_addr (void)
00092 {
00093   return &this->peer_addr_;
00094 }
00095 
00096 ACE_Addr*
00097 TAO_AV_UDP_MCast_Transport::get_local_addr (void)
00098 {
00099   this->handler_->get_mcast_socket ()->get_local_addr (this->local_addr_);
00100   return &this->local_addr_;
00101 }
00102 
00103 ssize_t
00104 TAO_AV_UDP_MCast_Transport::send (const ACE_Message_Block *mblk, ACE_Time_Value *)
00105 {
00106   // For the most part this was copied from GIOP::send_request and
00107   // friends.
00108 
00109   iovec iov[ACE_IOV_MAX];
00110   int iovcnt = 0;
00111   ssize_t n = 0;
00112   ssize_t nbytes = 0;
00113 
00114   for (const ACE_Message_Block *i = mblk;
00115        i != 0;
00116        i = i->cont ())
00117     {
00118       // Make sure there is something to send!
00119       if (i->length () > 0)
00120         {
00121           iov[iovcnt].iov_base = i->rd_ptr ();
00122           iov[iovcnt].iov_len  = static_cast<u_long> (i->length ());
00123           iovcnt++;
00124 
00125           // The buffer is full make a OS call.  @@ TODO this should
00126           // be optimized on a per-platform basis, for instance, some
00127           // platforms do not implement writev() there we should copy
00128           // the data into a buffer and call send_n(). In other cases
00129           // there may be some limits on the size of the iovec, there
00130           // we should set ACE_IOV_MAX to that limit.
00131           if (iovcnt == ACE_IOV_MAX)
00132             {
00133               n = this->handler_->get_mcast_socket ()->send ((const iovec *) iov,
00134                                                              iovcnt);
00135 
00136               if (n < 1)
00137                 return n;
00138 
00139               nbytes += n;
00140               iovcnt = 0;
00141             }
00142         }
00143     }
00144 
00145   // Check for remaining buffers to be sent!
00146   if (iovcnt != 0)
00147     {
00148       n = this->handler_->get_mcast_socket ()->send ((const iovec *) iov,
00149                                                      iovcnt);
00150       if (n < 1)
00151         return n;
00152 
00153       nbytes += n;
00154     }
00155 
00156   return nbytes;
00157 }
00158 
00159 ssize_t
00160 TAO_AV_UDP_MCast_Transport::send (const char *buf,
00161                                   size_t len,
00162                                   ACE_Time_Value *)
00163 {
00164 //   if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"TAO_AV_UDP_MCast_Transport::send "));
00165 //   char addr [BUFSIZ];
00166 //   this->peer_addr_.addr_to_string (addr,BUFSIZ);
00167 //   if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"to %s\n",addr));
00168 
00169   return this->handler_->get_mcast_socket ()->send (buf, len);
00170 
00171 }
00172 
00173 ssize_t
00174 TAO_AV_UDP_MCast_Transport::send (const iovec *iov,
00175                                   int iovcnt,
00176                                   ACE_Time_Value *)
00177 {
00178   return this->handler_->get_mcast_socket ()->send (iov,
00179                                                     iovcnt,
00180                                                     0);
00181 
00182 }
00183 
00184 int
00185 TAO_AV_UDP_MCast_Transport::mtu (void)
00186 {
00187   return ACE_MAX_DGRAM_SIZE;
00188 }
00189 
00190 
00191 ssize_t
00192 TAO_AV_UDP_MCast_Transport::recv (char *buf,
00193                                   size_t len,
00194                                   ACE_Time_Value *)
00195 {
00196   return this->handler_->get_mcast_socket ()->recv (buf, len,this->peer_addr_);
00197 }
00198 
00199 ssize_t
00200 TAO_AV_UDP_MCast_Transport::recv (char *buf,
00201                                   size_t len,
00202                                   int flags,
00203                                   ACE_Time_Value *timeout)
00204 {
00205   return this->handler_->get_mcast_socket ()->recv (buf,
00206                                                     len,
00207                                                     this->peer_addr_,
00208                                                     flags,
00209                                                     timeout);
00210 }
00211 
00212 ssize_t
00213 TAO_AV_UDP_MCast_Transport::recv (iovec *iov,
00214                                   int /*iovcnt*/,
00215                             ACE_Time_Value *timeout)
00216 {
00217   return handler_->get_mcast_socket ()->recv (iov,this->peer_addr_,0,timeout);
00218 }
00219 
00220 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:47:49 2010 for TAO_AV by  doxygen 1.4.7