1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Replaced open port check with server crash check

This commit is contained in:
Ivan Savenko 2023-12-26 21:13:46 +02:00
parent aa7ecea683
commit 78b7d9e726
3 changed files with 8 additions and 31 deletions

View File

@ -181,17 +181,7 @@ void CServerHandler::startLocalServerAndConnect()
threadRunLocalServer->join();
th->update();
auto errorMsg = CGI->generaltexth->translate("vcmi.server.errors.existingProcess");
// TODO: restore
// if (!checkNetworkPortIsFree(localhostAddress, getDefaultPort()))
// {
// logNetwork->error("Port is busy, check if another instance of vcmiserver is working");
// CInfoWindow::showInfoDialog(errorMsg, {});
// return;
// }
#if defined(SINGLE_PROCESS_APP)
boost::condition_variable cond;
std::vector<std::string> args{"--uuid=" + uuid, "--port=" + std::to_string(getLocalPort())};
@ -962,6 +952,14 @@ void CServerHandler::threadRunServer()
}
else
{
if (state != EClientState::DISCONNECTING)
{
if (state == EClientState::CONNECTING)
CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.server.errors.existingProcess"), {});
else
CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.server.errors.serverCrashed"), {});
}
state = EClientState::CONNECTION_CANCELLED; // stop attempts to reconnect
logNetwork->error("Error: server failed to close correctly or crashed!");
logNetwork->error("Check %s for more info", logName);

View File

@ -13,23 +13,6 @@
VCMI_LIB_NAMESPACE_BEGIN
DLL_LINKAGE bool checkNetworkPortIsFree(const std::string & host, uint16_t port)
{
boost::asio::io_service io;
NetworkAcceptor acceptor(io);
boost::system::error_code ec;
acceptor.open(boost::asio::ip::tcp::v4(), ec);
if (ec)
return false;
acceptor.bind(boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port), ec);
if (ec)
return false;
return true;
}
NetworkClient::NetworkClient(INetworkClientListener & listener)
: io(new NetworkService)
, socket(new NetworkSocket(*io))

View File

@ -14,10 +14,6 @@
VCMI_LIB_NAMESPACE_BEGIN
/// Function that attempts to open specified port on local system to determine whether port is in use
/// Returns: true if port is free and can be used to receive connections
DLL_LINKAGE bool checkNetworkPortIsFree(const std::string & host, uint16_t port);
class NetworkConnection;
class DLL_LINKAGE NetworkClient : boost::noncopyable, public INetworkConnectionListener