|
reSIProcate/stack
9694
|
00001 #ifndef RESIP_ConnectionBase_hxx 00002 #define RESIP_ConnectionBase_hxx 00003 00004 #include <deque> 00005 #include <list> 00006 00007 #include "rutil/Timer.hxx" 00008 // #include "rutil/Fifo.hxx" 00009 #include "resip/stack/Transport.hxx" 00010 #include "resip/stack/MsgHeaderScanner.hxx" 00011 #include "resip/stack/SendData.hxx" 00012 00013 namespace osc 00014 { 00015 class Stack; 00016 class TcpStream; 00017 } 00018 00019 namespace resip 00020 { 00021 00022 class TransactionMessage; 00023 class Compression; 00024 00035 class ConnectionBase 00036 { 00037 friend EncodeStream& operator<<(EncodeStream& strm, const resip::ConnectionBase& c); 00038 public: 00039 ConnectionBase(Transport* transport, 00040 const Tuple& who, 00041 Compression &compression = Compression::Disabled); 00042 FlowKey getFlowKey() const; 00043 00045 virtual Transport* transport() const; 00046 00047 Tuple& who() { return mWho; } 00048 const UInt64& whenLastUsed() { return mLastUsed; } 00049 void resetLastUsed() { mLastUsed = Timer::getTimeMs(); } 00050 00051 enum { ChunkSize = 2048 }; // !jf! what is the optimal size here? 00052 00053 protected: 00054 enum ConnState 00055 { 00056 NewMessage = 0, 00057 ReadingHeaders, 00058 PartialBody, 00059 SigComp, // This indicates that incoming bytes are compressed. 00060 MAX 00061 }; 00062 00063 typedef enum 00064 { 00065 Unknown, 00066 Uncompressed, 00067 Compressed 00068 } TransmissionFormat; 00069 00070 ConnState getCurrentState() const { return mConnState; } 00071 bool preparseNewBytes(int bytesRead); 00072 void decompressNewBytes(int bytesRead); 00073 std::pair<char*, size_t> getWriteBuffer(); 00074 std::pair<char*, size_t> getCurrentWriteBuffer(); 00075 char* getWriteBufferForExtraBytes(int extraBytes); 00076 00077 // for avoiding copies in external transports--not used in core resip 00078 void setBuffer(char* bytes, int count); 00079 00080 Data::size_type mSendPos; 00081 std::list<SendData*> mOutstandingSends; // !jacob! intrusive queue? 00082 00083 void setFailureReason(TransportFailure::FailureReason failReason, int subCode); 00084 00085 virtual ~ConnectionBase(); 00086 // no value semantics 00087 private: 00088 ConnectionBase(); 00089 ConnectionBase(const Connection&); 00090 ConnectionBase& operator=(const Connection&); 00091 protected: 00092 virtual void onDoubleCRLF(){} 00093 virtual void onSingleCRLF(){} 00094 Transport* mTransport; 00095 Tuple mWho; 00096 TransportFailure::FailureReason mFailureReason; 00097 int mFailureSubCode; 00098 Compression &mCompression; 00099 osc::Stack *mSigcompStack; 00100 osc::TcpStream *mSigcompFramer; 00101 TransmissionFormat mSendingTransmissionFormat; 00102 TransmissionFormat mReceivingTransmissionFormat; 00103 00104 private: 00105 SipMessage* mMessage; 00106 char* mBuffer; 00107 size_t mBufferPos; 00108 size_t mBufferSize; 00109 00110 static char connectionStates[MAX][32]; 00111 UInt64 mLastUsed; 00112 ConnState mConnState; 00113 MsgHeaderScanner mMsgHeaderScanner; 00114 }; 00115 00116 EncodeStream& 00117 operator<<(EncodeStream& strm, const resip::ConnectionBase& c); 00118 00119 } 00120 00121 #endif 00122 /* ==================================================================== 00123 * The Vovida Software License, Version 1.0 00124 * 00125 * Copyright (c) 2000 00126 * 00127 * Redistribution and use in source and binary forms, with or without 00128 * modification, are permitted provided that the following conditions 00129 * are met: 00130 * 00131 * 1. Redistributions of source code must retain the above copyright 00132 * notice, this list of conditions and the following disclaimer. 00133 * 00134 * 2. Redistributions in binary form must reproduce the above copyright 00135 * notice, this list of conditions and the following disclaimer in 00136 * the documentation and/or other materials provided with the 00137 * distribution. 00138 * 00139 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00140 * and "Vovida Open Communication Application Library (VOCAL)" must 00141 * not be used to endorse or promote products derived from this 00142 * software without prior written permission. For written 00143 * permission, please contact vocal@vovida.org. 00144 * 00145 * 4. Products derived from this software may not be called "VOCAL", nor 00146 * may "VOCAL" appear in their name, without prior written 00147 * permission of Vovida Networks, Inc. 00148 * 00149 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00150 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00151 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00152 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00153 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00154 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00155 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00156 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00157 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00158 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00159 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00160 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00161 * DAMAGE. 00162 * 00163 * ==================================================================== 00164 * 00165 * This software consists of voluntary contributions made by Vovida 00166 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00167 * Inc. For more information on Vovida Networks, Inc., please see 00168 * <http://www.vovida.org/>. 00169 * 00170 */
1.7.5.1