OpenDDS::DCPS::TcpSendStrategy Class Reference

#include <TcpSendStrategy.h>

Inheritance diagram for OpenDDS::DCPS::TcpSendStrategy:

Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::TcpSendStrategy:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TcpSendStrategy (std::size_t id, const TcpDataLink_rch &link, const TcpInst_rch &config, const TcpConnection_rch &connection, TcpSynchResource *synch_resource, const TransportReactorTask_rch &task, Priority priority)
virtual ~TcpSendStrategy ()
int reset (TcpConnection *connection, bool reset_mode=false)
virtual void schedule_output ()
 Enable or disable output processing by the reactor according to mode.

Protected Member Functions

virtual ssize_t send_bytes (const iovec iov[], int n, int &bp)
virtual ACE_HANDLE get_handle ()
virtual ssize_t send_bytes_i (const iovec iov[], int n)
virtual void relink (bool do_suspend=true)
virtual void stop_i ()
 Let the subclass stop.

Private Attributes

TcpConnection_rch connection_
TcpDataLink_rch link_
TransportReactorTask_rch reactor_task_

Detailed Description

Definition at line 23 of file TcpSendStrategy.h.


Constructor & Destructor Documentation

OpenDDS::DCPS::TcpSendStrategy::TcpSendStrategy ( std::size_t  id,
const TcpDataLink_rch link,
const TcpInst_rch config,
const TcpConnection_rch connection,
TcpSynchResource synch_resource,
const TransportReactorTask_rch task,
Priority  priority 
)

Definition at line 20 of file TcpSendStrategy.cpp.

References DBG_ENTRY_LVL.

00028   : TransportSendStrategy(id, static_rchandle_cast<TransportInst>(config),
00029                           synch_resource, priority,
00030                           new ReactorSynchStrategy(
00031                                 this,
00032                                 task->get_reactor()))
00033   , connection_(connection)
00034   , link_(link)
00035   , reactor_task_(task)
00036 {
00037   DBG_ENTRY_LVL("TcpSendStrategy","TcpSendStrategy",6);
00038 
00039   connection->set_send_strategy(this);
00040 }

OpenDDS::DCPS::TcpSendStrategy::~TcpSendStrategy (  )  [virtual]

Definition at line 42 of file TcpSendStrategy.cpp.

References DBG_ENTRY_LVL.

00043 {
00044   DBG_ENTRY_LVL("TcpSendStrategy","~TcpSendStrategy",6);
00045 }


Member Function Documentation

ACE_HANDLE OpenDDS::DCPS::TcpSendStrategy::get_handle (  )  [protected, virtual]

Reimplemented from OpenDDS::DCPS::TransportSendStrategy.

Definition at line 125 of file TcpSendStrategy.cpp.

References connection_, and OpenDDS::DCPS::RcHandle< T >::is_nil().

Referenced by schedule_output().

00126 {
00127   TcpConnection_rch connection = this->connection_;
00128 
00129   if (connection.is_nil())
00130     return ACE_INVALID_HANDLE;
00131 
00132   return connection->peer().get_handle();
00133 }

void OpenDDS::DCPS::TcpSendStrategy::relink ( bool  do_suspend = true  )  [protected, virtual]

Delegate to the connection object to re-establish the connection.

Reimplemented from OpenDDS::DCPS::TransportSendStrategy.

Definition at line 150 of file TcpSendStrategy.cpp.

References DBG_ENTRY_LVL.

00151 {
00152   DBG_ENTRY_LVL("TcpSendStrategy","relink",6);
00153 
00154   if (!this->connection_.is_nil()) {
00155     this->connection_->relink_from_send(do_suspend);
00156   }
00157 }

int OpenDDS::DCPS::TcpSendStrategy::reset ( TcpConnection connection,
bool  reset_mode = false 
)

This is called by the datalink object to associate with the "new" connection object. The "old" connection object is unregistered with the reactor and the "new" connection object is registered for sending. The implementation of this method is borrowed from the ReceiveStrategy.

Definition at line 71 of file TcpSendStrategy.cpp.

References OpenDDS::DCPS::RcObject< T >::_add_ref(), OpenDDS::DCPS::TransportSendStrategy::clear(), connection_, DBG_ENTRY_LVL, OpenDDS::DCPS::TransportSendStrategy::MODE_DIRECT, and OpenDDS::DCPS::TransportSendStrategy::set_graceful_disconnecting().

00072 {
00073   DBG_ENTRY_LVL("TcpSendStrategy","reset",6);
00074 
00075   // Sanity check - this connection is passed in from the constructor and
00076   // it should not be nil.
00077   if (this->connection_.is_nil()) {
00078     ACE_ERROR_RETURN((LM_ERROR,
00079                       "(%P|%t) ERROR: TcpSendStrategy::reset  previous connection "
00080                       "should not be nil.\n"),
00081                      -1);
00082   }
00083 
00084   if (this->connection_.in() == connection) {
00085     ACE_ERROR_RETURN((LM_ERROR,
00086                       "(%P|%t) ERROR: TcpSendStrategy::reset should not be called"
00087                       " to replace the same connection.\n"),
00088                      -1);
00089   }
00090 
00091   // This will cause the connection_ object to drop its reference to this
00092   // TransportSendStrategy object.
00093   this->connection_->remove_send_strategy();
00094 
00095   // Replace with a new connection.
00096   connection->_add_ref();
00097   this->connection_ = connection;
00098 
00099   // Tell the TcpConnection that we are the object that it should
00100   // call when it receives a handle_input() "event", and we will carry
00101   // it out.  The TcpConnection object will make a "copy" of the
00102   // reference (to this object) that we pass-in here.
00103   this->connection_->set_send_strategy(this);
00104 
00105   //For the case of a send_strategy being reused for a new connection (not reconnect)
00106   //need to reset the state
00107   if (reset_mode) {
00108     //Need to make sure that the send mode is set back to MODE_DIRECT in case
00109     //it was terminated prior to being reused/reset.
00110     this->clear(MODE_DIRECT);
00111     //reset graceful_disconnecting_ to initial state
00112     this->set_graceful_disconnecting(false);
00113   }
00114   return 0;
00115 }

