Socket.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 
00038 #ifndef BLOCXX_SOCKET_HPP_INCLUDE_GUARD_
00039 #define BLOCXX_SOCKET_HPP_INCLUDE_GUARD_
00040 #include "blocxx/BLOCXX_config.h"
00041 #include "blocxx/SelectableIFC.hpp"
00042 #include "blocxx/SocketBaseImpl.hpp"
00043 #include "blocxx/String.hpp"
00044 #include "blocxx/Types.hpp"
00045 #include "blocxx/UnnamedPipe.hpp"
00046 #include "blocxx/SocketFlags.hpp"
00047 #include "blocxx/NetworkTypes.hpp"
00048 #include "blocxx/SocketAddress.hpp"
00049 #include "blocxx/IntrusiveReference.hpp"
00050 #include "blocxx/SSLCtxMgr.hpp"
00051 
00052 
00053 // TODO: This is duplicated in BLOCXX_ConfigOpts.hpp.  Figure out a way to merge the 2 without drastically increasing header dependencies.
00054 #ifdef BLOCXX_DEFAULT_HTTP_SERVER_UDS_FILENAME
00055 #define BLOCXX_DOMAIN_SOCKET_NAME BLOCXX_DEFAULT_HTTP_SERVER_UDS_FILENAME
00056 #endif
00057 
00058 #ifndef BLOCXX_DOMAIN_SOCKET_NAME
00059 #define BLOCXX_DOMAIN_SOCKET_NAME "/tmp/OW@LCL@APIIPC_72859_Xq47Bf_P9r761-5_J-7_Q"BLOCXX_PACKAGE_PREFIX
00060 #endif
00061 
00062 namespace BLOCXX_NAMESPACE
00063 {
00064 
00065 BLOCXX_DECLARE_APIEXCEPTION(SocketTimeout, BLOCXX_COMMON_API)
00066 class BLOCXX_COMMON_API Socket : public SelectableIFC, public IOIFC
00067 {
00068 public:
00072    Socket();
00077    Socket(const SSLClientCtxRef& sslCtx);
00086    Socket(SocketHandle_t fd, SocketAddress::AddressType addrType,
00087       SocketFlags::ESSLFlag isSSL = SocketFlags::E_NOT_SSL);
00095    Socket(const SocketAddress& addr, SocketFlags::ESSLFlag isSSL = SocketFlags::E_NOT_SSL);
00101    void connect(const SocketAddress& addr)
00102       { m_impl->connect(addr); }
00106    void disconnect() { m_impl->disconnect(); }
00107 
00108    static const int INFINITE_TIMEOUT = -1;
00113    void setReceiveTimeout(int seconds) { m_impl->setReceiveTimeout(seconds);}
00118    int getReceiveTimeout() const { return m_impl->getReceiveTimeout(); }
00123    void setSendTimeout(int seconds) { m_impl->setSendTimeout(seconds); }
00128    int getSendTimeout() const { return m_impl->getSendTimeout(); }
00133    void setConnectTimeout(int seconds) { m_impl->setConnectTimeout(seconds); }
00138    int getConnectTimeout() const { return m_impl->getConnectTimeout(); }
00143    void setTimeouts(int seconds) { m_impl->setTimeouts(seconds); }
00148    bool receiveTimeOutExpired() const { return m_impl->receiveTimeOutExpired(); }
00157    int write(const void* dataOut, int dataOutLen, bool errorAsException=false)
00158       { return m_impl->write(dataOut, dataOutLen, errorAsException); }
00167    int read(void* dataIn, int dataInLen, bool errorAsException=false)
00168       { return m_impl->read(dataIn, dataInLen, errorAsException); }
00175    bool waitForInput(int timeOutSecs=INFINITE_TIMEOUT)
00176       { return m_impl->waitForInput(timeOutSecs); }
00183    bool waitForOutput(int timeOutSecs=INFINITE_TIMEOUT)
00184       { return m_impl->waitForOutput(timeOutSecs); }
00185 
00190    SocketAddress getLocalAddress() const { return m_impl->getLocalAddress(); }
00195    SocketAddress getPeerAddress() const { return m_impl->getPeerAddress(); }
00199    Select_t getSelectObj() const { return m_impl->getSelectObj(); }
00204    SocketHandle_t getfd() { return m_impl->getfd(); }
00205 
00209    bool isConnected() const { return m_impl->isConnected(); }
00210 
00211    static void createShutDownMechanism();
00217    static void shutdownAllSockets();
00222    static void deleteShutDownMechanism();
00223 
00224 #if defined(BLOCXX_WIN32)
00225    typedef HANDLE ShutDownMechanism_t;
00226 #else
00227    typedef UnnamedPipeRef ShutDownMechanism_t;
00228 #endif
00229 
00230    static ShutDownMechanism_t getShutDownMechanism()
00231    {
00232       return s_shutDownMechanism;
00233    }
00234 
00235 #ifndef BLOCXX_NO_SSL
00236 
00241    SSL* getSSL() const;
00242 
00247    bool peerCertVerified() const;
00248 #endif
00249 
00250 private:
00258    Socket(SocketHandle_t fd, SocketAddress::AddressType addrType,
00259       const SSLServerCtxRef& sslCtx);
00260 
00261 #ifdef BLOCXX_WIN32
00262 #pragma warning (push)
00263 #pragma warning (disable: 4251)
00264 #endif
00265 
00266    SocketBaseImplRef m_impl;
00267 
00268 #ifdef BLOCXX_WIN32
00269 #pragma warning (pop)
00270 #endif
00271 
00272    static ShutDownMechanism_t s_shutDownMechanism;
00273 
00274    friend class ServerSocketImpl;
00275 
00276 };
00277 
00278 } // end namespace BLOCXX_NAMESPACE
00279 
00280 #endif

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