reSIProcate/stack  9694
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends
resip::InternalTransport Class Reference

#include <InternalTransport.hxx>

Inheritance diagram for resip::InternalTransport:
Inheritance graph
[legend]
Collaboration diagram for resip::InternalTransport:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 InternalTransport (Fifo< TransactionMessage > &rxFifo, int portNum, IpVersion version, const Data &interfaceObj, AfterSocketCreationFuncPtr socketFunc=0, Compression &compression=Compression::Disabled, unsigned transportFlags=0)
virtual ~InternalTransport ()
virtual bool isFinished () const
virtual bool hasDataToSend () const
 only applies to transports that shareStackProcessAndSelect
virtual bool shareStackProcessAndSelect () const
 Returns true if this Transport should be included in the FdSet processing loop, false if the Transport will provide its own cycles.
virtual void startOwnProcessing ()
 transports that returned false to shareStackProcessAndSelect() shouldn't put messages into the fifo until this is called
void bind ()
virtual void setPollGrp (FdPollGrp *grp)
virtual unsigned int getFifoSize () const
virtual void send (std::auto_ptr< SendData > data)
virtual void poke ()
 Called when a writer is done adding messages to the TxFifo; this is used to interrupt the select call if the Transport is running in its own thread.
virtual void setCongestionManager (CongestionManager *manager)

Static Public Member Functions

static Socket socket (TransportType type, IpVersion ipVer)

Protected Attributes

Socket mFd
SelectInterruptor mSelectInterruptor
FdPollItemHandle mInterruptorHandle
Fifo< SendDatamTxFifo
ConsumerFifoBuffer< SendDatamTxFifoOutBuffer
FdPollGrpmPollGrp
FdPollItemHandle mPollItemHandle

Friends

class SipStack

Detailed Description

Definition at line 30 of file InternalTransport.hxx.


Constructor & Destructor Documentation

InternalTransport::InternalTransport ( Fifo< TransactionMessage > &  rxFifo,
int  portNum,
IpVersion  version,
const Data interfaceObj,
AfterSocketCreationFuncPtr  socketFunc = 0,
Compression compression = Compression::Disabled,
unsigned  transportFlags = 0 
)

Definition at line 24 of file InternalTransport.cxx.

References INVALID_SOCKET.

                                                              :
   Transport(rxFifo, portNum, version, interfaceObj, Data::Empty,
             socketFunc, compression, transportFlags),
   mFd(INVALID_SOCKET),
   mInterruptorHandle(0),
   mTxFifoOutBuffer(mTxFifo),
   mPollGrp(NULL),
   mPollItemHandle(NULL)
{}
InternalTransport::~InternalTransport ( ) [virtual]

Definition at line 40 of file InternalTransport.cxx.

References resip::closeSocket(), resip::FdPollGrp::delPollItem(), resip::AbstractFifo< T >::empty(), INVALID_SOCKET, mFd, mInterruptorHandle, mPollGrp, mPollItemHandle, mTxFifo, resip::AbstractFifo< T >::size(), and WarningLog.

{
   if (mPollItemHandle)
      mPollGrp->delPollItem(mPollItemHandle);
   if (mInterruptorHandle)
      mPollGrp->delPollItem(mInterruptorHandle);

   if  (mFd != INVALID_SOCKET)
   {
      //DebugLog (<< "Closing " << mFd);
      closeSocket(mFd);
   }
   mFd = -2;
   if(!mTxFifo.empty())
   {
      WarningLog(<< "TX Fifo non-empty in ~InternalTransport! Has " << mTxFifo.size() << " messages.");
   }
}

Here is the call graph for this function:


Member Function Documentation

void InternalTransport::bind ( )

Definition at line 105 of file InternalTransport.cxx.

References DebugLog, ErrLog, resip::Transport::error(), resip::getErrno(), resip::Tuple::getMutableSockaddr(), resip::Tuple::getPort(), resip::Tuple::inet_ntop(), len, resip::Tuple::length(), resip::makeSocketNonBlocking(), mFd, resip::Transport::mSocketFunc, resip::Transport::mTuple, resip::Transport::port(), SOCKET_ERROR, and resip::Transport::transport().

Referenced by resip::TcpBaseTransport::init(), and resip::UdpTransport::UdpTransport().

