bool DgramTwoWayStream::join(const Contact& group, bool sender, const Contact& ipLocal) { #ifdef YARP_HAS_ACE YARP_DEBUG(Logger::get(),String("subscribing to mcast address ") + group.toURI() + " for " + (sender?"writing":"reading")); multiMode = true; if (sender) { if (ipLocal.isValid()) { return openMcast(group,ipLocal); } else { // just use udp as normal return open(group); } //return; } ACE_SOCK_Dgram_Mcast *dmcast = new ACE_SOCK_Dgram_Mcast; //possible flags: ((ACE_SOCK_Dgram_Mcast::options)(ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL | ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES)); dgram = dmcast; mgram = dmcast; yAssert(dgram!=NULL); ACE_INET_Addr addr(group.getPort(),group.getHost().c_str()); int result = -1; if (ipLocal.isValid()) { result = 0; result = dmcast->join(addr,1); if (result==0) { result = restrictMcast(dmcast,group,ipLocal,true); } } else { result = dmcast->join(addr,1); } configureSystemBuffers(); if (result!=0) { YARP_ERROR(Logger::get(),"cannot connect to multi-cast address"); happy = false; return false; } localAddress = group; 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); } }
int send_multicast (const ACE_INET_Addr &mcast_addr) { const char *message = "this is the message!\n"; ACE_SOCK_Dgram_Mcast udp; if (-1 == udp.join (mcast_addr)) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("join")), -1); ssize_t sent = udp.send (message, ACE_OS::strlen (message) + 1); udp.close (); if (sent == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send")), -1); return 0; }