bool DgramTwoWayStream::openMcast(const Contact& group, const Contact& ipLocal) { #ifdef YARP_HAS_ACE multiMode = true; localAddress = ipLocal; localHandle = ACE_INET_Addr((u_short)(localAddress.getPort()), (ACE_UINT32)INADDR_ANY); ACE_SOCK_Dgram_Mcast *dmcast = new ACE_SOCK_Dgram_Mcast; dgram = dmcast; mgram = dmcast; yAssert(dgram!=NULL); int result = -1; ACE_INET_Addr addr(group.getPort(),group.getHost().c_str()); if (ipLocal.isValid()) { result = dmcast->open(addr,NULL,1); if (result==0) { result = restrictMcast(dmcast,group,ipLocal,false); } } else { result = dmcast->open(addr,NULL,1); } if (result!=0) { YARP_ERROR(Logger::get(),"could not open multicast datagram socket"); return false; } configureSystemBuffers(); remoteAddress = group; localHandle.set(localAddress.getPort(),localAddress.getHost().c_str()); remoteHandle.set(remoteAddress.getPort(),remoteAddress.getHost().c_str()); allocate(); return true; #else return false; #endif }
void TAO_ECG_Mcast_EH::add_new_subscriptions (Address_Set& multicast_addresses) { typedef ACE_Unbounded_Set_Iterator<ACE_INET_Addr> Address_Iterator; for (Address_Iterator k = multicast_addresses.begin (); k != multicast_addresses.end (); ++k) { Subscription new_subscription; new_subscription.mcast_addr = *k; ACE_NEW (new_subscription.dgram, ACE_SOCK_Dgram_Mcast); size_t const subscriptions_size = this->subscriptions_.size (); this->subscriptions_.size (subscriptions_size + 1); this->subscriptions_[subscriptions_size] = new_subscription; ACE_SOCK_Dgram_Mcast *socket = new_subscription.dgram; if (socket->open (new_subscription.mcast_addr, this->net_if_, 1) == -1) { ORBSVCS_ERROR ((LM_ERROR, "Error: %d - Unable to open multicast socket\n", ACE_ERRNO_GET)); } if ( socket->enable (ACE_NONBLOCK) != 0 ) { ORBSVCS_ERROR ((LM_ERROR, "Error: %d - Unable to enable nonblocking on mcast_eh\n", ACE_ERRNO_GET)); } if (socket->join (new_subscription.mcast_addr, 1, this->net_if_) == -1) { ORBSVCS_ERROR ((LM_ERROR, "Error: %d - Unable to join multicast group\n", ACE_ERRNO_GET)); } if (this->recvbuf_size_ != 0 && (((ACE_SOCK_Dgram *)socket)->set_option(SOL_SOCKET, SO_RCVBUF, (void *) &this->recvbuf_size_, sizeof (this->recvbuf_size_)) == -1) && errno != ENOTSUP ) { ORBSVCS_ERROR ((LM_ERROR, "Error: %d - Unable to set mcast_eh recvbuf_size:%d\n", ACE_ERRNO_GET, this->recvbuf_size_)); } (void) this->reactor ()->register_handler ( socket->get_handle (), this, ACE_Event_Handler::READ_MASK); } }