blocxx

ServerSocketImpl.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2005, Vintela, Inc. All rights reserved.
00003 * Copyright (C) 2006, 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 *     * Redistributions in binary form must reproduce the above copyright
00011 *       notice, this list of conditions and the following disclaimer in the
00012 *       documentation and/or other materials provided with the distribution.
00013 *     * Neither the name of 
00014 *       Vintela, Inc., 
00015 *       nor Novell, Inc., 
00016 *       nor the names of its contributors or employees may be used to 
00017 *       endorse or promote products derived from this software without 
00018 *       specific prior written permission.
00019 * 
00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030 * POSSIBILITY OF SUCH DAMAGE.
00031 *******************************************************************************/
00032 
00033 
00042 #ifndef BLOCXX_INETSERVERSOCKETIMPL_HPP_INCLUDE_GUARD_
00043 #define BLOCXX_INETSERVERSOCKETIMPL_HPP_INCLUDE_GUARD_
00044 #include "blocxx/BLOCXX_config.h"
00045 #include "blocxx/SelectableIFC.hpp"
00046 #include "blocxx/Socket.hpp"
00047 #include "blocxx/SocketAddress.hpp"
00048 #include "blocxx/Types.hpp"
00049 #include "blocxx/File.hpp"
00050 #include "blocxx/SocketFlags.hpp"
00051 #include "blocxx/IntrusiveCountableBase.hpp"
00052 #include "blocxx/SSLCtxMgr.hpp"
00053 
00054 // The classes and functions defined in this file are not meant for general
00055 // use, they are internal implementation details.  They may change at any time.
00056 
00057 namespace BLOCXX_NAMESPACE
00058 {
00059 
00060 class BLOCXX_COMMON_API ServerSocketImpl : public SelectableIFC
00061 {
00062 public:
00063    ServerSocketImpl(SSLServerCtxRef sslCtx); 
00064    ServerSocketImpl(SocketFlags::ESSLFlag isSSL);
00065    ~ServerSocketImpl();
00066    String addrString();
00067    Socket accept(const Timeout& timeout);
00068    void close();
00069 // unsigned long getLocalAddressRaw() { return m_localAddress; }
00070 // unsigned short getLocalPortRaw() { return m_localPort; }
00071    SocketAddress getLocalAddress() { return m_localAddress; }
00072    SocketHandle_t getfd() const { return m_sockfd; }
00073 
00074 
00075    // this is deprecated, but we don't mark it so here because it's and impl.
00076    void doListen(UInt16 port, SocketFlags::ESSLFlag isSSL, int queueSize=10,
00077       const String& listenAddr = SocketAddress::ALL_LOCAL_ADDRESSES,
00078       SocketFlags::EReuseAddrFlag reuseAddr = SocketFlags::E_REUSE_ADDR);
00079 
00080    // listen for IPv4 protocol
00081    void doListenIPv4(UInt16 port, int queueSize, const String& listenAddr);
00082 #ifdef BLOCXX_HAVE_IPV6
00083    // listen for IPv6 protocol
00084    void doListenIPv6(UInt16 port, int queueSize, const String& listenAddr);
00085 #endif
00086    void doListen(UInt16 port, int queueSize=10,
00087       const String& listenAddr = SocketAddress::ALL_LOCAL_ADDRESSES,
00088       SocketFlags::EReuseAddrFlag reuseAddr = SocketFlags::E_REUSE_ADDR);
00089 
00090 #ifndef BLOCXX_WIN32
00091    void doListenUDS(const String& filename, int queueSize=10,
00092       bool reuseAddr = true);
00093 #endif
00094 
00095    Select_t getSelectObj() const;
00096 private:
00097    void fillAddrParms();
00098    SocketHandle_t m_sockfd;
00099 // unsigned long m_localAddress;
00100 // unsigned short m_localPort;
00101    SocketAddress m_localAddress;
00102    bool m_isActive;
00103    ServerSocketImpl(const ServerSocketImpl& arg);
00104    ServerSocketImpl& operator=(const ServerSocketImpl& arg);
00105    SocketFlags::ESSLFlag m_isSSL;
00106 
00107 #ifdef BLOCXX_WIN32
00108 #pragma warning (push)
00109 #pragma warning (disable: 4251)
00110 #endif
00111 
00112    SSLServerCtxRef m_sslCtx; 
00113 #if defined(BLOCXX_WIN32)
00114 #pragma warning (pop)
00115    HANDLE m_event;
00116    bool m_shuttingDown;
00117 #else
00118    File m_udsFile;
00119 #endif
00120 };
00121 
00122 } // end namespace BLOCXX_NAMESPACE
00123 
00124 #endif