|
blocxx
|
#include <Socket.hpp>
Classes | |
| struct | ShutDownMechanismFactory |
Public Types | |
| typedef UnnamedPipeRef | ShutDownMechanism_t |
Public Types inherited from BLOCXX_NAMESPACE::IOIFC | |
| enum | ErrorAction { E_THROW_ON_ERROR , E_RETURN_ON_ERROR } |
Public Member Functions | |
| Socket () | |
| Construct a non-SSL Socket. | |
| Socket (const SSLClientCtxRef &sslCtx) | |
| Construct a Socket. | |
| Socket (SocketFlags::ESSLFlag isSSL) BLOCXX_DEPRECATED | |
| Allocate a new Socket. | |
| Socket (SocketHandle_t fd, SocketAddress::AddressType addrType, SocketFlags::ESSLFlag isSSL=SocketFlags::E_NOT_SSL) | |
| TODO: Make a replacement for this function so it can be deprecated. | |
| Socket (const SocketAddress &addr, SocketFlags::ESSLFlag isSSL=SocketFlags::E_NOT_SSL) | |
| TODO: Make a replacement for this function so it can be deprecated. | |
| void | connect (const SocketAddress &addr) |
| Connect to a peer node. | |
| void | disconnect () |
| Disconnect the (presumably) open connection. | |
| BLOCXX_DEPRECATED void | setReceiveTimeout (int seconds) |
| Set the receive timeout on the socket. | |
| void | setReceiveTimeout (const Timeout &timeout) |
| Set the receive timeout on the socket. | |
| Timeout | getReceiveTimeout () const |
| Get the receive timeout. | |
| BLOCXX_DEPRECATED void | setSendTimeout (int seconds) |
| Set the send timeout on the socket. | |
| void | setSendTimeout (const Timeout &timeout) |
| Set the send timeout on the socket. | |
| Timeout | getSendTimeout () const |
| Get the send timeout. | |
| BLOCXX_DEPRECATED void | setConnectTimeout (int seconds) |
| Set the connect timeout on the socket. | |
| void | setConnectTimeout (const Timeout &timeout) |
| Set the connect timeout on the socket. | |
| Timeout | getConnectTimeout () const |
| Get the connect timeout. | |
| BLOCXX_DEPRECATED void | setTimeouts (int seconds) |
| Set all timeouts (send, receive, connect) | |
| void | setTimeouts (const Timeout &timeout) |
| Set all timeouts (send, receive, connect) | |
| bool | receiveTimeOutExpired () const |
| Has the receive timeout expired? | |
| int | write (const void *dataOut, int dataOutLen, ErrorAction errorAsException=E_RETURN_ON_ERROR) |
| Write some data to the socket. | |
| int | read (void *dataIn, int dataInLen, ErrorAction errorAsException=E_RETURN_ON_ERROR) |
| Read from the socket. | |
| BLOCXX_DEPRECATED bool | waitForInput (int timeOutSecs) |
| Wait for input on the socket for a specified length of time. | |
| bool | waitForInput (const Timeout &timeout=Timeout::infinite) |
| Wait for input on the socket for a specified length of time. | |
| BLOCXX_DEPRECATED bool | waitForOutput (int timeOutSecs) |
| Wait for output on the socket for a specified length of time. | |
| bool | waitForOutput (const Timeout &timeout=Timeout::infinite) |
| Wait for output on the socket for a specified length of time. | |
| SocketAddress | getLocalAddress () const |
| Get the local address associated with the socket connection. | |
| SocketAddress | getPeerAddress () const |
| Get the peer address associated with the socket connection. | |
| std::istream & | getInputStream () |
| Get an istream to read from the socket. | |
| std::ostream & | getOutputStream () |
| Get an ostream to write to the socket. | |
| BLOCXX_DEPRECATED std::iostream & | getIOStream () |
| Get an iostream to read/write from/to the socket. | |
| Select_t | getSelectObj () const |
| SocketHandle_t | getfd () |
| Get the socket handle for the socket. | |
| bool | isConnected () const |
| Get connected state. | |
| SSL * | getSSL () const |
| get the SSL structure associated with the socket (if it is an SSL socket) | |
| bool | peerCertVerified () const |
| did the peer certificate pass verification? | |
Public Member Functions inherited from BLOCXX_NAMESPACE::SelectableIFC | |
| virtual | ~SelectableIFC () |
Public Member Functions inherited from BLOCXX_NAMESPACE::IOIFC | |
| virtual | ~IOIFC () |
Static Public Member Functions | |
| static void | createShutDownMechanism () |
| static void | shutdownAllSockets () |
| Call this to shutdown all sockets. | |
| static bool | gotShutDown () BLOCXX_DEPRECATED |
| Have the sockets been shutdown? | |
| static void | deleteShutDownMechanism () |
| static ShutDownMechanism_t | getShutDownMechanism () |
Static Public Attributes | |
| static const int INFINITE_TIMEOUT | BLOCXX_DEPRECATED = -1 |
Private Member Functions | |
| Socket (SocketHandle_t fd, SocketAddress::AddressType addrType, const SSLServerCtxRef &sslCtx) | |
| Allocate a new Socket based on an existing handle. | |
Private Attributes | |
| SocketBaseImplRef | m_impl |
Static Private Attributes | |
| static LazyGlobal< Socket::ShutDownMechanism_t, int, ShutDownMechanismFactory > | s_shutDownMechanism = { 0 , 0, {0, PTHREAD_MUTEX_INITIALIZER} } |
Friends | |
| class | ServerSocketImpl |
Additional Inherited Members | |
Protected Member Functions inherited from BLOCXX_NAMESPACE::IntrusiveCountableBase | |
| IntrusiveCountableBase () | |
| IntrusiveCountableBase (const IntrusiveCountableBase &) | |
| IntrusiveCountableBase & | operator= (const IntrusiveCountableBase &) |
| virtual | ~IntrusiveCountableBase () |
Definition at line 65 of file Socket.hpp.
Definition at line 293 of file Socket.hpp.
| BLOCXX_NAMESPACE::Socket::Socket | ( | ) |
Construct a non-SSL Socket.
Definition at line 60 of file Socket.cpp.
| BLOCXX_NAMESPACE::Socket::Socket | ( | const SSLClientCtxRef & | sslCtx | ) |
Construct a Socket.
| sslCtx | The SSL client context. If null, the socket will not use SSL. |
Definition at line 52 of file Socket_needs_SSL.cpp.
References BLOCXX_THROW, m_impl, and BLOCXX_NAMESPACE::operator==().
| BLOCXX_NAMESPACE::Socket::Socket | ( | SocketFlags::ESSLFlag | isSSL | ) |
Allocate a new Socket.
| isSSL | is it an ssl socket? |
Definition at line 69 of file Socket_needs_SSL.cpp.
References BLOCXX_THROW, BLOCXX_NAMESPACE::SocketFlags::E_SSL, m_impl, and BLOCXX_NAMESPACE::operator==().
| BLOCXX_NAMESPACE::Socket::Socket | ( | SocketHandle_t | fd, |
| SocketAddress::AddressType | addrType, | ||
| SocketFlags::ESSLFlag | isSSL = SocketFlags::E_NOT_SSL ) |
TODO: Make a replacement for this function so it can be deprecated.
Allocate a new Socket based on an existing handle. This is used by ServerSocket::accept()
| fd | a handle to the existing socket |
| isSSL | is it an SSL socket? |
Definition at line 85 of file Socket_needs_SSL.cpp.
References BLOCXX_THROW, BLOCXX_NAMESPACE::SocketFlags::E_SSL, m_impl, and BLOCXX_NAMESPACE::operator==().
| BLOCXX_NAMESPACE::Socket::Socket | ( | const SocketAddress & | addr, |
| SocketFlags::ESSLFlag | isSSL = SocketFlags::E_NOT_SSL ) |
TODO: Make a replacement for this function so it can be deprecated.
Allocate a new Socket and connect it to a peer machine
| addr | the address of the peer machine |
| addrType | the address type of the socket @isSSL is it an SSL socket? |
| SocketException |
Definition at line 120 of file Socket_needs_SSL.cpp.
References BLOCXX_THROW, BLOCXX_NAMESPACE::SocketFlags::E_SSL, m_impl, and BLOCXX_NAMESPACE::operator==().
|
private |
Allocate a new Socket based on an existing handle.
This is used by ServerSocket::accept()
| fd | a handle to the existing socket |
| addrType | the address type of the socket |
| sslCtx | a SSL server context reference |
Definition at line 103 of file Socket_needs_SSL.cpp.
References BLOCXX_THROW, m_impl, and BLOCXX_NAMESPACE::operator==().
|
inline |
Connect to a peer node.
| addr | The address of the machine to connect to. |
| SocketException |
Definition at line 105 of file Socket.hpp.
References m_impl, and BLOCXX_NAMESPACE::operator==().
|
static |
Definition at line 95 of file Socket.cpp.
References BLOCXX_NAMESPACE::b_gotShutDown, BLOCXX_ASSERT, BLOCXX_NAMESPACE::UnnamedPipe::createUnnamedPipe(), BLOCXX_NAMESPACE::UnnamedPipe::E_NONBLOCKING, BLOCXX_NAMESPACE::operator==(), s_shutDownMechanism, and BLOCXX_NAMESPACE::shutdownMutex.
|
static |
Definition at line 113 of file Socket.cpp.
References BLOCXX_NAMESPACE::operator==(), s_shutDownMechanism, and BLOCXX_NAMESPACE::shutdownMutex.
|
inline |
Disconnect the (presumably) open connection.
Definition at line 110 of file Socket.hpp.
References m_impl.
|
inline |
Get the connect timeout.
Definition at line 157 of file Socket.hpp.
References m_impl.
|
inline |
Get the socket handle for the socket.
Definition at line 269 of file Socket.hpp.
References m_impl.
|
inline |
Get an istream to read from the socket.
| SocketException |
Definition at line 245 of file Socket.hpp.
References m_impl.
|
inline |
Get an iostream to read/write from/to the socket.
| SocketException |
Definition at line 259 of file Socket.hpp.
References m_impl.
|
inline |
Get the local address associated with the socket connection.
Definition at line 234 of file Socket.hpp.
References m_impl.
|
inline |
Get an ostream to write to the socket.
| SocketException |
Definition at line 252 of file Socket.hpp.
References m_impl.
|
inline |
Get the peer address associated with the socket connection.
Definition at line 239 of file Socket.hpp.
References m_impl.
|
inline |
Get the receive timeout.
Definition at line 127 of file Socket.hpp.
References m_impl.
|
inlinevirtual |
Implements BLOCXX_NAMESPACE::SelectableIFC.
Definition at line 264 of file Socket.hpp.
References m_impl.
|
inline |
Get the send timeout.
Definition at line 142 of file Socket.hpp.
References m_impl.
|
inlinestatic |
Definition at line 296 of file Socket.hpp.
Referenced by BLOCXX_NAMESPACE::SocketBaseImpl::connect(), and BLOCXX_NAMESPACE::SocketUtils::waitForIO().
| SSL * BLOCXX_NAMESPACE::Socket::getSSL | ( | ) | const |
get the SSL structure associated with the socket (if it is an SSL socket)
Definition at line 138 of file Socket_needs_SSL.cpp.
References BLOCXX_NAMESPACE::IntrusiveReference< T >::cast_to(), BLOCXX_NAMESPACE::SSLSocketImpl::getSSL(), m_impl, and BLOCXX_NAMESPACE::operator==().
|
static |
Have the sockets been shutdown?
Definition at line 127 of file Socket.cpp.
References BLOCXX_NAMESPACE::b_gotShutDown, BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::shutdownMutex.
|
inline |
| bool BLOCXX_NAMESPACE::Socket::peerCertVerified | ( | ) | const |
did the peer certificate pass verification?
Definition at line 150 of file Socket_needs_SSL.cpp.
References BLOCXX_NAMESPACE::IntrusiveReference< T >::cast_to(), m_impl, BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::SSLSocketImpl::peerCertVerified().
|
inlinevirtual |
Read from the socket.
| dataIn | a pointer to a buffer where data should be copied to |
| dataInLen | the number of bytes to read. |
| errorAsException | true if errors should throw exceptions. |
| SocketException |
Implements BLOCXX_NAMESPACE::IOIFC.
Definition at line 191 of file Socket.hpp.
References m_impl, and BLOCXX_NAMESPACE::operator==().
|
inline |
Has the receive timeout expired?
Definition at line 172 of file Socket.hpp.
References m_impl.
Set the connect timeout on the socket.
| seconds | the number of seconds for the connect timeout |
Definition at line 152 of file Socket.hpp.
References m_impl, and BLOCXX_NAMESPACE::operator==().
|
inline |
Set the connect timeout on the socket.
| seconds | the number of seconds for the connect timeout |
Definition at line 147 of file Socket.hpp.
References m_impl, BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Timeout::relative().
Set the receive timeout on the socket.
| seconds | the number of seconds for the receive timeout |
Definition at line 122 of file Socket.hpp.
References m_impl, and BLOCXX_NAMESPACE::operator==().
|
inline |
Set the receive timeout on the socket.
| seconds | the number of seconds for the receive timeout |
Definition at line 117 of file Socket.hpp.
References m_impl, BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Timeout::relative().
Set the send timeout on the socket.
| seconds | the number of seconds for the send timeout |
Definition at line 137 of file Socket.hpp.
References m_impl, and BLOCXX_NAMESPACE::operator==().
|
inline |
Set the send timeout on the socket.
| seconds | the number of seconds for the send timeout |
Definition at line 132 of file Socket.hpp.
References m_impl, BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Timeout::relative().
Set all timeouts (send, receive, connect)
| seconds | the number of seconds for the timeouts |
Definition at line 167 of file Socket.hpp.
References m_impl, and BLOCXX_NAMESPACE::operator==().
|
inline |
Set all timeouts (send, receive, connect)
| seconds | the number of seconds for the timeouts |
Definition at line 162 of file Socket.hpp.
References m_impl, BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Timeout::relative().
|
static |
Call this to shutdown all sockets.
This is usefull when a server is shutting down. We want any outstanding connections to close immediately.
Definition at line 71 of file Socket.cpp.
References BLOCXX_NAMESPACE::b_gotShutDown, BLOCXX_ASSERT, BLOCXX_THROW_ERRNO_MSG, BLOCXX_NAMESPACE::operator==(), s_shutDownMechanism, and BLOCXX_NAMESPACE::shutdownMutex.
|
inline |
Wait for input on the socket for a specified length of time.
| timeOutSecs | the number of seconds to wait. |
| SocketException |
Definition at line 209 of file Socket.hpp.
References m_impl, and BLOCXX_NAMESPACE::operator==().
|
inline |
Wait for input on the socket for a specified length of time.
| timeOutSecs | the number of seconds to wait. |
| SocketException |
Definition at line 200 of file Socket.hpp.
References m_impl, BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Timeout::relative().
|
inline |
Wait for output on the socket for a specified length of time.
| timeOutSecs | the number of seconds to wait. |
| SocketException |
Definition at line 227 of file Socket.hpp.
References m_impl, and BLOCXX_NAMESPACE::operator==().
|
inline |
Wait for output on the socket for a specified length of time.
| timeOutSecs | the number of seconds to wait. |
| SocketException |
Definition at line 218 of file Socket.hpp.
References m_impl, BLOCXX_NAMESPACE::operator==(), and BLOCXX_NAMESPACE::Timeout::relative().
|
inlinevirtual |
Write some data to the socket.
| dataOut | a pointer to the memory to be written to the socket. |
| dataOutLen | the length of the data to be written |
| errorAsException | true if errors should throw exceptions. |
| SocketException |
Implements BLOCXX_NAMESPACE::IOIFC.
Definition at line 181 of file Socket.hpp.
References m_impl, and BLOCXX_NAMESPACE::operator==().
|
friend |
Definition at line 347 of file Socket.hpp.
Definition at line 112 of file Socket.hpp.
|
private |
Definition at line 332 of file Socket.hpp.
Referenced by getSSL(), peerCertVerified(), Socket(), Socket(), Socket(), Socket(), and Socket().
|
staticprivate |
Definition at line 345 of file Socket.hpp.
Referenced by createShutDownMechanism(), deleteShutDownMechanism(), and shutdownAllSockets().