void OpenDDS::DCPS::TcpSendStrategy::schedule_output (  )  [virtual]

Enable or disable output processing by the reactor according to mode.

Reimplemented from OpenDDS::DCPS::ThreadSynchWorker.

Definition at line 48 of file TcpSendStrategy.cpp.

References DBG_ENTRY_LVL, OpenDDS::DCPS::DCPS_debug_level, get_handle(), OpenDDS::DCPS::TransportSendStrategy::mode(), OpenDDS::DCPS::TransportSendStrategy::MODE_DIRECT, OpenDDS::DCPS::TransportSendStrategy::MODE_QUEUE, OpenDDS::DCPS::TransportSendStrategy::MODE_SUSPEND, OpenDDS::DCPS::TransportSendStrategy::synch(), and OpenDDS::DCPS::ThreadSynch::work_available().

00049 {
00050   DBG_ENTRY_LVL("TcpSendStrategy","schedule_output",6);
00051 
00052   // Notify the reactor to adjust its processing policy according to mode_.
00053   synch()->work_available();
00054 
00055   if (DCPS_debug_level > 4) {
00056     const char* action = "";
00057     if( mode() == MODE_DIRECT) {
00058       action = "canceling";
00059     } else if( (mode() == MODE_QUEUE)
00060             || (mode() == MODE_SUSPEND)) {
00061       action = "starting";
00062     }
00063     ACE_DEBUG((LM_DEBUG,
00064                ACE_TEXT("(%P|%t) TcpSendStrategy::schedule_output() [%d] - ")
00065                ACE_TEXT("%C data queueing for handle %d.\n"),
00066                id(),action,get_handle()));
00067   }
00068 }

ssize_t OpenDDS::DCPS::TcpSendStrategy::send_bytes ( const iovec  iov[],
int  n,
int &  bp 
) [protected, virtual]

Reimplemented from OpenDDS::DCPS::TransportSendStrategy.

Definition at line 118 of file TcpSendStrategy.cpp.

References DBG_ENTRY_LVL, and OpenDDS::DCPS::TransportSendStrategy::non_blocking_send().

00119 {
00120   DBG_ENTRY_LVL("TcpSendStrategy","send_bytes",6);
00121   return this->non_blocking_send(iov, n, bp);
00122 }

ssize_t OpenDDS::DCPS::TcpSendStrategy::send_bytes_i ( const iovec  iov[],
int  n 
) [protected, virtual]

Implements OpenDDS::DCPS::TransportSendStrategy.

Definition at line 136 of file TcpSendStrategy.cpp.

References connection_, OpenDDS::DCPS::DCPS_debug_level, and OpenDDS::DCPS::RcHandle< T >::is_nil().

00137 {
00138   TcpConnection_rch connection = this->connection_;
00139 
00140   if (connection.is_nil())
00141     return -1;
00142   ssize_t result = connection->peer().sendv(iov, n);
00143   if (DCPS_debug_level > 4)
00144     ACE_DEBUG((LM_DEBUG, "(%P|%t) TcpSendStrategy::send_bytes_i sent %d bytes \n", result));
00145 
00146   return result;
00147 }

void OpenDDS::DCPS::TcpSendStrategy::stop_i (  )  [protected, virtual]

Let the subclass stop.

Implements OpenDDS::DCPS::TransportSendStrategy.

Definition at line 160 of file TcpSendStrategy.cpp.

References connection_, and DBG_ENTRY_LVL.

00161 {
00162   DBG_ENTRY_LVL("TcpSendStrategy","stop_i",6);
00163 
00164   // This will cause the connection_ object to drop its reference to this
00165   // TransportSendStrategy object.
00166   this->connection_->remove_send_strategy();
00167 
00168   // Take back the "copy" of connection object given. (see constructor).
00169   this->connection_ = 0;
00170 }


Member Data Documentation

TcpConnection_rch OpenDDS::DCPS::TcpSendStrategy::connection_ [private]

Definition at line 57 of file TcpSendStrategy.h.

Referenced by get_handle(), reset(), send_bytes_i(), and stop_i().

TcpDataLink_rch OpenDDS::DCPS::TcpSendStrategy::link_ [private]

Definition at line 58 of file TcpSendStrategy.h.

TransportReactorTask_rch OpenDDS::DCPS::TcpSendStrategy::reactor_task_ [private]

Definition at line 59 of file TcpSendStrategy.h.


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:06:39 2016 for OpenDDS by  doxygen 1.4.7