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);
}
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::SSLdata_ = new Jupiter::SecureSocket::SSLData();

8
Jupiter/SecureSocket.h

@ -156,6 +156,14 @@ namespace Jupiter
*/
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.
* 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;
}
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)
{
}

8
Jupiter/Socket.h

@ -497,6 +497,14 @@ namespace Jupiter
*/
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.
* 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 */
Jupiter::TCPSocket &Jupiter::TCPSocket::operator=(Jupiter::TCPSocket &&source)
{
Jupiter::Socket::operator=(std::move(source));
return *this;
}
Jupiter::TCPSocket::TCPSocket() : Socket()
{
setSocketTCP(this);
@ -41,6 +47,12 @@ Jupiter::TCPSocket::TCPSocket(Jupiter::Socket &&source) : Socket(std::move(sourc
/** SecureTCPSocket Implementation */
Jupiter::SecureTCPSocket &Jupiter::SecureTCPSocket::operator=(Jupiter::SecureTCPSocket &&source)
{
Jupiter::SecureSocket::operator=(std::move(source));
return *this;
}
Jupiter::SecureTCPSocket::SecureTCPSocket() : SecureSocket()
{
setSocketTCP(this);

2
Jupiter/TCPSocket.h

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

29
Jupiter/UDPSocket.cpp

@ -15,8 +15,31 @@
#include <netinet/in.h>
#endif // _WIN32
Jupiter::UDPSocket::UDPSocket()
void setSocketUDP(Jupiter::Socket *sock)
{
this->setType(SOCK_DGRAM);
this->setProtocol(IPPROTO_UDP);
sock->setType(SOCK_DGRAM);
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
{
public:
UDPSocket &UDPSocket::operator=(UDPSocket &&source);
UDPSocket();
UDPSocket(const UDPSocket &) = delete;
UDPSocket(size_t bufferSize);
UDPSocket(Jupiter::Socket &&source);
};
}

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save