reSIProcate/stack  9694
Connection.hxx
Go to the documentation of this file.
00001 #ifndef RESIP_Connection_hxx
00002 #define RESIP_Connection_hxx
00003 
00004 #include <list>
00005 
00006 #include "resip/stack/ConnectionBase.hxx"
00007 //#include "rutil/Fifo.hxx"
00008 #include "rutil/Socket.hxx"
00009 #include "rutil/FdPoll.hxx"
00010 #include "rutil/Timer.hxx"
00011 #include "resip/stack/Transport.hxx"
00012 #include "resip/stack/MsgHeaderScanner.hxx"
00013 #include "rutil/IntrusiveListElement.hxx"
00014 
00015 namespace resip
00016 {
00017 
00018 class Message;
00019 class TlsConnection;
00020 class ConnectionManager;
00021 class Connection;
00022 class Compression;
00023 
00025 typedef IntrusiveListElement<Connection*> ConnectionLruList;
00026 typedef IntrusiveListElement1<Connection*> ConnectionReadList;
00027 typedef IntrusiveListElement2<Connection*> ConnectionWriteList;
00028 typedef IntrusiveListElement3<Connection*> FlowTimerLruList;
00029 
00035 class Connection : public ConnectionBase, 
00036                    public ConnectionLruList, 
00037                    public ConnectionReadList, 
00038                    public ConnectionWriteList, 
00039                    public FlowTimerLruList, 
00040                    public FdPollItemIf
00041 {
00042       friend class ConnectionManager;
00043       friend EncodeStream& operator<<(EncodeStream& strm, const resip::Connection& c);
00044 
00045    public:
00046       Connection(Transport* transport,const Tuple& who, Socket socket, Compression &compression);
00047       virtual ~Connection();
00048       
00056       Socket getSocket() const {return mWho.mFlowKey;}
00057 
00059       virtual bool hasDataToRead();
00061       virtual bool isGood(); 
00062       virtual bool isWritable();
00063       virtual bool transportWrite(){return false;}
00064 
00066       void requestWrite(SendData* sendData);
00067 
00069       int performWrite();
00070 
00079       bool performWrites(unsigned int max=0);
00080 
00082       void ensureWritable();
00083 
00088       int read();
00089 
00096       bool performReads(unsigned int max=0);
00097 
00099       void enableFlowTimer();
00100       bool isFlowTimerEnabled() { return mFlowTimerEnabled; }
00101 
00102       bool mRequestPostConnectSocketFuncCall;
00103       static volatile bool mEnablePostConnectSocketFuncCall;
00104       static void setEnablePostConnectSocketFuncCall(bool enabled = true) { mEnablePostConnectSocketFuncCall = enabled; }
00105 
00106    protected:
00108       virtual int read(char* /* buffer */, const int /* count */) { return 0; }
00110       virtual int write(const char* /* buffer */, const int /* count */) { return 0; }
00111       virtual void onDoubleCRLF();
00112       virtual void onSingleCRLF();
00113 
00114       /* callback method of FdPollItemIf */
00115       virtual void processPollEvent(FdPollEventMask mask);
00116 
00117    private:
00118       ConnectionManager& getConnectionManager() const;
00119       void removeFrontOutstandingSend();
00120       bool mInWritable;
00121       bool mFlowTimerEnabled;
00122       FdPollItemHandle mPollItemHandle;
00123       
00125       Connection();
00126 
00128       Connection(const Connection&);
00129       Connection& operator=(const Connection&);
00130 };
00131 
00132 EncodeStream& 
00133 operator<<(EncodeStream& strm, const resip::Connection& c);
00134 
00135 }
00136 
00137 #endif
00138 /* ====================================================================
00139  * The Vovida Software License, Version 1.0 
00140  * 
00141  * Copyright (c) 2000
00142  * 
00143  * Redistribution and use in source and binary forms, with or without
00144  * modification, are permitted provided that the following conditions
00145  * are met:
00146  * 
00147  * 1. Redistributions of source code must retain the above copyright
00148  *    notice, this list of conditions and the following disclaimer.
00149  * 
00150  * 2. Redistributions in binary form must reproduce the above copyright
00151  *    notice, this list of conditions and the following disclaimer in
00152  *    the documentation and/or other materials provided with the
00153  *    distribution.
00154  * 
00155  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00156  *    and "Vovida Open Communication Application Library (VOCAL)" must
00157  *    not be used to endorse or promote products derived from this
00158  *    software without prior written permission. For written
00159  *    permission, please contact vocal@vovida.org.
00160  *
00161  * 4. Products derived from this software may not be called "VOCAL", nor
00162  *    may "VOCAL" appear in their name, without prior written
00163  *    permission of Vovida Networks, Inc.
00164  * 
00165  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00166  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00167  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00168  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00169  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00170  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00171  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00172  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00173  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00174  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00175  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00176  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00177  * DAMAGE.
00178  * 
00179  * ====================================================================
00180  * 
00181  * This software consists of voluntary contributions made by Vovida
00182  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00183  * Inc.  For more information on Vovida Networks, Inc., please see
00184  * <http://www.vovida.org/>.
00185  *
00186  */