From bcd562a2e147c988bf265cf8ac2cbaea4c501214 Mon Sep 17 00:00:00 2001 From: JustinAJ Date: Fri, 6 Jun 2014 21:22:27 -0400 Subject: [PATCH] Socket recreation now uses move semantics instead of reconstruction from scratch. --- Jupiter/IRC_Client.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Jupiter/IRC_Client.cpp b/Jupiter/IRC_Client.cpp index 22ab0bc..a16c23a 100644 --- a/Jupiter/IRC_Client.cpp +++ b/Jupiter/IRC_Client.cpp @@ -1272,15 +1272,21 @@ void Jupiter::IRC::Client::disconnect(bool stayDead) bool ssl = Jupiter::IRC::Client::readConfigBool(STRING_LITERAL_AS_REFERENCE("SSL")); if (ssl != Jupiter::IRC::Client::data_->ssl) { - delete Jupiter::IRC::Client::data_->sock; if (Jupiter::IRC::Client::data_->ssl = ssl) { - Jupiter::SecureTCPSocket *t = new Jupiter::SecureTCPSocket(); + Jupiter::SecureTCPSocket *t = new Jupiter::SecureTCPSocket(std::move(*Jupiter::IRC::Client::data_->sock)); if (Jupiter::IRC::Client::data_->SSLCertificate.size() != 0) t->setCertificate(Jupiter::IRC::Client::data_->SSLCertificate, Jupiter::IRC::Client::data_->SSLKey); + + delete Jupiter::IRC::Client::data_->sock; + Jupiter::IRC::Client::data_->sock = t; + } + else + { + Jupiter::TCPSocket *t = new Jupiter::TCPSocket(std::move(*Jupiter::IRC::Client::data_->sock)); + delete Jupiter::IRC::Client::data_->sock; Jupiter::IRC::Client::data_->sock = t; } - else Jupiter::IRC::Client::data_->sock = new Jupiter::TCPSocket(); } for (int i = Jupiter::plugins->size() - 1; i >= 0; i--) Jupiter::plugins->get(i)->OnDisconnect(this); }