reSIProcate/stack  9694
InternalTransport.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_INTERNAL_TRANSPORT_HXX)
00002 #define RESIP_INTERNAL_TRANSPORT_HXX
00003 
00004 #include <exception>
00005 
00006 #include "rutil/BaseException.hxx"
00007 #include "rutil/ConsumerFifoBuffer.hxx"
00008 #include "rutil/Data.hxx"
00009 #include "rutil/Fifo.hxx"
00010 #include "rutil/Socket.hxx"
00011 #include "rutil/FdPoll.hxx"
00012 #include "resip/stack/Message.hxx"
00013 #include "resip/stack/Transport.hxx"
00014 #include "resip/stack/Tuple.hxx"
00015 #include "resip/stack/SendData.hxx"
00016 #include "resip/stack/Compression.hxx"
00017 #include "rutil/SelectInterruptor.hxx"
00018 
00019 namespace resip
00020 {
00021 
00022 class TransactionMessage;
00023 class SipMessage;
00024 class Connection;
00025 class FdPollGrp;
00026 
00030 class InternalTransport : public Transport
00031 {
00032    public:
00033       // sendHost what to put in the Via:sent-by
00034       // portNum is the port to receive and/or send on
00035       InternalTransport(Fifo<TransactionMessage>& rxFifo,
00036                         int portNum,
00037                         IpVersion version,
00038                         const Data& interfaceObj,
00039                         AfterSocketCreationFuncPtr socketFunc = 0,
00040                         Compression &compression = Compression::Disabled,
00041                         unsigned transportFlags = 0);
00042 
00043       virtual ~InternalTransport();
00044 
00045       virtual bool isFinished() const;
00046       virtual bool hasDataToSend() const;
00047 
00048       virtual bool shareStackProcessAndSelect() const 
00049       { return !(mTransportFlags & RESIP_TRANSPORT_FLAG_OWNTHREAD); }
00050 
00051       // No-op, even if this Transport is marked as having its own thread. It is the
00052       // responsibility of the app-writer to ensure that a TransportThread is 
00053       // created for this Transport, and run it.
00054       virtual void startOwnProcessing() {}
00055 
00056       // shared by UDP, TCP, and TLS
00057       static Socket socket(TransportType type, IpVersion ipVer);
00058       void bind();
00059 
00060       //used for epoll
00061       virtual void setPollGrp(FdPollGrp *grp);
00062 
00063       // used for statistics
00064       virtual unsigned int getFifoSize() const;
00065       virtual void send(std::auto_ptr<SendData> data);
00066       virtual void poke();
00067       
00068       // .bwc. This needs to be overridden if this transport runs in its own
00069       // thread to be threadsafe.
00070       virtual void setCongestionManager(CongestionManager* manager)
00071       {
00072          if(mCongestionManager)
00073          {
00074             mCongestionManager->unregisterFifo(&mTxFifo);
00075          }
00076          Transport::setCongestionManager(manager);
00077          if(mCongestionManager)
00078          {
00079             mCongestionManager->registerFifo(&mTxFifo);
00080          }
00081       }
00082    protected:
00083       friend class SipStack;
00084 
00085       Socket mFd; // this is a unix file descriptor or a windows SOCKET
00086 
00087       // .bwc. We use this to interrupt the select call when our tx fifo goes
00088       // from empty to non-empty; if the fifo is empty when we build our fd set, 
00089       // we will add the read end of this pipe to the fd set, and when a message
00090       // is added, we will write something to the write end.
00091       SelectInterruptor mSelectInterruptor;
00092       FdPollItemHandle mInterruptorHandle;
00093 
00094       Fifo<SendData> mTxFifo; // owned by the transport
00095       ConsumerFifoBuffer<SendData> mTxFifoOutBuffer;
00096       FdPollGrp *mPollGrp;      // not owned by transport, just used
00097       // FdPollItemIf *mPollItem;       // owned by the transport
00098       FdPollItemHandle mPollItemHandle; // owned by the transport
00099 };
00100 
00101 
00102 }
00103 
00104 #endif
00105 
00106 /* ====================================================================
00107  * The Vovida Software License, Version 1.0
00108  *
00109  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00110  *
00111  * Redistribution and use in source and binary forms, with or without
00112  * modification, are permitted provided that the following conditions
00113  * are met:
00114  *
00115  * 1. Redistributions of source code must retain the above copyright
00116  *    notice, this list of conditions and the following disclaimer.
00117  *
00118  * 2. Redistributions in binary form must reproduce the above copyright
00119  *    notice, this list of conditions and the following disclaimer in
00120  *    the documentation and/or other materials provided with the
00121  *    distribution.
00122  *
00123  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00124  *    and "Vovida Open Communication Application Library (VOCAL)" must
00125  *    not be used to endorse or promote products derived from this
00126  *    software without prior written permission. For written
00127  *    permission, please contact vocal@vovida.org.
00128  *
00129  * 4. Products derived from this software may not be called "VOCAL", nor
00130  *    may "VOCAL" appear in their name, without prior written
00131  *    permission of Vovida Networks, Inc.
00132  *
00133  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00134  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00135  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00136  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00137  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00138  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00139  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00140  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00141  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00142  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00144  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00145  * DAMAGE.
00146  *
00147  * ====================================================================
00148  *
00149  * This software consists of voluntary contributions made by Vovida
00150  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00151  * Inc.  For more information on Vovida Networks, Inc., please see
00152  * <http://www.vovida.org/>.
00153  *
00154  * vi: set shiftwidth=3 expandtab:
00155  */