Skip to content

Commit

Permalink
Add check for double call RedisAsyncClient::connect
Browse files Browse the repository at this point in the history
  • Loading branch information
nekipelov committed Sep 15, 2016
1 parent c952da9 commit 3e1bdf0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/redisclient/impl/redisasyncclient.cpp
Expand Up @@ -35,9 +35,19 @@ void RedisAsyncClient::connect(const boost::asio::ip::address &address,
void RedisAsyncClient::connect(const boost::asio::ip::tcp::endpoint &endpoint,
std::function<void(bool, const std::string &)> handler)
{
pimpl->state = State::Connecting;
pimpl->socket.async_connect(endpoint, std::bind(&RedisClientImpl::handleAsyncConnect,
pimpl, std::placeholders::_1, std::move(handler)));
if( pimpl->state == State::Unconnected || pimpl->state == State::Closed )
{
pimpl->state = State::Connecting;
pimpl->socket.async_connect(endpoint, std::bind(&RedisClientImpl::handleAsyncConnect,
pimpl, std::placeholders::_1, std::move(handler)));
}
else
{
std::stringstream ss;

ss << "RedisAsyncClient::connect called on socket with state " << to_string(pimpl->state);
handler(false, ss.str());
}
}

bool RedisAsyncClient::isConnected() const
Expand Down

0 comments on commit 3e1bdf0

Please sign in to comment.