Fix incomplete move construction of SSLSocket. Add move constructor to Socket and TcpSocket
This commit is contained in:
parent
c97280d190
commit
d3f8f3a92b
@ -23,7 +23,7 @@ namespace fr
|
|||||||
~SSLSocket() override;
|
~SSLSocket() override;
|
||||||
SSLSocket(SSLSocket &&);
|
SSLSocket(SSLSocket &&);
|
||||||
SSLSocket(const SSLSocket &) = delete;
|
SSLSocket(const SSLSocket &) = delete;
|
||||||
SSLSocket& operator=(SSLSocket &&);
|
SSLSocket &operator=(SSLSocket &&);
|
||||||
void operator=(const SSLSocket &)=delete;
|
void operator=(const SSLSocket &)=delete;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@ -52,10 +52,10 @@ namespace fr
|
|||||||
};
|
};
|
||||||
|
|
||||||
Socket();
|
Socket();
|
||||||
Socket(Socket &&) =delete;
|
Socket(Socket &&);
|
||||||
Socket(const Socket &) =delete;
|
Socket(const Socket &) =delete;
|
||||||
void operator=(const Socket &) =delete;
|
void operator=(const Socket &) =delete;
|
||||||
void operator=(Socket &&) =delete;
|
Socket &operator=(Socket &&);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Converts an fr::Socket::Status value to a printable string
|
* Converts an fr::Socket::Status value to a printable string
|
||||||
|
|||||||
@ -16,9 +16,9 @@ namespace fr
|
|||||||
public:
|
public:
|
||||||
TcpSocket() noexcept;
|
TcpSocket() noexcept;
|
||||||
~TcpSocket() override;
|
~TcpSocket() override;
|
||||||
TcpSocket(TcpSocket &&) = delete;
|
TcpSocket(TcpSocket &&);
|
||||||
TcpSocket(const TcpSocket &) = delete;
|
TcpSocket(const TcpSocket &) = delete;
|
||||||
void operator=(TcpSocket &&)=delete;
|
TcpSocket &operator=(TcpSocket &&);
|
||||||
void operator=(const TcpSocket &)=delete;
|
void operator=(const TcpSocket &)=delete;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
#include <mbedtls/ssl.h>
|
#include <mbedtls/ssl.h>
|
||||||
#include <cstdlib> //size_t
|
#include <cstdlib> //size_t
|
||||||
#include <cstring> //memcpy, memset
|
#include <cstring> //memcpy, memset
|
||||||
#include <utility> //move
|
|
||||||
|
|
||||||
namespace fr
|
namespace fr
|
||||||
{
|
{
|
||||||
@ -29,22 +28,11 @@ namespace fr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr mbedtls_ssl_config move_mbedtls_ssl_config(mbedtls_ssl_config &&src)
|
static inline mbedtls_ssl_config move_mbedtls_ssl_config(mbedtls_ssl_config &&src)
|
||||||
{
|
{
|
||||||
mbedtls_ssl_config retval = {};
|
mbedtls_ssl_config retval = {};
|
||||||
swap(retval.ciphersuite_list, src.ciphersuite_list);
|
memcpy(&retval, &src, sizeof(src));
|
||||||
swap(retval.p_dbg, src.p_dbg);
|
memset(&src, 0, sizeof(src));
|
||||||
swap(retval.f_get_cache, src.f_get_cache);
|
|
||||||
swap(retval.f_set_cache, src.f_set_cache);
|
|
||||||
swap(retval.p_cache, src.p_cache);
|
|
||||||
retval.max_major_ver = src.max_major_ver;
|
|
||||||
retval.max_minor_ver = src.max_minor_ver;
|
|
||||||
retval.min_major_ver = src.min_major_ver;
|
|
||||||
retval.min_minor_ver = src.min_minor_ver;
|
|
||||||
retval.endpoint = src.endpoint;
|
|
||||||
retval.transport = src.transport;
|
|
||||||
retval.authmode = src.authmode;
|
|
||||||
retval.allow_legacy_renegotiation = src.allow_legacy_renegotiation;
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,7 +60,8 @@ namespace fr
|
|||||||
}
|
}
|
||||||
|
|
||||||
SSLSocket::SSLSocket(SSLSocket &&s)
|
SSLSocket::SSLSocket(SSLSocket &&s)
|
||||||
: ssl_context(std::move(s.ssl_context)),
|
: Socket(std::move(s)),
|
||||||
|
ssl_context(std::move(s.ssl_context)),
|
||||||
ssl_socket_descriptor(std::move(s.ssl_socket_descriptor)),
|
ssl_socket_descriptor(std::move(s.ssl_socket_descriptor)),
|
||||||
ssl(std::move(s.ssl)),
|
ssl(std::move(s.ssl)),
|
||||||
conf(move_mbedtls_ssl_config(std::move(s.conf))),
|
conf(move_mbedtls_ssl_config(std::move(s.conf))),
|
||||||
@ -68,8 +69,9 @@ namespace fr
|
|||||||
receive_timeout(s.receive_timeout),
|
receive_timeout(s.receive_timeout),
|
||||||
is_blocking(s.is_blocking){}
|
is_blocking(s.is_blocking){}
|
||||||
|
|
||||||
SSLSocket& SSLSocket::operator=(SSLSocket &&s)
|
SSLSocket &SSLSocket::operator=(SSLSocket &&s)
|
||||||
{
|
{
|
||||||
|
Socket::operator=(std::move(s));
|
||||||
ssl_context = std::move(s.ssl_context);
|
ssl_context = std::move(s.ssl_context);
|
||||||
ssl_socket_descriptor = std::move(s.ssl_socket_descriptor);
|
ssl_socket_descriptor = std::move(s.ssl_socket_descriptor);
|
||||||
ssl = std::move(s.ssl);
|
ssl = std::move(s.ssl);
|
||||||
|
|||||||
@ -24,6 +24,23 @@ namespace fr
|
|||||||
init_wsa();
|
init_wsa();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Socket::Socket(Socket &&s)
|
||||||
|
: fr_socket_remote_address(std::move(s.fr_socket_remote_address)),
|
||||||
|
ai_family(s.ai_family),
|
||||||
|
max_receive_size(s.max_receive_size),
|
||||||
|
socket_read_timeout(s.socket_read_timeout),
|
||||||
|
socket_write_timeout(s.socket_write_timeout){}
|
||||||
|
|
||||||
|
Socket &Socket::operator=(Socket &&s)
|
||||||
|
{
|
||||||
|
fr_socket_remote_address = std::move(s.fr_socket_remote_address);
|
||||||
|
ai_family = s.ai_family;
|
||||||
|
max_receive_size = s.max_receive_size;
|
||||||
|
socket_read_timeout = s.socket_read_timeout;
|
||||||
|
socket_write_timeout = s.socket_write_timeout;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Socket::Status Socket::send(const Sendable &obj)
|
Socket::Status Socket::send(const Sendable &obj)
|
||||||
{
|
{
|
||||||
if(!connected())
|
if(!connected())
|
||||||
|
|||||||
@ -17,11 +17,24 @@ namespace fr
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TcpSocket::TcpSocket(TcpSocket &&t)
|
||||||
|
: Socket(std::move(t)),
|
||||||
|
socket_descriptor(std::exchange(t.socket_descriptor, -1)),
|
||||||
|
is_blocking(t.is_blocking){}
|
||||||
|
|
||||||
TcpSocket::~TcpSocket()
|
TcpSocket::~TcpSocket()
|
||||||
{
|
{
|
||||||
TcpSocket::close_socket();
|
TcpSocket::close_socket();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TcpSocket &TcpSocket::operator=(TcpSocket &&t)
|
||||||
|
{
|
||||||
|
Socket::operator=(std::move(t));
|
||||||
|
std::swap(socket_descriptor, t.socket_descriptor);
|
||||||
|
is_blocking = t.is_blocking;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Socket::Status TcpSocket::send_raw(const char *data, size_t size, size_t &sent)
|
Socket::Status TcpSocket::send_raw(const char *data, size_t size, size_t &sent)
|
||||||
{
|
{
|
||||||
while(sent < size)
|
while(sent < size)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user