OW_SocketBaseImpl.hpp

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

Generated on Thu Feb 9 08:48:11 2006 for openwbem by  doxygen 1.4.6