OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Private Attributes | List of all members
OpenDDS::RTPS::Spdp::SendStun Class Reference
Inheritance diagram for OpenDDS::RTPS::Spdp::SendStun:
Inheritance graph
[legend]
Collaboration diagram for OpenDDS::RTPS::Spdp::SendStun:
Collaboration graph
[legend]

Public Member Functions

 SendStun (const DCPS::RcHandle< SpdpTransport > &tport, const ACE_INET_Addr &address, const STUN::Message &message)
 
void execute ()
 
- Public Member Functions inherited from OpenDDS::DCPS::Job
virtual ~Job ()
 
- Public Member Functions inherited from OpenDDS::DCPS::RcObject
virtual ~RcObject ()
 
virtual void _add_ref ()
 
virtual void _remove_ref ()
 
long ref_count () const
 
WeakObject_get_weak_object () const
 

Private Attributes

DCPS::WeakRcHandle< SpdpTransporttport_
 
ACE_INET_Addr address_
 
STUN::Message message_
 

Additional Inherited Members

- Protected Member Functions inherited from OpenDDS::DCPS::RcObject
 RcObject ()
 

Detailed Description

Definition at line 559 of file Spdp.h.

Constructor & Destructor Documentation

◆ SendStun()

OpenDDS::RTPS::Spdp::SendStun::SendStun ( const DCPS::RcHandle< SpdpTransport > &  tport,
const ACE_INET_Addr address,
const STUN::Message message 
)
inline

Definition at line 561 of file Spdp.h.

564  : tport_(tport)
565  , address_(address)
566  , message_(message)
567  {}
STUN::Message message_
Definition: Spdp.h:572
DCPS::WeakRcHandle< SpdpTransport > tport_
Definition: Spdp.h:570
ACE_INET_Addr address_
Definition: Spdp.h:571

Member Function Documentation

◆ execute()

void OpenDDS::RTPS::Spdp::SendStun::execute ( void  )
virtual

Implements OpenDDS::DCPS::Job.

Definition at line 3290 of file Spdp.cpp.

References ACE_ERROR, ACE_GUARD, ACE_TEXT(), OpenDDS::DCPS::DCPS_debug_level, OpenDDS::STUN::encoding(), ENETUNREACH, if(), LM_WARNING, OpenDDS::DCPS::MCK_STUN, OpenDDS::DCPS::RcHandle< T >::reset(), ACE_SOCK_Dgram::send(), socket(), and OpenDDS::RTPS::Spdp::tport_.

3291 {
3292  DCPS::RcHandle<SpdpTransport> tport = tport_.lock();
3293  if (!tport) return;
3294 
3295  DCPS::RcHandle<Spdp> outer = tport->outer_.lock();
3296  if (!outer) return;
3297 
3298  ACE_GUARD(ACE_Thread_Mutex, g, outer->lock_);
3299  tport->wbuff_.reset();
3300  Serializer serializer(&tport->wbuff_, STUN::encoding);
3301  const_cast<STUN::Message&>(message_).block = &tport->wbuff_;
3302  serializer << message_;
3303 
3304 #ifdef OPENDDS_TESTING_FEATURES
3305  if (outer->sedp_->transport_inst()->should_drop(tport->wbuff_.length())) {
3306  return;
3307  }
3308 #endif
3309 
3310  const ACE_SOCK_Dgram& socket = tport->choose_send_socket(address_);
3311  const ssize_t res = socket.send(tport->wbuff_.rd_ptr(), tport->wbuff_.length(), address_);
3312  if (res < 0) {
3313  if (outer->sedp_->transport_inst()->count_messages()) {
3314  // Have the lock.
3315  const DCPS::InternalMessageCountKey key(DCPS::NetworkAddress(address_), DCPS::MCK_STUN, address_ == outer->config_->spdp_stun_server_address());
3316  tport->transport_statistics_.message_count[key].send_fail(tport->wbuff_.length());
3317  }
3318  const int err = errno;
3319  if (err != ENETUNREACH || !tport->network_is_unreachable_) {
3320  errno = err;
3321  if (DCPS::DCPS_debug_level > 0) {
3322  ACE_ERROR((LM_WARNING,
3323  ACE_TEXT("(%P|%t) WARNING: Spdp::SendStun::execute() - ")
3324  ACE_TEXT("destination %C failed send: %m\n"), DCPS::LogAddr(address_).c_str()));
3325  }
3326  }
3327  if (err == ENETUNREACH) {
3328  tport->network_is_unreachable_ = true;
3329  }
3330  } else {
3331  if (outer->sedp_->transport_inst()->count_messages()) {
3332  // Have the lock.
3333  const DCPS::InternalMessageCountKey key(DCPS::NetworkAddress(address_), DCPS::MCK_STUN, address_ == outer->config_->spdp_stun_server_address());
3334  tport->transport_statistics_.message_count[key].send(tport->wbuff_.length());
3335  }
3336  tport->network_is_unreachable_ = false;
3337  }
3338 }
const MessageCountKind MCK_STUN
#define ACE_ERROR(X)
#define ACE_GUARD(MUTEX, OBJ, LOCK)
if(!(yy_init))
sequence< octet > key
int ssize_t
const DCPS::Encoding encoding(DCPS::Encoding::KIND_UNALIGNED_CDR, DCPS::ENDIAN_BIG)
ACE_HANDLE socket(int protocol_family, int type, int proto)
OpenDDS_Dcps_Export unsigned int DCPS_debug_level
Definition: debug.cpp:30
STUN::Message message_
Definition: Spdp.h:572
DCPS::WeakRcHandle< SpdpTransport > tport_
Definition: Spdp.h:570
ACE_TEXT("TCP_Factory")
ACE_thread_mutex_t lock_
ssize_t send(const void *buf, size_t n, const ACE_Addr &addr, int flags=0) const
ACE_INET_Addr address_
Definition: Spdp.h:571

Member Data Documentation

◆ address_

ACE_INET_Addr OpenDDS::RTPS::Spdp::SendStun::address_
private

Definition at line 571 of file Spdp.h.

◆ message_

STUN::Message OpenDDS::RTPS::Spdp::SendStun::message_
private

Definition at line 572 of file Spdp.h.

◆ tport_

DCPS::WeakRcHandle<SpdpTransport> OpenDDS::RTPS::Spdp::SendStun::tport_
private

Definition at line 570 of file Spdp.h.


The documentation for this class was generated from the following files: