|
reSIProcate/stack
9694
|
00001 #if !defined(RESIP_UDPTRANSPORT_HXX) 00002 #define RESIP_UDPTRANSPORT_HXX 00003 00004 #include <memory> 00005 #include "resip/stack/InternalTransport.hxx" 00006 #include "resip/stack/MsgHeaderScanner.hxx" 00007 #include "rutil/HeapInstanceCounter.hxx" 00008 #include "resip/stack/Compression.hxx" 00009 00010 namespace osc { class Stack; } 00011 00012 namespace resip 00013 { 00014 class UdpTransport; 00015 00020 class ExternalUnknownDatagramHandler { 00021 public: 00022 virtual ~ExternalUnknownDatagramHandler(){}; 00023 00028 virtual void operator()(UdpTransport* transport, const Tuple& source, std::auto_ptr<Data> unknownDatagram) = 0; 00029 }; 00030 00040 class UdpTransport : public InternalTransport, public FdPollItemIf 00041 { 00042 public: 00043 RESIP_HeapCount(UdpTransport); 00059 UdpTransport(Fifo<TransactionMessage>& fifo, 00060 int portNum, 00061 IpVersion version, 00062 StunSetting stun, 00063 const Data& interfaceObj, 00064 AfterSocketCreationFuncPtr socketFunc = 0, 00065 Compression &compression = Compression::Disabled, 00066 unsigned transportFlags = 0); 00067 virtual ~UdpTransport(); 00068 00069 virtual TransportType transport() const { return UDP; } 00070 virtual bool isReliable() const { return false; } 00071 virtual bool isDatagram() const { return true; } 00072 00073 virtual void process(FdSet& fdset); 00074 virtual void process(); 00075 virtual bool hasDataToSend() const; 00076 virtual void buildFdSet( FdSet& fdset); 00077 virtual void setPollGrp(FdPollGrp *grp); 00078 virtual void setRcvBufLen(int buflen); 00079 00080 // FdPollItemIf 00081 // virtual Socket getPollSocket() const; 00082 virtual void processPollEvent(FdPollEventMask mask); 00083 00084 static const int MaxBufferSize = 8192; 00085 00086 // STUN client functionality 00087 bool stunSendTest(const Tuple& dest); 00088 bool stunResult(Tuple& mappedAddress); 00089 00091 void setExternalUnknownDatagramHandler(ExternalUnknownDatagramHandler *handler); 00092 00093 protected: 00094 00095 void processRxAll(); 00096 int processRxRecv(char*& buffer, Tuple& sender); 00097 bool processRxParse(char *buffer, int len, Tuple& sender); 00098 void processTxAll(); 00099 void processTxOne(SendData *data); 00100 void updateEvents(); 00101 00102 osc::Stack *mSigcompStack; 00103 00104 // statistics 00105 unsigned mPollEventCnt; 00106 unsigned mTxTryCnt; 00107 unsigned mTxMsgCnt; 00108 unsigned mTxFailCnt; 00109 unsigned mRxTryCnt; 00110 unsigned mRxMsgCnt; 00111 unsigned mRxKeepaliveCnt; 00112 unsigned mRxTransactionCnt; 00113 private: 00114 char* mRxBuffer; 00115 MsgHeaderScanner mMsgHeaderScanner; 00116 mutable resip::Mutex myMutex; 00117 Tuple mStunMappedAddress; 00118 bool mStunSuccess; 00119 ExternalUnknownDatagramHandler* mExternalUnknownDatagramHandler; 00120 bool mInWritable; 00121 bool mInActiveWrite; 00122 }; 00123 00124 } 00125 00126 #endif 00127 00128 /* ==================================================================== 00129 * The Vovida Software License, Version 1.0 00130 * 00131 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00132 * 00133 * Redistribution and use in source and binary forms, with or without 00134 * modification, are permitted provided that the following conditions 00135 * are met: 00136 * 00137 * 1. Redistributions of source code must retain the above copyright 00138 * notice, this list of conditions and the following disclaimer. 00139 * 00140 * 2. Redistributions in binary form must reproduce the above copyright 00141 * notice, this list of conditions and the following disclaimer in 00142 * the documentation and/or other materials provided with the 00143 * distribution. 00144 * 00145 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00146 * and "Vovida Open Communication Application Library (VOCAL)" must 00147 * not be used to endorse or promote products derived from this 00148 * software without prior written permission. For written 00149 * permission, please contact vocal@vovida.org. 00150 * 00151 * 4. Products derived from this software may not be called "VOCAL", nor 00152 * may "VOCAL" appear in their name, without prior written 00153 * permission of Vovida Networks, Inc. 00154 * 00155 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00156 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00157 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00158 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00159 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00160 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00161 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00162 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00163 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00164 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00165 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00166 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00167 * DAMAGE. 00168 * 00169 * ==================================================================== 00170 * 00171 * This software consists of voluntary contributions made by Vovida 00172 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00173 * Inc. For more information on Vovida Networks, Inc., please see 00174 * <http://www.vovida.org/>. 00175 * 00176 * vi: set shiftwidth=3 expandtab: 00177 */
1.7.5.1