diff --git a/src/connection.cpp b/src/connection.cpp index 8f7c153d0..8ba75264e 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -173,7 +173,7 @@ static int connSocketWrite(connection *conn, const void *data, size_t data_len) * connected, not to mess with handler callbacks. */ ConnectionState expected = CONN_STATE_CONNECTED; - conn->state.compare_exchange_strong(expected, CONN_STATE_ERROR); + conn->state.compare_exchange_strong(expected, CONN_STATE_ERROR, std::memory_order_relaxed); } return ret; @@ -189,8 +189,8 @@ static int connSocketRead(connection *conn, void *buf, size_t buf_len) { /* Don't overwrite the state of a connection that is not already * connected, not to mess with handler callbacks. */ - if (conn->state == CONN_STATE_CONNECTED) - conn->state.store(CONN_STATE_ERROR, std::memory_order_release); + ConnectionState expected = CONN_STATE_CONNECTED; + conn->state.compare_exchange_strong(expected, CONN_STATE_ERROR, std::memory_order_release); } return ret;