diff --git a/README.md b/README.md index ecf0c11..3f2de49 100644 --- a/README.md +++ b/README.md @@ -327,3 +327,4 @@ Thanks for everyone who reported a bug, suggested a feature and contributed to t - **10/05/21 (v0.5.1)** - Fingerprints and Certificates in the examples were updated by [@Khoi Hoang ](https://github.com/khoih-prog). Thank you Khoi! - **29/07/21 (v0.5.2)** - Merged PR by [ONLYstcm](https://github.com/ONLYstcm) which added a (configurable) timeout for connections. Thank you ONLYstcm. +- **29/07/21 (v0.5.3)** - Deleted unsafe copy and assignment operators in `WebsocketsClient`. \ No newline at end of file diff --git a/library.properties b/library.properties index b37b6d7..34fcc91 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoWebsockets -version=0.5.2 +version=0.5.3 author=Gil Maimon maintainer=Gil Maimon sentence=A library for writing modern Websockets applications with Arduino. diff --git a/src/tiny_websockets/client.hpp b/src/tiny_websockets/client.hpp index f3c035c..491a526 100644 --- a/src/tiny_websockets/client.hpp +++ b/src/tiny_websockets/client.hpp @@ -28,11 +28,10 @@ namespace websockets { WebsocketsClient(); WebsocketsClient(std::shared_ptr client); - WebsocketsClient(const WebsocketsClient& other); - WebsocketsClient(const WebsocketsClient&& other); - - WebsocketsClient& operator=(const WebsocketsClient& other); - WebsocketsClient& operator=(const WebsocketsClient&& other); + WebsocketsClient(const WebsocketsClient& other) = delete; + WebsocketsClient(const WebsocketsClient&& other) = delete; + WebsocketsClient& operator=(const WebsocketsClient& other) = delete; + WebsocketsClient& operator=(const WebsocketsClient&& other) = delete; void addHeader(const WSInterfaceString key, const WSInterfaceString value); diff --git a/src/websockets_client.cpp b/src/websockets_client.cpp index 49bfcb5..4c2212a 100644 --- a/src/websockets_client.cpp +++ b/src/websockets_client.cpp @@ -19,66 +19,6 @@ namespace websockets { // Empty } - WebsocketsClient::WebsocketsClient(const WebsocketsClient& other) : - _client(other._client), - _endpoint(other._endpoint), - _connectionOpen(other._client->available()), - _messagesCallback(other._messagesCallback), - _eventsCallback(other._eventsCallback), - _sendMode(other._sendMode) { - - // delete other's client - const_cast(other)._client = nullptr; - const_cast(other)._connectionOpen = false; - } - - WebsocketsClient::WebsocketsClient(const WebsocketsClient&& other) : - _client(other._client), - _endpoint(other._endpoint), - _connectionOpen(other._client->available()), - _messagesCallback(other._messagesCallback), - _eventsCallback(other._eventsCallback), - _sendMode(other._sendMode) { - - // delete other's client - const_cast(other)._client = nullptr; - const_cast(other)._connectionOpen = false; - } - - WebsocketsClient& WebsocketsClient::operator=(const WebsocketsClient& other) { - // call endpoint's copy operator - _endpoint = other._endpoint; - - // get callbacks and data from other - this->_client = other._client; - this->_messagesCallback = other._messagesCallback; - this->_eventsCallback = other._eventsCallback; - this->_connectionOpen = other._connectionOpen; - this->_sendMode = other._sendMode; - - // delete other's client - const_cast(other)._client = nullptr; - const_cast(other)._connectionOpen = false; - return *this; - } - - WebsocketsClient& WebsocketsClient::operator=(const WebsocketsClient&& other) { - // call endpoint's copy operator - _endpoint = other._endpoint; - - // get callbacks and data from other - this->_client = other._client; - this->_messagesCallback = other._messagesCallback; - this->_eventsCallback = other._eventsCallback; - this->_connectionOpen = other._connectionOpen; - this->_sendMode = other._sendMode; - - // delete other's client - const_cast(other)._client = nullptr; - const_cast(other)._connectionOpen = false; - return *this; - } - struct HandshakeRequestResult { WSString requestStr; WSString expectedAcceptKey;