|
reSIProcate/stack
9694
|
#include <InternalTransport.hxx>


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< SendData > | mTxFifo |
| ConsumerFifoBuffer< SendData > | mTxFifoOutBuffer |
| FdPollGrp * | mPollGrp |
| FdPollItemHandle | mPollItemHandle |
Friends | |
| class | SipStack |
Definition at line 30 of file InternalTransport.hxx.
| 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.");
}
}

| 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__);
}
}

| unsigned int InternalTransport::getFifoSize | ( | ) | const [virtual] |
Implements resip::Transport.
Definition at line 152 of file InternalTransport.cxx.
References mTxFifo, and resip::AbstractFifo< T >::size().

| 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.
{
return mTxFifoOutBuffer.messageAvailable();
}

| bool InternalTransport::isFinished | ( | ) | const [virtual] |
Implements resip::Transport.
Definition at line 60 of file InternalTransport.cxx.
References resip::ConsumerFifoBuffer< class >::messageAvailable(), and mTxFifoOutBuffer.
{
return !mTxFifoOutBuffer.messageAvailable();
}

| 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();
}
}

| void InternalTransport::send | ( | std::auto_ptr< SendData > | data | ) | [virtual] |
It might make a copy, or send synchronously, or convert to another type, etc.
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().

| 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().
{
if(mCongestionManager)
{
mCongestionManager->unregisterFifo(&mTxFifo);
}
Transport::setCongestionManager(manager);
if(mCongestionManager)
{
mCongestionManager->registerFifo(&mTxFifo);
}
}

| 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;
}

| 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.
| true | will run in the SipStack's processing context |
| false | provides 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().
{ return !(mTransportFlags & RESIP_TRANSPORT_FLAG_OWNTHREAD); }
| 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;
}

| virtual void resip::InternalTransport::startOwnProcessing | ( | ) | [inline, virtual] |
transports that returned false to shareStackProcessAndSelect() shouldn't put messages into the fifo until this is called
Implements resip::Transport.
Definition at line 54 of file InternalTransport.hxx.
{}
friend class SipStack [friend] |
Definition at line 83 of file InternalTransport.hxx.
Socket resip::InternalTransport::mFd [protected] |
Definition at line 85 of file InternalTransport.hxx.
Referenced by bind(), resip::TcpBaseTransport::buildFdSet(), resip::UdpTransport::buildFdSet(), resip::TcpBaseTransport::init(), resip::TcpBaseTransport::process(), resip::UdpTransport::process(), resip::TcpBaseTransport::processListen(), resip::UdpTransport::processRxRecv(), resip::UdpTransport::processTxOne(), resip::TcpBaseTransport::setPollGrp(), resip::UdpTransport::setPollGrp(), resip::UdpTransport::setRcvBufLen(), resip::TcpBaseTransport::TcpBaseTransport(), resip::UdpTransport::UdpTransport(), and ~InternalTransport().
Definition at line 92 of file InternalTransport.hxx.
Referenced by setPollGrp(), and ~InternalTransport().
FdPollGrp* resip::InternalTransport::mPollGrp [protected] |
Definition at line 96 of file InternalTransport.hxx.
Referenced by resip::TcpBaseTransport::buildFdSet(), resip::TcpBaseTransport::process(), resip::UdpTransport::process(), resip::TcpBaseTransport::setPollGrp(), setPollGrp(), resip::UdpTransport::setPollGrp(), resip::UdpTransport::updateEvents(), ~InternalTransport(), resip::TcpBaseTransport::~TcpBaseTransport(), and resip::UdpTransport::~UdpTransport().
Definition at line 98 of file InternalTransport.hxx.
Referenced by resip::TcpBaseTransport::setPollGrp(), resip::UdpTransport::setPollGrp(), resip::UdpTransport::updateEvents(), ~InternalTransport(), and resip::TcpBaseTransport::~TcpBaseTransport().
Definition at line 91 of file InternalTransport.hxx.
Referenced by resip::TcpBaseTransport::buildFdSet(), poke(), and setPollGrp().
Fifo<SendData> resip::InternalTransport::mTxFifo [protected] |
Definition at line 94 of file InternalTransport.hxx.
Referenced by getFifoSize(), resip::UdpTransport::processRxParse(), send(), setCongestionManager(), resip::UdpTransport::stunSendTest(), resip::TcpTransport::TcpTransport(), resip::UdpTransport::UdpTransport(), and ~InternalTransport().
Definition at line 95 of file InternalTransport.hxx.
Referenced by resip::UdpTransport::buildFdSet(), hasDataToSend(), isFinished(), poke(), resip::TcpBaseTransport::processAllWriteRequests(), resip::UdpTransport::processTxAll(), resip::UdpTransport::updateEvents(), and resip::TcpBaseTransport::~TcpBaseTransport().
1.7.5.1