{
   DebugLog (<< "Binding to " << Tuple::inet_ntop(mTuple));

   if ( ::bind( mFd, &mTuple.getMutableSockaddr(), mTuple.length()) == SOCKET_ERROR )
   {
      int e = getErrno();
      if ( e == EADDRINUSE )
      {
         error(e);
         ErrLog (<< mTuple << " already in use ");
         throw Transport::Exception("port already in use", __FILE__,__LINE__);
      }
      else
      {
         error(e);
         ErrLog (<< "Could not bind to " << mTuple);
         throw Transport::Exception("Could not use port", __FILE__,__LINE__);
      }
   }

   // If we bound to port 0, then query OS for assigned port number
   if(mTuple.getPort() == 0)
   {
      socklen_t len = sizeof(mTuple.getMutableSockaddr());
      if(::getsockname(mFd, &mTuple.getMutableSockaddr(), &len) == SOCKET_ERROR)
      {
         int e = getErrno();
         ErrLog (<<"getsockname failed, error=" << e);
         throw Transport::Exception("Could not query port", __FILE__,__LINE__);
      }
   }

   bool ok = makeSocketNonBlocking(mFd);
   if ( !ok )
   {
      ErrLog (<< "Could not make socket non-blocking " << port());
      throw Transport::Exception("Failed making socket non-blocking", __FILE__,__LINE__);
   }

   if (mSocketFunc)
   {
      mSocketFunc(mFd, transport(), __FILE__, __LINE__);
   }
}

Here is the call graph for this function:

unsigned int InternalTransport::getFifoSize ( ) const [virtual]

Implements resip::Transport.

Definition at line 152 of file InternalTransport.cxx.

References mTxFifo, and resip::AbstractFifo< T >::size().

{
   return mTxFifo.size();
}

Here is the call graph for this function:

bool InternalTransport::hasDataToSend ( ) const [virtual]

only applies to transports that shareStackProcessAndSelect

Implements resip::Transport.

Reimplemented in resip::UdpTransport.

Definition at line 158 of file InternalTransport.cxx.

References resip::ConsumerFifoBuffer< class >::messageAvailable(), and mTxFifoOutBuffer.

Here is the call graph for this function:

bool InternalTransport::isFinished ( ) const [virtual]
Note:
Subclasses override this method by checking whether there are unprocessed messages on the TransactionMessage Fifo (that was passed in to the constructor).

Implements resip::Transport.

Definition at line 60 of file InternalTransport.cxx.

References resip::ConsumerFifoBuffer< class >::messageAvailable(), and mTxFifoOutBuffer.

Here is the call graph for this function:

void InternalTransport::poke ( ) [virtual]

Called when a writer is done adding messages to the TxFifo; this is used to interrupt the select call if the Transport is running in its own thread.

This does nothing if select is not currently blocking, so don't bother calling this from the same thread that selects on this Transport's fds. Default impl is a no-op.

Reimplemented from resip::Transport.

Definition at line 193 of file InternalTransport.cxx.

References resip::SelectInterruptor::handleProcessNotification(), resip::ConsumerFifoBuffer< class >::messageAvailable(), mSelectInterruptor, and mTxFifoOutBuffer.

{
   // !bwc! I have tried installing mSelectInterruptor in mTxFifo, but it 
   // hampers performance. This seems to be because we get a significant 
   // performance boost from having multiple messages added to mTxFifo before 
   // mSelectInterruptor is invoked (this is what the TransactionController 
   // does; it processes at most 16 TransactionMessages, and then pokes the 
   // Transports). Once we have buffered producer queues in place, this 
   // performance concern will be rendered moot, and we'll be able to install 
   // the interruptor in mTxFifo.
   if(mTxFifoOutBuffer.messageAvailable())
   {
      // This will interrupt the select statement and cause processing of 
      // this new outgoing message.
      mSelectInterruptor.handleProcessNotification();
   }
}

Here is the call graph for this function:

void InternalTransport::send ( std::auto_ptr< SendData data) [virtual]
Todo:
!bwc! What we do with a SendData is flexible.

It might make a copy, or send synchronously, or convert to another type, etc.

Todo:
!bch! Should this be protected and not public? !bwc! TransportSelector uses this directly for retransmissions.

Implements resip::Transport.

Definition at line 164 of file InternalTransport.cxx.

References resip::Fifo< Msg >::add(), and mTxFifo.

Referenced by main(), resip::UdpTransport::processRxParse(), and Loadgen::Transceiver::send().

{
   mTxFifo.add(data.release());
}

Here is the call graph for this function:

virtual void resip::InternalTransport::setCongestionManager ( CongestionManager manager) [inline, virtual]

Reimplemented from resip::Transport.

Definition at line 70 of file InternalTransport.hxx.

References resip::Transport::mCongestionManager, mTxFifo, resip::CongestionManager::registerFifo(), and resip::CongestionManager::unregisterFifo().

