00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
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()
00204 { return m_impl->getInputStream(); }
00210 std::ostream& getOutputStream()
00211 { return m_impl->getOutputStream(); }
00217 OW_DEPRECATED std::iostream& getIOStream()
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;
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 }
00302
00303 #endif