Unverified Commit fcf8f910 authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #402 from knowledge4igor/fix_data_races_in_client

Fix data races in client connection state logic
parents 7fe7bb56 e1784bf6
......@@ -41,9 +41,9 @@ struct Connection : public std::enable_shared_from_this<Connection> {
Connection()
: fd(-1)
, requestEntry(nullptr)
, connectionState_(NotConnected)
{
state_.store(static_cast<uint32_t>(State::Idle));
connectionState_.store(NotConnected);
}
struct RequestData {
......@@ -133,7 +133,7 @@ private:
struct sockaddr_in saddr;
std::unique_ptr<RequestEntry> requestEntry;
std::atomic<uint32_t> state_;
ConnectionState connectionState_;
std::atomic<ConnectionState> connectionState_;
std::shared_ptr<Transport> transport_;
Queue<RequestData> requestsQueue;
......
......@@ -355,14 +355,14 @@ Connection::connect(const Address& addr)
make_non_blocking(sfd);
connectionState_ = Connecting;
connectionState_.store(Connecting);
fd = sfd;
transport_->asyncConnect(shared_from_this(), addr->ai_addr, addr->ai_addrlen)
.then([=]() {
socklen_t len = sizeof(saddr);
getsockname(sfd, (struct sockaddr *)&saddr, &len);
connectionState_ = Connected;
connectionState_.store(Connected);
processRequestQueue();
}, ExceptionPrinter());
break;
......@@ -388,12 +388,12 @@ Connection::isIdle() const {
bool
Connection::isConnected() const {
return connectionState_ == Connected;
return connectionState_.load() == Connected;
}
void
Connection::close() {
connectionState_ = NotConnected;
connectionState_.store(NotConnected);
::close(fd);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment