Skip to content

Commit bd3a332

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 d9a4b50 commit bd3a332

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
@@ -744,24 +744,6 @@ AsyncClient::~AsyncClient() {
744744
* Operators
745745
* */
746746

747-
AsyncClient &AsyncClient::operator=(const AsyncClient &other) {
748-
if (_pcb) {
749-
_close();
750-
}
751-
752-
_pcb = other._pcb;
753-
_closed_slot = other._closed_slot;
754-
if (_pcb) {
755-
_rx_last_packet = millis();
756-
tcp_arg(_pcb, this);
757-
tcp_recv(_pcb, &_tcp_recv);
758-
tcp_sent(_pcb, &_tcp_sent);
759-
tcp_err(_pcb, &_tcp_error);
760-
tcp_poll(_pcb, &_tcp_poll, CONFIG_ASYNC_TCP_POLL_TIMER);
761-
}
762-
return *this;
763-
}
764-
765747
bool AsyncClient::operator==(const AsyncClient &other) const {
766748
return _pcb == other._pcb;
767749
}

src/AsyncTCP.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ class AsyncClient {
7575
AsyncClient(tcp_pcb *pcb = 0);
7676
~AsyncClient();
7777

78-
AsyncClient &operator=(const AsyncClient &other);
78+
// Noncopyable
79+
AsyncClient(const AsyncClient &) = delete;
80+
AsyncClient &operator=(const AsyncClient &) = delete;
81+
82+
// Nonmovable
83+
AsyncClient(AsyncClient &&) = delete;
84+
AsyncClient &operator=(AsyncClient &&) = delete;
7985

8086
bool operator==(const AsyncClient &other) const;
8187

0 commit comments

Comments
 (0)