Browse Source

Added move assignment operators to sockets.

release/0.19
JustinAJ 10 years ago
parent
commit
2896b93024
  1. 8
      Jupiter/SecureSocket.cpp
  2. 8
      Jupiter/SecureSocket.h
  3. 7
      Jupiter/Socket.cpp
  4. 8
      Jupiter/Socket.h
  5. 12
      Jupiter/TCPSocket.cpp
  6. 2
      Jupiter/TCPSocket.h
  7. 29
      Jupiter/UDPSocket.cpp
  8. 4
      Jupiter/UDPSocket.h
  9. BIN
      Release/Jupiter.lib

8
Jupiter/SecureSocket.cpp

@ -33,6 +33,14 @@ Jupiter::SecureSocket::SSLData::~SSLData()
if (Jupiter::SecureSocket::SSLData::context != nullptr) SSL_CTX_free(Jupiter::SecureSocket::SSLData::context); if (Jupiter::SecureSocket::SSLData::context != nullptr) SSL_CTX_free(Jupiter::SecureSocket::SSLData::context);
} }
Jupiter::SecureSocket &Jupiter::SecureSocket::operator=(Jupiter::SecureSocket &&source)
{
Jupiter::Socket::operator=(std::move(source));
Jupiter::SecureSocket::SSLdata_ = source.SSLdata_;
source.SSLdata_ = nullptr;
return *this;
}
Jupiter::SecureSocket::SecureSocket() : Jupiter::Socket() Jupiter::SecureSocket::SecureSocket() : Jupiter::Socket()
{ {
Jupiter::SecureSocket::SSLdata_ = new Jupiter::SecureSocket::SSLData(); Jupiter::SecureSocket::SSLdata_ = new Jupiter::SecureSocket::SSLData();

8
Jupiter/SecureSocket.h

@ -156,6 +156,14 @@ namespace Jupiter
*/ */
bool initSSL(); bool initSSL();
/**
* @brief Move assignment operator for the Socket class
*
* @param source Socket to move data from
* @return Reference to this socket.
*/
SecureSocket &SecureSocket::operator=(SecureSocket &&source);
/** /**
* @brief Default constructor for the SecureSocket class. * @brief Default constructor for the SecureSocket class.
* This constructor will set the buffer size to 4096 chars. * This constructor will set the buffer size to 4096 chars.

7
Jupiter/Socket.cpp

@ -79,6 +79,13 @@ Jupiter::Socket::Data::~Data()
if (Jupiter::Socket::Data::buff != nullptr) delete[] Jupiter::Socket::Data::buff; if (Jupiter::Socket::Data::buff != nullptr) delete[] Jupiter::Socket::Data::buff;
} }
Jupiter::Socket &Jupiter::Socket::operator=(Jupiter::Socket &&source)
{
Jupiter::Socket::data_ = source.data_;
source.data_ = nullptr;
return *this;
}
Jupiter::Socket::Socket() : Jupiter::Socket::Socket(4096) Jupiter::Socket::Socket() : Jupiter::Socket::Socket(4096)
{ {
} }

8
Jupiter/Socket.h

@ -497,6 +497,14 @@ namespace Jupiter
*/ */
static bool cleanup(); static bool cleanup();
/**
* @brief Move assignment operator for the Socket class
*
* @param source Socket to move data from
* @return Reference to this socket.
*/
Socket &Socket::operator=(Socket &&source);
/** /**
* @brief Default constructor for the Socket class. * @brief Default constructor for the Socket class.
* This constructor will set the buffer size to 4096 chars. * This constructor will set the buffer size to 4096 chars.

12
Jupiter/TCPSocket.cpp

@ -24,6 +24,12 @@ void setSocketTCP(Jupiter::Socket *sock)
/** TCPSocket Implementation */ /** TCPSocket Implementation */
Jupiter::TCPSocket &Jupiter::TCPSocket::operator=(Jupiter::TCPSocket &&source)
{
Jupiter::Socket::operator=(std::move(source));
return *this;
}
Jupiter::TCPSocket::TCPSocket() : Socket() Jupiter::TCPSocket::TCPSocket() : Socket()
{ {
setSocketTCP(this); setSocketTCP(this);
@ -41,6 +47,12 @@ Jupiter::TCPSocket::TCPSocket(Jupiter::Socket &&source) : Socket(std::move(sourc
/** SecureTCPSocket Implementation */ /** SecureTCPSocket Implementation */
Jupiter::SecureTCPSocket &Jupiter::SecureTCPSocket::operator=(Jupiter::SecureTCPSocket &&source)
{
Jupiter::SecureSocket::operator=(std::move(source));
return *this;
}
Jupiter::SecureTCPSocket::SecureTCPSocket() : SecureSocket() Jupiter::SecureTCPSocket::SecureTCPSocket() : SecureSocket()
{ {
setSocketTCP(this); setSocketTCP(this);

2
Jupiter/TCPSocket.h

@ -36,6 +36,7 @@ namespace Jupiter
class JUPITER_API TCPSocket : public Socket class JUPITER_API TCPSocket : public Socket
{ {
public: public:
TCPSocket &TCPSocket::operator=(TCPSocket &&source);
TCPSocket(); TCPSocket();
TCPSocket(const TCPSocket &) = delete; TCPSocket(const TCPSocket &) = delete;
TCPSocket(size_t bufferSize); TCPSocket(size_t bufferSize);
@ -49,6 +50,7 @@ namespace Jupiter
class JUPITER_API SecureTCPSocket : public SecureSocket class JUPITER_API SecureTCPSocket : public SecureSocket
{ {
public: public:
SecureTCPSocket &SecureTCPSocket::operator=(SecureTCPSocket &&source);
SecureTCPSocket(); SecureTCPSocket();
SecureTCPSocket(const SecureTCPSocket &) = delete; SecureTCPSocket(const SecureTCPSocket &) = delete;
SecureTCPSocket(size_t bufferSize); SecureTCPSocket(size_t bufferSize);

29
Jupiter/UDPSocket.cpp

@ -15,8 +15,31 @@
#include <netinet/in.h> #include <netinet/in.h>
#endif // _WIN32 #endif // _WIN32
Jupiter::UDPSocket::UDPSocket() void setSocketUDP(Jupiter::Socket *sock)
{ {
this->setType(SOCK_DGRAM); sock->setType(SOCK_DGRAM);
this->setProtocol(IPPROTO_UDP); sock->setProtocol(IPPROTO_UDP);
}
/** UDPSocket Implementation */
Jupiter::UDPSocket &Jupiter::UDPSocket::operator=(Jupiter::UDPSocket &&source)
{
Jupiter::Socket::operator=(std::move(source));
return *this;
}
Jupiter::UDPSocket::UDPSocket() : Socket()
{
setSocketUDP(this);
}
Jupiter::UDPSocket::UDPSocket(size_t bufferSize) : Socket(bufferSize)
{
setSocketUDP(this);
}
Jupiter::UDPSocket::UDPSocket(Jupiter::Socket &&source) : Socket(std::move(source))
{
setSocketUDP(this);
} }

4
Jupiter/UDPSocket.h

@ -35,7 +35,11 @@ namespace Jupiter
class JUPITER_API UDPSocket : public Socket class JUPITER_API UDPSocket : public Socket
{ {
public: public:
UDPSocket &UDPSocket::operator=(UDPSocket &&source);
UDPSocket(); UDPSocket();
UDPSocket(const UDPSocket &) = delete;
UDPSocket(size_t bufferSize);
UDPSocket(Jupiter::Socket &&source);
}; };
} }

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save