Here is the call graph for this function:

void InternalTransport::setPollGrp ( FdPollGrp grp) [virtual]

Implements resip::Transport.

Reimplemented in resip::UdpTransport, and resip::TcpBaseTransport.

Definition at line 170 of file InternalTransport.cxx.

References resip::FdPollGrp::addPollItem(), resip::FdPollGrp::delPollItem(), FPEM_Read, resip::SelectInterruptor::getReadSocket(), mInterruptorHandle, mPollGrp, mSelectInterruptor, and shareStackProcessAndSelect().

{
   if(!shareStackProcessAndSelect())
   {
      // If this transport does not have its own thread, it does not need to
      // register its SelectInterruptor because the TransportSelector will take
      // care of interrupting the select()/epoll() loop when necessary.
      if(mPollGrp && mInterruptorHandle)
      {
         mPollGrp->delPollItem(mInterruptorHandle);
         mInterruptorHandle=0;
      }

      if (grp)
      {
         mInterruptorHandle = grp->addPollItem(mSelectInterruptor.getReadSocket(), FPEM_Read, &mSelectInterruptor);
      }
   }

   mPollGrp = grp;
}

Here is the call graph for this function:

virtual bool resip::InternalTransport::shareStackProcessAndSelect ( ) const [inline, virtual]

Returns true if this Transport should be included in the FdSet processing loop, false if the Transport will provide its own cycles.

If the Transport is going to provide its own cycles, the startOwnProcessing() and shutdown() will be called to tell the Transport when to process.

Return values:
truewill run in the SipStack's processing context
falseprovides own cycles, just puts messages in rxFifo

Implements resip::Transport.

Definition at line 48 of file InternalTransport.hxx.

References resip::Transport::mTransportFlags, and RESIP_TRANSPORT_FLAG_OWNTHREAD.

Referenced by resip::TcpBaseTransport::buildFdSet(), and setPollGrp().

Socket InternalTransport::socket ( TransportType  type,
IpVersion  ipVer 
) [static]

Definition at line 66 of file InternalTransport.cxx.

References DebugLog, ErrLog, resip::getErrno(), InfoLog, INVALID_SOCKET, strerror(), resip::TCP, resip::TLS, resip::Tuple::toData(), resip::UDP, and resip::V4.

Referenced by resip::TransportSelector::determineSourceInterface(), resip::TcpBaseTransport::makeOutgoingConnection(), resip::TcpBaseTransport::TcpBaseTransport(), and resip::UdpTransport::UdpTransport().

{
   Socket fd;
   switch (type)
   {
      case UDP:
#ifdef USE_IPV6
         fd = ::socket(ipVer == V4 ? PF_INET : PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
#else
         fd = ::socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
#endif
         break;
      case TCP:
      case TLS:
#ifdef USE_IPV6
         fd = ::socket(ipVer == V4 ? PF_INET : PF_INET6, SOCK_STREAM, 0);
#else
         fd = ::socket(PF_INET, SOCK_STREAM, 0);
#endif
         break;
      default:
         InfoLog (<< "Try to create an unsupported socket type: " << Tuple::toData(type));
         assert(0);
         throw Transport::Exception("Unsupported transport", __FILE__,__LINE__);
   }

   if ( fd == INVALID_SOCKET )
   {
      int e = getErrno();
      ErrLog (<< "Failed to create socket: " << strerror(e));
      throw Transport::Exception("Can't create TcpBaseTransport", __FILE__,__LINE__);
   }

   DebugLog (<< "Creating fd=" << fd << (ipVer == V4 ? " V4/" : " V6/") << (type == UDP ? "UDP" : "TCP"));

   return fd;
}

Here is the call graph for this function:

virtual void resip::InternalTransport::startOwnProcessing ( ) [inline, virtual]

transports that returned false to shareStackProcessAndSelect() shouldn't put messages into the fifo until this is called

Todo:
?dcm? avoid the received a message but haven't added a transport to the TransportSelector race, but this might not be necessary.

Implements resip::Transport.

Definition at line 54 of file InternalTransport.hxx.

{}

Friends And Related Function Documentation

friend class SipStack [friend]

Definition at line 83 of file InternalTransport.hxx.


Member Data Documentation

Definition at line 92 of file InternalTransport.hxx.

Referenced by setPollGrp(), and ~InternalTransport().

Definition at line 91 of file InternalTransport.hxx.

Referenced by resip::TcpBaseTransport::buildFdSet(), poke(), and setPollGrp().


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