Skip to content

Commit 124a8e0

Browse files
committed
Make AsyncClient noncopyable/nonmovable
The previous code tried to implement move-as-copy semantics, which can lead to unexpected behavior; and further it was not safe, as there was a risk of race conditions with the LwIP thread. Remove the unsafe function for now, and indicate to the compiler to check for it. If there's a strong need for a move operation in the future, the thread safety can be reviewed at that time.
1 parent b9c100e commit 124a8e0

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

src/AsyncTCP.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -759,24 +759,6 @@ AsyncClient::~AsyncClient() {
759759
* Operators
760760
* */
761761

762-
AsyncClient &AsyncClient::operator=(const AsyncClient &other) {
763-
if (_pcb) {
764-
_close();
765-
}
766-
767-
_pcb = other._pcb;
768-
_closed_slot = other._closed_slot;
769-
if (_pcb) {
770-
_rx_last_packet = millis();
771-
tcp_arg(_pcb, this);
772-
tcp_recv(_pcb, &_tcp_recv);
773-
tcp_sent(_pcb, &_tcp_sent);
774-
tcp_err(_pcb, &_tcp_error);
775-
tcp_poll(_pcb, &_tcp_poll, CONFIG_ASYNC_TCP_POLL_TIMER);
776-
}
777-
return *this;
778-
}
779-
780762
bool AsyncClient::operator==(const AsyncClient &other) const {
781763
return _pcb == other._pcb;
782764
}

src/AsyncTCP.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ class AsyncClient {
8080
AsyncClient(tcp_pcb *pcb = 0);
8181
~AsyncClient();
8282

83-
AsyncClient &operator=(const AsyncClient &other);
83+
// Noncopyable
84+
AsyncClient(const AsyncClient &) = delete;
85+
AsyncClient &operator=(const AsyncClient &) = delete;
86+
87+
// Nonmovable
88+
AsyncClient(AsyncClient &&) = delete;
89+
AsyncClient &operator=(AsyncClient &&) = delete;
8490

8591
bool operator==(const AsyncClient &other) const;
8692

0 commit comments

Comments
 (0)