mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-22 16:02:29 +02:00
#2418: SecureServerSocket doesn't work with IpV6
This commit is contained in:
@@ -85,7 +85,7 @@ public:
|
|||||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
/// socket option.
|
/// socket option.
|
||||||
|
|
||||||
virtual void bind(const SocketAddress& address, bool reuseAddress, bool reusePort );
|
virtual void bind(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||||
/// Bind a local address to the socket.
|
/// Bind a local address to the socket.
|
||||||
///
|
///
|
||||||
/// This is usually only done when establishing a server
|
/// This is usually only done when establishing a server
|
||||||
@@ -115,7 +115,7 @@ public:
|
|||||||
/// If the library has not been built with IPv6 support,
|
/// If the library has not been built with IPv6 support,
|
||||||
/// a Poco::NotImplementedException will be thrown.
|
/// a Poco::NotImplementedException will be thrown.
|
||||||
|
|
||||||
virtual void bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only);
|
virtual void bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only);
|
||||||
/// Bind a local IPv6 address to the socket.
|
/// Bind a local IPv6 address to the socket.
|
||||||
///
|
///
|
||||||
/// This is usually only done when establishing a server
|
/// This is usually only done when establishing a server
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
/// with the client.
|
/// with the client.
|
||||||
///
|
///
|
||||||
/// The client socket's address is returned in clientAddr.
|
/// The client socket's address is returned in clientAddr.
|
||||||
|
|
||||||
void connect(const SocketAddress& address);
|
void connect(const SocketAddress& address);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
@@ -62,8 +62,18 @@ public:
|
|||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
void bind(const SocketAddress& address, bool reuseAddress = false, bool reusePort = false);
|
void bind(const SocketAddress& address, bool reuseAddress = false);
|
||||||
|
/// Bind a local address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
|
||||||
|
void bind(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||||
/// Bind a local address to the socket.
|
/// Bind a local address to the socket.
|
||||||
///
|
///
|
||||||
/// This is usually only done when establishing a server
|
/// This is usually only done when establishing a server
|
||||||
@@ -76,7 +86,43 @@ public:
|
|||||||
/// If reusePort is true, sets the SO_REUSEPORT
|
/// If reusePort is true, sets the SO_REUSEPORT
|
||||||
/// socket option.
|
/// socket option.
|
||||||
|
|
||||||
|
void bind6(const SocketAddress& address, bool reuseAddress = false, bool ipV6Only = false);
|
||||||
|
/// Bind a local IPv6 address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// The given address must be an IPv6 address. The
|
||||||
|
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||||
|
/// according to the ipV6Only parameter.
|
||||||
|
///
|
||||||
|
/// If the library has not been built with IPv6 support,
|
||||||
|
/// a Poco::NotImplementedException will be thrown.
|
||||||
|
|
||||||
|
void bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only);
|
||||||
|
/// Bind a local IPv6 address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// If reusePort is true, sets the SO_REUSEPORT
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// The given address must be an IPv6 address. The
|
||||||
|
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||||
|
/// according to the ipV6Only parameter.
|
||||||
|
///
|
||||||
|
/// If the library has not been built with IPv6 support,
|
||||||
|
/// a Poco::NotImplementedException will be thrown.
|
||||||
|
|
||||||
void listen(int backlog = 64);
|
void listen(int backlog = 64);
|
||||||
/// Puts the socket into listening state.
|
/// Puts the socket into listening state.
|
||||||
///
|
///
|
||||||
@@ -89,27 +135,27 @@ public:
|
|||||||
|
|
||||||
void close();
|
void close();
|
||||||
/// Close the socket.
|
/// Close the socket.
|
||||||
|
|
||||||
int sendBytes(const void* buffer, int length, int flags = 0);
|
int sendBytes(const void* buffer, int length, int flags = 0);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
int receiveBytes(void* buffer, int length, int flags = 0);
|
int receiveBytes(void* buffer, int length, int flags = 0);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
|
int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0);
|
int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
void sendUrgent(unsigned char data);
|
void sendUrgent(unsigned char data);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
@@ -118,7 +164,7 @@ public:
|
|||||||
bool secure() const;
|
bool secure() const;
|
||||||
/// Returns true iff the socket's connection is secure
|
/// Returns true iff the socket's connection is secure
|
||||||
/// (using SSL or TLS).
|
/// (using SSL or TLS).
|
||||||
|
|
||||||
Context::Ptr context() const;
|
Context::Ptr context() const;
|
||||||
/// Returns the SSL context used by this socket.
|
/// Returns the SSL context used by this socket.
|
||||||
|
|
||||||
|
|||||||
@@ -56,29 +56,39 @@ public:
|
|||||||
/// with the client.
|
/// with the client.
|
||||||
///
|
///
|
||||||
/// The client socket's address is returned in clientAddr.
|
/// The client socket's address is returned in clientAddr.
|
||||||
|
|
||||||
void connect(const SocketAddress& address, bool performHandshake);
|
void connect(const SocketAddress& address, bool performHandshake);
|
||||||
/// Initializes the socket and establishes a secure connection to
|
/// Initializes the socket and establishes a secure connection to
|
||||||
/// the TCP server at the given address.
|
/// the TCP server at the given address.
|
||||||
///
|
///
|
||||||
/// If performHandshake is true, the SSL handshake is performed immediately
|
/// If performHandshake is true, the SSL handshake is performed immediately
|
||||||
/// after establishing the connection. Otherwise, the handshake is performed
|
/// after establishing the connection. Otherwise, the handshake is performed
|
||||||
/// the first time sendBytes(), receiveBytes() or completeHandshake() is called.
|
/// the first time sendBytes(), receiveBytes() or completeHandshake() is called.
|
||||||
|
|
||||||
void connect(const SocketAddress& address, const Poco::Timespan& timeout, bool performHandshake);
|
void connect(const SocketAddress& address, const Poco::Timespan& timeout, bool performHandshake);
|
||||||
/// Initializes the socket, sets the socket timeout and
|
/// Initializes the socket, sets the socket timeout and
|
||||||
/// establishes a secure connection to the TCP server at the given address.
|
/// establishes a secure connection to the TCP server at the given address.
|
||||||
///
|
///
|
||||||
/// If performHandshake is true, the SSL handshake is performed immediately
|
/// If performHandshake is true, the SSL handshake is performed immediately
|
||||||
/// after establishing the connection. Otherwise, the handshake is performed
|
/// after establishing the connection. Otherwise, the handshake is performed
|
||||||
/// the first time sendBytes(), receiveBytes() or completeHandshake() is called.
|
/// the first time sendBytes(), receiveBytes() or completeHandshake() is called.
|
||||||
|
|
||||||
void connectNB(const SocketAddress& address);
|
void connectNB(const SocketAddress& address);
|
||||||
/// Initializes the socket and establishes a secure connection to
|
/// Initializes the socket and establishes a secure connection to
|
||||||
/// the TCP server at the given address. Prior to opening the
|
/// the TCP server at the given address. Prior to opening the
|
||||||
/// connection the socket is set to nonblocking mode.
|
/// connection the socket is set to nonblocking mode.
|
||||||
|
|
||||||
void bind(const SocketAddress& address, bool reuseAddress = false, bool reusePort = false);
|
void bind(const SocketAddress& address, bool reuseAddress = false);
|
||||||
|
/// Bind a local address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
|
||||||
|
void bind(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||||
/// Bind a local address to the socket.
|
/// Bind a local address to the socket.
|
||||||
///
|
///
|
||||||
/// This is usually only done when establishing a server
|
/// This is usually only done when establishing a server
|
||||||
@@ -90,7 +100,44 @@ public:
|
|||||||
///
|
///
|
||||||
/// If reusePort is true, sets the SO_REUSEPORT
|
/// If reusePort is true, sets the SO_REUSEPORT
|
||||||
/// socket option.
|
/// socket option.
|
||||||
|
|
||||||
|
void bind6(const SocketAddress& address, bool reuseAddress = false, bool ipV6Only = false);
|
||||||
|
/// Bind a local IPv6 address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// The given address must be an IPv6 address. The
|
||||||
|
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||||
|
/// according to the ipV6Only parameter.
|
||||||
|
///
|
||||||
|
/// If the library has not been built with IPv6 support,
|
||||||
|
/// a Poco::NotImplementedException will be thrown.
|
||||||
|
|
||||||
|
void bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only);
|
||||||
|
/// Bind a local IPv6 address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// If reusePort is true, sets the SO_REUSEPORT
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// The given address must be an IPv6 address. The
|
||||||
|
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||||
|
/// according to the ipV6Only parameter.
|
||||||
|
///
|
||||||
|
/// If the library has not been built with IPv6 support,
|
||||||
|
/// a Poco::NotImplementedException will be thrown.
|
||||||
|
|
||||||
void listen(int backlog = 64);
|
void listen(int backlog = 64);
|
||||||
/// Puts the socket into listening state.
|
/// Puts the socket into listening state.
|
||||||
///
|
///
|
||||||
@@ -108,42 +155,42 @@ public:
|
|||||||
|
|
||||||
void close();
|
void close();
|
||||||
/// Close the socket.
|
/// Close the socket.
|
||||||
|
|
||||||
void abort();
|
void abort();
|
||||||
/// Aborts the connection by closing the
|
/// Aborts the connection by closing the
|
||||||
/// underlying TCP connection. No orderly SSL shutdown
|
/// underlying TCP connection. No orderly SSL shutdown
|
||||||
/// is performed.
|
/// is performed.
|
||||||
|
|
||||||
int sendBytes(const void* buffer, int length, int flags = 0);
|
int sendBytes(const void* buffer, int length, int flags = 0);
|
||||||
/// Sends the contents of the given buffer through
|
/// Sends the contents of the given buffer through
|
||||||
/// the socket. Any specified flags are ignored.
|
/// the socket. Any specified flags are ignored.
|
||||||
///
|
///
|
||||||
/// Returns the number of bytes sent, which may be
|
/// Returns the number of bytes sent, which may be
|
||||||
/// less than the number of bytes specified.
|
/// less than the number of bytes specified.
|
||||||
|
|
||||||
int receiveBytes(void* buffer, int length, int flags = 0);
|
int receiveBytes(void* buffer, int length, int flags = 0);
|
||||||
/// Receives data from the socket and stores it
|
/// Receives data from the socket and stores it
|
||||||
/// in buffer. Up to length bytes are received.
|
/// in buffer. Up to length bytes are received.
|
||||||
///
|
///
|
||||||
/// Returns the number of bytes received.
|
/// Returns the number of bytes received.
|
||||||
|
|
||||||
int available() const;
|
int available() const;
|
||||||
/// Returns the number of bytes available from the
|
/// Returns the number of bytes available from the
|
||||||
/// SSL buffer for immediate reading.
|
/// SSL buffer for immediate reading.
|
||||||
|
|
||||||
int completeHandshake();
|
int completeHandshake();
|
||||||
/// Completes the SSL handshake.
|
/// Completes the SSL handshake.
|
||||||
///
|
///
|
||||||
/// If the SSL connection was the result of an accept(),
|
/// If the SSL connection was the result of an accept(),
|
||||||
/// the server-side handshake is completed, otherwise
|
/// the server-side handshake is completed, otherwise
|
||||||
/// a client-side handshake is performed.
|
/// a client-side handshake is performed.
|
||||||
|
|
||||||
poco_socket_t sockfd();
|
poco_socket_t sockfd();
|
||||||
/// Returns the underlying socket descriptor.
|
/// Returns the underlying socket descriptor.
|
||||||
|
|
||||||
X509* peerCertificate() const;
|
X509* peerCertificate() const;
|
||||||
/// Returns the peer's certificate.
|
/// Returns the peer's certificate.
|
||||||
|
|
||||||
Context::Ptr context() const;
|
Context::Ptr context() const;
|
||||||
/// Returns the SSL context used for this socket.
|
/// Returns the SSL context used for this socket.
|
||||||
|
|
||||||
@@ -158,17 +205,17 @@ public:
|
|||||||
|
|
||||||
void setPeerHostName(const std::string& hostName);
|
void setPeerHostName(const std::string& hostName);
|
||||||
/// Sets the peer host name for certificate validation purposes.
|
/// Sets the peer host name for certificate validation purposes.
|
||||||
|
|
||||||
const std::string& getPeerHostName() const;
|
const std::string& getPeerHostName() const;
|
||||||
/// Returns the peer host name.
|
/// Returns the peer host name.
|
||||||
|
|
||||||
Session::Ptr currentSession();
|
Session::Ptr currentSession();
|
||||||
/// Returns the SSL session of the current connection,
|
/// Returns the SSL session of the current connection,
|
||||||
/// for reuse in a future connection (if session caching
|
/// for reuse in a future connection (if session caching
|
||||||
/// is enabled).
|
/// is enabled).
|
||||||
///
|
///
|
||||||
/// If no connection is established, returns null.
|
/// If no connection is established, returns null.
|
||||||
|
|
||||||
void useSession(Session::Ptr pSession);
|
void useSession(Session::Ptr pSession);
|
||||||
/// Sets the SSL session to use for the next
|
/// Sets the SSL session to use for the next
|
||||||
/// connection. Setting a previously saved Session
|
/// connection. Setting a previously saved Session
|
||||||
@@ -178,31 +225,31 @@ public:
|
|||||||
/// can be given.
|
/// can be given.
|
||||||
///
|
///
|
||||||
/// Must be called before connect() to be effective.
|
/// Must be called before connect() to be effective.
|
||||||
|
|
||||||
bool sessionWasReused();
|
bool sessionWasReused();
|
||||||
/// Returns true iff a reused session was negotiated during
|
/// Returns true iff a reused session was negotiated during
|
||||||
/// the handshake.
|
/// the handshake.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void acceptSSL();
|
void acceptSSL();
|
||||||
/// Performs a server-side SSL handshake and certificate verification.
|
/// Performs a server-side SSL handshake and certificate verification.
|
||||||
|
|
||||||
void connectSSL(bool performHandshake);
|
void connectSSL(bool performHandshake);
|
||||||
/// Performs a client-side SSL handshake and establishes a secure
|
/// Performs a client-side SSL handshake and establishes a secure
|
||||||
/// connection over an already existing TCP connection.
|
/// connection over an already existing TCP connection.
|
||||||
|
|
||||||
long verifyPeerCertificateImpl(const std::string& hostName);
|
long verifyPeerCertificateImpl(const std::string& hostName);
|
||||||
/// Performs post-connect (or post-accept) peer certificate validation.
|
/// Performs post-connect (or post-accept) peer certificate validation.
|
||||||
|
|
||||||
static bool isLocalHost(const std::string& hostName);
|
static bool isLocalHost(const std::string& hostName);
|
||||||
/// Returns true iff the given host name is the local host
|
/// Returns true iff the given host name is the local host
|
||||||
/// (either "localhost" or "127.0.0.1").
|
/// (either "localhost" or "127.0.0.1").
|
||||||
|
|
||||||
bool mustRetry(int rc);
|
bool mustRetry(int rc);
|
||||||
/// Returns true if the last operation should be retried,
|
/// Returns true if the last operation should be retried,
|
||||||
/// otherwise false.
|
/// otherwise false.
|
||||||
///
|
///
|
||||||
/// In case of an SSL_ERROR_WANT_READ error, and if the socket is
|
/// In case of an SSL_ERROR_WANT_READ error, and if the socket is
|
||||||
/// blocking, waits for the underlying socket to become readable.
|
/// blocking, waits for the underlying socket to become readable.
|
||||||
///
|
///
|
||||||
/// In case of an SSL_ERROR_WANT_WRITE error, and if the socket is
|
/// In case of an SSL_ERROR_WANT_WRITE error, and if the socket is
|
||||||
@@ -216,7 +263,7 @@ protected:
|
|||||||
/// Handles an SSL error by throwing an appropriate exception.
|
/// Handles an SSL error by throwing an appropriate exception.
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
/// Prepares the socket for re-use.
|
/// Prepares the socket for re-use.
|
||||||
///
|
///
|
||||||
/// After closing and resetting a socket, the socket can
|
/// After closing and resetting a socket, the socket can
|
||||||
/// be used for a new connection.
|
/// be used for a new connection.
|
||||||
@@ -224,7 +271,7 @@ protected:
|
|||||||
/// Note that simply closing a socket is not sufficient
|
/// Note that simply closing a socket is not sufficient
|
||||||
/// to be able to re-use it again.
|
/// to be able to re-use it again.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SecureSocketImpl(const SecureSocketImpl&);
|
SecureSocketImpl(const SecureSocketImpl&);
|
||||||
SecureSocketImpl& operator = (const SecureSocketImpl&);
|
SecureSocketImpl& operator = (const SecureSocketImpl&);
|
||||||
|
|
||||||
@@ -234,7 +281,7 @@ private:
|
|||||||
bool _needHandshake;
|
bool _needHandshake;
|
||||||
std::string _peerHostName;
|
std::string _peerHostName;
|
||||||
Session::Ptr _pSession;
|
Session::Ptr _pSession;
|
||||||
|
|
||||||
friend class SecureStreamSocketImpl;
|
friend class SecureStreamSocketImpl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -54,13 +54,20 @@ void SecureServerSocketImpl::connect(const SocketAddress& address, const Poco::T
|
|||||||
{
|
{
|
||||||
throw Poco::InvalidAccessException("Cannot connect() a SecureServerSocket");
|
throw Poco::InvalidAccessException("Cannot connect() a SecureServerSocket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureServerSocketImpl::connectNB(const SocketAddress& address)
|
void SecureServerSocketImpl::connectNB(const SocketAddress& address)
|
||||||
{
|
{
|
||||||
throw Poco::InvalidAccessException("Cannot connect() a SecureServerSocket");
|
throw Poco::InvalidAccessException("Cannot connect() a SecureServerSocket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureServerSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
|
||||||
|
{
|
||||||
|
_impl.bind(address, reuseAddress);
|
||||||
|
reset(_impl.sockfd());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureServerSocketImpl::bind(const SocketAddress& address, bool reuseAddress, bool reusePort)
|
void SecureServerSocketImpl::bind(const SocketAddress& address, bool reuseAddress, bool reusePort)
|
||||||
{
|
{
|
||||||
@@ -68,20 +75,34 @@ void SecureServerSocketImpl::bind(const SocketAddress& address, bool reuseAddres
|
|||||||
reset(_impl.sockfd());
|
reset(_impl.sockfd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureServerSocketImpl::bind6(const SocketAddress& address, bool reuseAddress, bool ipV6Only)
|
||||||
|
{
|
||||||
|
_impl.bind6(address, reuseAddress, ipV6Only);
|
||||||
|
reset(_impl.sockfd());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureServerSocketImpl::bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only)
|
||||||
|
{
|
||||||
|
_impl.bind6(address, reuseAddress, reusePort, ipV6Only);
|
||||||
|
reset(_impl.sockfd());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureServerSocketImpl::listen(int backlog)
|
void SecureServerSocketImpl::listen(int backlog)
|
||||||
{
|
{
|
||||||
_impl.listen(backlog);
|
_impl.listen(backlog);
|
||||||
reset(_impl.sockfd());
|
reset(_impl.sockfd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureServerSocketImpl::close()
|
void SecureServerSocketImpl::close()
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
_impl.close();
|
_impl.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SecureServerSocketImpl::sendBytes(const void* buffer, int length, int flags)
|
int SecureServerSocketImpl::sendBytes(const void* buffer, int length, int flags)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -192,6 +192,14 @@ void SecureSocketImpl::connectSSL(bool performHandshake)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
|
||||||
|
{
|
||||||
|
poco_check_ptr (_pSocket);
|
||||||
|
|
||||||
|
_pSocket->bind(address, reuseAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureSocketImpl::bind(const SocketAddress& address, bool reuseAddress, bool reusePort)
|
void SecureSocketImpl::bind(const SocketAddress& address, bool reuseAddress, bool reusePort)
|
||||||
{
|
{
|
||||||
poco_check_ptr (_pSocket);
|
poco_check_ptr (_pSocket);
|
||||||
@@ -200,6 +208,22 @@ void SecureSocketImpl::bind(const SocketAddress& address, bool reuseAddress, boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureSocketImpl::bind6(const SocketAddress& address, bool reuseAddress, bool ipV6Only)
|
||||||
|
{
|
||||||
|
poco_check_ptr (_pSocket);
|
||||||
|
|
||||||
|
_pSocket->bind6(address, reuseAddress, ipV6Only);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureSocketImpl::bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only)
|
||||||
|
{
|
||||||
|
poco_check_ptr (_pSocket);
|
||||||
|
|
||||||
|
_pSocket->bind6(address, reuseAddress, reusePort, ipV6Only);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureSocketImpl::listen(int backlog)
|
void SecureSocketImpl::listen(int backlog)
|
||||||
{
|
{
|
||||||
poco_check_ptr (_pSocket);
|
poco_check_ptr (_pSocket);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
/// with the client.
|
/// with the client.
|
||||||
///
|
///
|
||||||
/// The client socket's address is returned in clientAddr.
|
/// The client socket's address is returned in clientAddr.
|
||||||
|
|
||||||
void connect(const SocketAddress& address);
|
void connect(const SocketAddress& address);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
void bind(const SocketAddress& address, bool reuseAddress = false);
|
void bind(const SocketAddress& address, bool reuseAddress = false);
|
||||||
/// Bind a local address to the socket.
|
/// Bind a local address to the socket.
|
||||||
///
|
///
|
||||||
@@ -72,7 +72,57 @@ public:
|
|||||||
///
|
///
|
||||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
/// socket option.
|
/// socket option.
|
||||||
|
|
||||||
|
void bind(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||||
|
/// Bind a local address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// If reusePort is true, sets the SO_REUSEPORT
|
||||||
|
/// socket option.
|
||||||
|
|
||||||
|
void bind6(const SocketAddress& address, bool reuseAddress = false, bool ipV6Only = false);
|
||||||
|
/// Bind a local IPv6 address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// The given address must be an IPv6 address. The
|
||||||
|
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||||
|
/// according to the ipV6Only parameter.
|
||||||
|
///
|
||||||
|
/// If the library has not been built with IPv6 support,
|
||||||
|
/// a Poco::NotImplementedException will be thrown.
|
||||||
|
|
||||||
|
void bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only);
|
||||||
|
/// Bind a local IPv6 address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// If reusePort is true, sets the SO_REUSEPORT
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// The given address must be an IPv6 address. The
|
||||||
|
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||||
|
/// according to the ipV6Only parameter.
|
||||||
|
///
|
||||||
|
/// If the library has not been built with IPv6 support,
|
||||||
|
/// a Poco::NotImplementedException will be thrown.
|
||||||
|
|
||||||
void listen(int backlog = 64);
|
void listen(int backlog = 64);
|
||||||
/// Puts the socket into listening state.
|
/// Puts the socket into listening state.
|
||||||
///
|
///
|
||||||
@@ -85,27 +135,27 @@ public:
|
|||||||
|
|
||||||
void close();
|
void close();
|
||||||
/// Close the socket.
|
/// Close the socket.
|
||||||
|
|
||||||
int sendBytes(const void* buffer, int length, int flags = 0);
|
int sendBytes(const void* buffer, int length, int flags = 0);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
int receiveBytes(void* buffer, int length, int flags = 0);
|
int receiveBytes(void* buffer, int length, int flags = 0);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
|
int sendTo(const void* buffer, int length, const SocketAddress& address, int flags = 0);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0);
|
int receiveFrom(void* buffer, int length, SocketAddress& address, int flags = 0);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
/// Throws a Poco::InvalidAccessException.
|
/// Throws a Poco::InvalidAccessException.
|
||||||
|
|
||||||
void sendUrgent(unsigned char data);
|
void sendUrgent(unsigned char data);
|
||||||
/// Not supported by this kind of socket.
|
/// Not supported by this kind of socket.
|
||||||
///
|
///
|
||||||
@@ -114,7 +164,7 @@ public:
|
|||||||
bool secure() const;
|
bool secure() const;
|
||||||
/// Returns true iff the socket's connection is secure
|
/// Returns true iff the socket's connection is secure
|
||||||
/// (using SSL or TLS).
|
/// (using SSL or TLS).
|
||||||
|
|
||||||
Context::Ptr context() const;
|
Context::Ptr context() const;
|
||||||
/// Returns the SSL context used by this socket.
|
/// Returns the SSL context used by this socket.
|
||||||
|
|
||||||
|
|||||||
@@ -66,9 +66,9 @@ public:
|
|||||||
/// with the client.
|
/// with the client.
|
||||||
///
|
///
|
||||||
/// The client socket's address is returned in clientAddr.
|
/// The client socket's address is returned in clientAddr.
|
||||||
|
|
||||||
void connect(const SocketAddress& address, bool performHandshake);
|
void connect(const SocketAddress& address, bool performHandshake);
|
||||||
/// Initializes the socket and establishes a connection to
|
/// Initializes the socket and establishes a connection to
|
||||||
/// the TCP server at the given address.
|
/// the TCP server at the given address.
|
||||||
///
|
///
|
||||||
/// Can also be used for UDP sockets. In this case, no
|
/// Can also be used for UDP sockets. In this case, no
|
||||||
@@ -76,14 +76,14 @@ public:
|
|||||||
/// packets are restricted to the specified address.
|
/// packets are restricted to the specified address.
|
||||||
|
|
||||||
void connect(const SocketAddress& address, const Poco::Timespan& timeout, bool performHandshake);
|
void connect(const SocketAddress& address, const Poco::Timespan& timeout, bool performHandshake);
|
||||||
/// Initializes the socket, sets the socket timeout and
|
/// Initializes the socket, sets the socket timeout and
|
||||||
/// establishes a connection to the TCP server at the given address.
|
/// establishes a connection to the TCP server at the given address.
|
||||||
|
|
||||||
void connectNB(const SocketAddress& address);
|
void connectNB(const SocketAddress& address);
|
||||||
/// Initializes the socket and establishes a connection to
|
/// Initializes the socket and establishes a connection to
|
||||||
/// the TCP server at the given address. Prior to opening the
|
/// the TCP server at the given address. Prior to opening the
|
||||||
/// connection the socket is set to nonblocking mode.
|
/// connection the socket is set to nonblocking mode.
|
||||||
|
|
||||||
void bind(const SocketAddress& address, bool reuseAddress = false);
|
void bind(const SocketAddress& address, bool reuseAddress = false);
|
||||||
/// Bind a local address to the socket.
|
/// Bind a local address to the socket.
|
||||||
///
|
///
|
||||||
@@ -93,7 +93,57 @@ public:
|
|||||||
///
|
///
|
||||||
/// If reuseAddress is true, sets the SO_REUSEADDR
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
/// socket option.
|
/// socket option.
|
||||||
|
|
||||||
|
void bind(const SocketAddress& address, bool reuseAddress, bool reusePort);
|
||||||
|
/// Bind a local address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. SSL clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// If reusePort is true, sets the SO_REUSEPORT
|
||||||
|
/// socket option.
|
||||||
|
|
||||||
|
void bind6(const SocketAddress& address, bool reuseAddress = false, bool ipV6Only = false);
|
||||||
|
/// Bind a local IPv6 address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// The given address must be an IPv6 address. The
|
||||||
|
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||||
|
/// according to the ipV6Only parameter.
|
||||||
|
///
|
||||||
|
/// If the library has not been built with IPv6 support,
|
||||||
|
/// a Poco::NotImplementedException will be thrown.
|
||||||
|
|
||||||
|
void bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only);
|
||||||
|
/// Bind a local IPv6 address to the socket.
|
||||||
|
///
|
||||||
|
/// This is usually only done when establishing a server
|
||||||
|
/// socket. TCP clients should not bind a socket to a
|
||||||
|
/// specific address.
|
||||||
|
///
|
||||||
|
/// If reuseAddress is true, sets the SO_REUSEADDR
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// If reusePort is true, sets the SO_REUSEPORT
|
||||||
|
/// socket option.
|
||||||
|
///
|
||||||
|
/// The given address must be an IPv6 address. The
|
||||||
|
/// IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket
|
||||||
|
/// according to the ipV6Only parameter.
|
||||||
|
///
|
||||||
|
/// If the library has not been built with IPv6 support,
|
||||||
|
/// a Poco::NotImplementedException will be thrown.
|
||||||
|
|
||||||
void listen(int backlog = 64);
|
void listen(int backlog = 64);
|
||||||
/// Puts the socket into listening state.
|
/// Puts the socket into listening state.
|
||||||
///
|
///
|
||||||
@@ -116,14 +166,14 @@ public:
|
|||||||
/// Aborts the connection by closing the
|
/// Aborts the connection by closing the
|
||||||
/// underlying TCP connection. No orderly SSL shutdown
|
/// underlying TCP connection. No orderly SSL shutdown
|
||||||
/// is performed.
|
/// is performed.
|
||||||
|
|
||||||
int sendBytes(const void* buffer, int length, int flags = 0);
|
int sendBytes(const void* buffer, int length, int flags = 0);
|
||||||
/// Sends the contents of the given buffer through
|
/// Sends the contents of the given buffer through
|
||||||
/// the socket. Any specified flags are ignored.
|
/// the socket. Any specified flags are ignored.
|
||||||
///
|
///
|
||||||
/// Returns the number of bytes sent, which may be
|
/// Returns the number of bytes sent, which may be
|
||||||
/// less than the number of bytes specified.
|
/// less than the number of bytes specified.
|
||||||
|
|
||||||
int receiveBytes(void* buffer, int length, int flags = 0);
|
int receiveBytes(void* buffer, int length, int flags = 0);
|
||||||
/// Receives data from the socket and stores it
|
/// Receives data from the socket and stores it
|
||||||
/// in buffer. Up to length bytes are received.
|
/// in buffer. Up to length bytes are received.
|
||||||
@@ -132,7 +182,7 @@ public:
|
|||||||
|
|
||||||
void setPeerHostName(const std::string& hostName);
|
void setPeerHostName(const std::string& hostName);
|
||||||
/// Sets the peer host name for certificate validation purposes.
|
/// Sets the peer host name for certificate validation purposes.
|
||||||
|
|
||||||
const std::string& getPeerHostName() const;
|
const std::string& getPeerHostName() const;
|
||||||
/// Returns the peer host name.
|
/// Returns the peer host name.
|
||||||
|
|
||||||
@@ -302,7 +352,7 @@ inline PCCERT_CONTEXT SecureSocketImpl::peerCertificate() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline int SecureSocketImpl::lastError()
|
inline int SecureSocketImpl::lastError()
|
||||||
{
|
{
|
||||||
return SocketImpl::lastError();
|
return SocketImpl::lastError();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ void SecureServerSocketImpl::connect(const SocketAddress& address, const Poco::T
|
|||||||
{
|
{
|
||||||
throw Poco::InvalidAccessException("Cannot connect() a SecureServerSocket");
|
throw Poco::InvalidAccessException("Cannot connect() a SecureServerSocket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureServerSocketImpl::connectNB(const SocketAddress& address)
|
void SecureServerSocketImpl::connectNB(const SocketAddress& address)
|
||||||
{
|
{
|
||||||
throw Poco::InvalidAccessException("Cannot connect() a SecureServerSocket");
|
throw Poco::InvalidAccessException("Cannot connect() a SecureServerSocket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureServerSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
|
void SecureServerSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
|
||||||
{
|
{
|
||||||
@@ -61,20 +61,41 @@ void SecureServerSocketImpl::bind(const SocketAddress& address, bool reuseAddres
|
|||||||
reset(_impl.sockfd());
|
reset(_impl.sockfd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureServerSocketImpl::bind(const SocketAddress& address, bool reuseAddress, bool reusePort)
|
||||||
|
{
|
||||||
|
_impl.bind(address, reuseAddress, reusePort);
|
||||||
|
reset(_impl.sockfd());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureServerSocketImpl::bind6(const SocketAddress& address, bool reuseAddress, bool ipV6Only)
|
||||||
|
{
|
||||||
|
_impl.bind6(address, reuseAddress, ipV6Only);
|
||||||
|
reset(_impl.sockfd());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureServerSocketImpl::bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only)
|
||||||
|
{
|
||||||
|
_impl.bind6(address, reuseAddress, reusePort, ipV6Only);
|
||||||
|
reset(_impl.sockfd());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureServerSocketImpl::listen(int backlog)
|
void SecureServerSocketImpl::listen(int backlog)
|
||||||
{
|
{
|
||||||
_impl.listen(backlog);
|
_impl.listen(backlog);
|
||||||
reset(_impl.sockfd());
|
reset(_impl.sockfd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureServerSocketImpl::close()
|
void SecureServerSocketImpl::close()
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
_impl.close();
|
_impl.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int SecureServerSocketImpl::sendBytes(const void* buffer, int length, int flags)
|
int SecureServerSocketImpl::sendBytes(const void* buffer, int length, int flags)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -212,10 +212,36 @@ void SecureSocketImpl::connectNB(const SocketAddress& address)
|
|||||||
|
|
||||||
void SecureSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
|
void SecureSocketImpl::bind(const SocketAddress& address, bool reuseAddress)
|
||||||
{
|
{
|
||||||
|
poco_check_ptr (_pSocket);
|
||||||
|
|
||||||
_pSocket->bind(address, reuseAddress);
|
_pSocket->bind(address, reuseAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureSocketImpl::bind(const SocketAddress& address, bool reuseAddress, bool reusePort)
|
||||||
|
{
|
||||||
|
poco_check_ptr (_pSocket);
|
||||||
|
|
||||||
|
_pSocket->bind(address, reuseAddress, reusePort);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureSocketImpl::bind6(const SocketAddress& address, bool reuseAddress, bool ipV6Only)
|
||||||
|
{
|
||||||
|
poco_check_ptr (_pSocket);
|
||||||
|
|
||||||
|
_pSocket->bind6(address, reuseAddress, ipV6Only);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SecureSocketImpl::bind6(const SocketAddress& address, bool reuseAddress, bool reusePort, bool ipV6Only)
|
||||||
|
{
|
||||||
|
poco_check_ptr (_pSocket);
|
||||||
|
|
||||||
|
_pSocket->bind6(address, reuseAddress, reusePort, ipV6Only);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SecureSocketImpl::listen(int backlog)
|
void SecureSocketImpl::listen(int backlog)
|
||||||
{
|
{
|
||||||
_mode = MODE_SERVER;
|
_mode = MODE_SERVER;
|
||||||
|
|||||||
Reference in New Issue
Block a user