rpcn: wait for signal before connect

This commit is contained in:
RipleyTom 2021-10-12 19:45:54 +02:00 committed by Megamouse
commit 8a72bdb422
2 changed files with 12 additions and 11 deletions

View file

@ -168,18 +168,16 @@ namespace rpcn
// By default is the object is alive we should be connected // By default is the object is alive we should be connected
if (!connected) if (!connected)
{ {
bool result_connect; if (want_conn)
{ {
std::lock_guard lock(mutex_connected); {
result_connect = connect(g_cfg_rpcn.get_host()); std::lock_guard lock(mutex_connected);
connect(g_cfg_rpcn.get_host());
}
sem_connected.release();
} }
sem_connected.release();
if (!result_connect) break;
{
break;
}
continue;
} }
if (!authentified) if (!authentified)
@ -195,7 +193,6 @@ namespace rpcn
if (!result_login) if (!result_login)
{ {
rpcn_log.notice("MT: login attempt failed");
break; break;
} }
continue; continue;
@ -435,6 +432,7 @@ namespace rpcn
if (res == 0) if (res == 0)
{ {
// Remote closed connection // Remote closed connection
rpcn_log.error("recv failed: connection reset by server");
return recvn_result::recvn_noconn; return recvn_result::recvn_noconn;
} }
@ -543,7 +541,6 @@ namespace rpcn
connected = false; connected = false;
authentified = false; authentified = false;
want_auth = false;
server_info_received = false; server_info_received = false;
} }
@ -1624,6 +1621,9 @@ namespace rpcn
{ {
return state; return state;
} }
want_conn = true;
sem_rpcn.release();
} }
sem_connected.acquire(); sem_connected.acquire();

View file

@ -215,6 +215,7 @@ namespace rpcn
atomic_t<bool> connected = false; atomic_t<bool> connected = false;
atomic_t<bool> authentified = false; atomic_t<bool> authentified = false;
atomic_t<bool> want_conn = false;
atomic_t<bool> want_auth = false; atomic_t<bool> want_auth = false;
std::binary_semaphore sem_connected, sem_authentified; std::binary_semaphore sem_connected, sem_authentified;
std::mutex mutex_connected, mutex_authentified; std::mutex mutex_connected, mutex_authentified;