OW_Socket.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 
00036 #ifndef OW_SOCKET_HPP_INCLUDE_GUARD_
00037 #define OW_SOCKET_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_SelectableIFC.hpp"
00040 #include "OW_SocketBaseImpl.hpp"
00041 #include "OW_String.hpp"
00042 #include "OW_Types.hpp"
00043 #include "OW_UnnamedPipe.hpp"
00044 #include "OW_SocketFlags.hpp"
00045 #include "OW_NetworkTypes.hpp"
00046 #include "OW_SocketAddress.hpp"
00047 #include "OW_IntrusiveReference.hpp"
00048 #include "OW_SSLCtxMgr.hpp"
00049 
00050 
00051 // TODO: This is duplicated in OW_ConfigOpts.hpp.  Figure out a way to merge the 2 without drastically increasing header dependencies.
00052 #ifdef OW_DEFAULT_HTTP_SERVER_UDS_FILENAME
00053 #define OW_DOMAIN_SOCKET_NAME OW_DEFAULT_HTTP_SERVER_UDS_FILENAME
00054 #endif
00055 
00056 #ifndef OW_DOMAIN_SOCKET_NAME
00057 #define OW_DOMAIN_SOCKET_NAME "/tmp/OW@LCL@APIIPC_72859_Xq47Bf_P9r761-5_J-7_Q"OW_PACKAGE_PREFIX
00058 #endif
00059 
00060 namespace OW_NAMESPACE
00061 {
00062 
00063 OW_DECLARE_APIEXCEPTION(SocketTimeout, OW_COMMON_API)
00064 class OW_COMMON_API Socket : public SelectableIFC, public IOIFC
00065 {
00066 public:
00070    Socket();
00075    Socket(const SSLClientCtxRef& sslCtx);
00080    Socket(SocketFlags::ESSLFlag isSSL) OW_DEPRECATED;
00088    Socket(SocketHandle_t fd, SocketAddress::AddressType addrType,
00089       SocketFlags::ESSLFlag isSSL = SocketFlags::E_NOT_SSL);
00097    Socket(const SocketAddress& addr, SocketFlags::ESSLFlag isSSL = SocketFlags::E_NOT_SSL);
00103    void connect(const SocketAddress& addr)
00104       { m_impl->connect(addr); }
00108    void disconnect() { m_impl->disconnect(); }
00109 
00110    static const int INFINITE_TIMEOUT = -1;
00115    void setReceiveTimeout(int seconds) { m_impl->setReceiveTimeout(seconds);}
00120    int getReceiveTimeout() const { return m_impl->getReceiveTimeout(); }
00125    void setSendTimeout(int seconds) { m_impl->setSendTimeout(seconds); }
00130    int getSendTimeout() const { return m_impl->getSendTimeout(); }
00135    void setConnectTimeout(int seconds) { m_impl->setConnectTimeout(seconds); }
00140    int getConnectTimeout() const { return m_impl->getConnectTimeout(); }
00145    void setTimeouts(int seconds) { m_impl->setTimeouts(seconds); }
00150    bool receiveTimeOutExpired() const { return m_impl->receiveTimeOutExpired(); }
00159    int write(const void* dataOut, int dataOutLen, bool errorAsException=false)
00160       { return m_impl->write(dataOut, dataOutLen, errorAsException); }
00169    int read(void* dataIn, int dataInLen, bool errorAsException=false)
00170       { return m_impl->read(dataIn, dataInLen, errorAsException); }
00177    bool waitForInput(int timeOutSecs=INFINITE_TIMEOUT)
00178       { return m_impl->waitForInput(timeOutSecs); }
00185    bool waitForOutput(int timeOutSecs=INFINITE_TIMEOUT)
00186       { return m_impl->waitForOutput(timeOutSecs); }
00187 
00192    SocketAddress getLocalAddress() const { return m_impl->getLocalAddress(); }
00197    SocketAddress getPeerAddress() const { return m_impl->getPeerAddress(); }
00203    std::istream& getInputStream() // TODO: OW_DEPRECATED in 3.2.0
00204       { return m_impl->getInputStream(); }
00210    std::ostream& getOutputStream() // TODO: OW_DEPRECATED in 3.2.0
00211       { return m_impl->getOutputStream(); }
00217    OW_DEPRECATED std::iostream& getIOStream() // in 3.2.0
00218       { return m_impl->getIOStream(); }
00222    Select_t getSelectObj() const { return m_impl->getSelectObj(); }
00227    SocketHandle_t getfd() { return m_impl->getfd(); }
00228 
00232    bool isConnected() const { return m_impl->isConnected(); }
00233 
00234    static void createShutDownMechanism();
00240    static void shutdownAllSockets();
00245    static bool gotShutDown() OW_DEPRECATED; // deprecated in 3.1.0
00246    static void deleteShutDownMechanism();
00247 
00248 #if defined(OW_WIN32)
00249    typedef HANDLE ShutDownMechanism_t;
00250 #else
00251    typedef UnnamedPipeRef ShutDownMechanism_t;
00252 #endif
00253 
00254    static ShutDownMechanism_t getShutDownMechanism()
00255    {
00256       return s_shutDownMechanism;
00257    }
00258 
00259 #ifndef OW_NO_SSL
00260 
00265    SSL* getSSL() const;
00266 
00271    bool peerCertVerified() const;
00272 #endif
00273 
00274 private:
00281    Socket(SocketHandle_t fd, SocketAddress::AddressType addrType,
00282       const SSLServerCtxRef& sslCtx);
00283 
00284 #ifdef OW_WIN32
00285 #pragma warning (push)
00286 #pragma warning (disable: 4251)
00287 #endif
00288 
00289    SocketBaseImplRef m_impl;
00290 
00291 #ifdef OW_WIN32
00292 #pragma warning (pop)
00293 #endif
00294 
00295    static ShutDownMechanism_t s_shutDownMechanism;
00296 
00297    friend class ServerSocketImpl;
00298 
00299 };
00300 
00301 } // end namespace OW_NAMESPACE
00302 
00303 #endif

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