SocketBaseImpl.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Vintela, Inc. All rights reserved.
00003 * Copyright (C) 2005 Novell, Inc. All rights reserved.
00004 *
00005 * Redistribution and use in source and binary forms, with or without
00006 * modification, are permitted provided that the following conditions are met:
00007 *
00008 *  - Redistributions of source code must retain the above copyright notice,
00009 *    this list of conditions and the following disclaimer.
00010 *
00011 *  - Redistributions in binary form must reproduce the above copyright notice,
00012 *    this list of conditions and the following disclaimer in the documentation
00013 *    and/or other materials provided with the distribution.
00014 *
00015 *  - Neither the name of Vintela, Inc., Novell, Inc., nor the names of its
00016 *    contributors may be used to endorse or promote products derived from this
00017 *    software without specific prior written permission.
00018 *
00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc., Novell, Inc., OR THE 
00023 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00026 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00027 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00028 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00029 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 *******************************************************************************/
00031 
00032 
00041 #ifndef BLOCXX_SOCKETBASEIMPL_HPP_INCLUDE_GUARD_
00042 #define BLOCXX_SOCKETBASEIMPL_HPP_INCLUDE_GUARD_
00043 #include "blocxx/BLOCXX_config.h"
00044 #include "blocxx/SelectableIFC.hpp"
00045 #include "blocxx/IntrusiveReference.hpp"
00046 #include "blocxx/SocketException.hpp"
00047 #include "blocxx/String.hpp"
00048 #include "blocxx/SocketAddress.hpp"
00049 #include "blocxx/Types.hpp"
00050 #include "blocxx/SocketStreamBuffer.hpp"
00051 #include "blocxx/IOIFC.hpp"
00052 #if defined(BLOCXX_HAVE_ISTREAM) && defined(BLOCXX_HAVE_OSTREAM)
00053 #include <istream>
00054 #include <ostream>
00055 #else
00056 #include <iostream>
00057 #endif
00058 
00059 // The classes and functions defined in this file are not meant for general
00060 // use, they are internal implementation details.  They may change at any time.
00061 
00062 namespace BLOCXX_NAMESPACE
00063 {
00064 
00065 class BLOCXX_COMMON_API SocketBaseImpl : public SelectableIFC, public IOIFC
00066 {
00067 public:
00068    SocketBaseImpl();
00069    SocketBaseImpl(SocketHandle_t fd, SocketAddress::AddressType addrType);
00070    SocketBaseImpl(const SocketAddress& addr);
00071    virtual ~SocketBaseImpl();
00072    virtual void connect(const SocketAddress& addr);
00073    virtual void disconnect();
00074    void setReceiveTimeout(int seconds) { m_recvTimeout = seconds; }
00075    int getReceiveTimeout() const { return m_recvTimeout; }
00076    void setSendTimeout(int seconds) { m_sendTimeout = seconds; }
00077    int getSendTimeout() const { return m_sendTimeout; }
00078    void setConnectTimeout(int seconds) { m_connectTimeout = seconds; }
00079    int getConnectTimeout() const { return m_connectTimeout; }
00080    void setTimeouts(int seconds) { m_recvTimeout = m_sendTimeout = m_connectTimeout = seconds; }
00081    bool receiveTimeOutExpired() const { return m_recvTimeoutExprd; }
00082    int write(const void* dataOut, int dataOutLen,
00083          bool errorAsException=false);
00084    int read(void* dataIn, int dataInLen,
00085          bool errorAsException=false);
00086    virtual bool waitForInput(int timeOutSecs=-1);
00087    bool waitForOutput(int timeOutSecs=-1);
00088    std::istream& getInputStream();
00089    std::ostream& getOutputStream();
00090    std::iostream& getIOStream();
00091    SocketAddress getLocalAddress() const { return m_localAddress; }
00092    SocketAddress getPeerAddress() const { return m_peerAddress; }
00093    SocketHandle_t getfd() const { return m_sockfd; }
00094    Select_t getSelectObj() const;
00095    bool isConnected() const { return m_isConnected; }
00096    static void setDumpFiles(const String& in, const String& out);
00097 protected:
00098    virtual int readAux(void* dataIn, int dataInLen) = 0;
00099    virtual int writeAux(const void* dataOut, int dataOutLen) = 0;
00100 
00101    bool m_isConnected;
00102    SocketHandle_t m_sockfd;
00103    SocketAddress m_localAddress;
00104    SocketAddress m_peerAddress;
00105 #if defined(BLOCXX_WIN32)
00106    HANDLE m_event;
00107 #endif
00108 
00109 private:
00110    void fillInetAddrParms();
00111 #if !defined(BLOCXX_WIN32)
00112    void fillUnixAddrParms();
00113 #endif
00114    SocketBaseImpl(const SocketBaseImpl& arg);
00115    SocketBaseImpl& operator= (const SocketBaseImpl& arg);
00116 #if defined(BLOCXX_WIN32)
00117    static int waitForEvent(HANDLE event, int secsToTimeout=-1);
00118 #endif
00119 
00120    bool m_recvTimeoutExprd;
00121    SocketStreamBuffer m_streamBuf;
00122    std::istream m_in;
00123    std::ostream m_out;
00124    std::iostream m_inout;
00125    int m_recvTimeout;
00126    int m_sendTimeout;
00127    int m_connectTimeout;
00128    
00129    static String m_traceFileOut;
00130    static String m_traceFileIn;
00131 };
00132 BLOCXX_EXPORT_TEMPLATE(BLOCXX_COMMON_API, IntrusiveReference, SocketBaseImpl);
00133 
00134 } // end namespace BLOCXX_NAMESPACE
00135 
00136 #endif

Generated on Fri Jun 16 15:39:09 2006 for blocxx by  doxygen 1.4.6