1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Make usage of boost::interprocess optional

If shared memory allocation failed on client server will be started without shared memory option.
Only downside of this is that server wouldn't be able to fallback to random port if default is busy.
This commit is contained in:
Arseniy Shestakov
2017-05-31 07:13:24 +03:00
parent cc163c4e05
commit c7e7a4d7be
2 changed files with 49 additions and 21 deletions

View File

@@ -963,10 +963,13 @@ void CServerHandler::waitForServer()
th.update();
#ifndef VCMI_ANDROID
intpr::scoped_lock<intpr::interprocess_mutex> slock(shared->sr->mutex);
while(!shared->sr->ready)
if(shared)
{
shared->sr->cond.wait(slock);
intpr::scoped_lock<intpr::interprocess_mutex> slock(shared->sr->mutex);
while(!shared->sr->ready)
{
shared->sr->cond.wait(slock);
}
}
#else
logNetwork->infoStream() << "waiting for server";
@@ -985,9 +988,12 @@ void CServerHandler::waitForServer()
CConnection * CServerHandler::connectToServer()
{
#ifndef VCMI_ANDROID
if(!shared->sr->ready)
waitForServer();
port = boost::lexical_cast<std::string>(shared->sr->port);
if(shared)
{
if(!shared->sr->ready)
waitForServer();
port = boost::lexical_cast<std::string>(shared->sr->port);
}
#else
waitForServer();
#endif
@@ -1013,6 +1019,9 @@ CServerHandler::CServerHandler(bool runServer /*= false*/)
verbose = true;
#ifndef VCMI_ANDROID
if(DO_NOT_START_SERVER)
return;
boost::interprocess::shared_memory_object::remove("vcmi_memory"); //if the application has previously crashed, the memory may not have been removed. to avoid problems - try to destroy it
try
{
@@ -1020,6 +1029,7 @@ CServerHandler::CServerHandler(bool runServer /*= false*/)
}
catch(...)
{
vstd::clear_pointer(shared);
logNetwork->error("Cannot open interprocess memory.");
handleException();
throw;
@@ -1038,7 +1048,12 @@ void CServerHandler::callServer()
#ifndef VCMI_ANDROID
setThreadName("CServerHandler::callServer");
const std::string logName = (VCMIDirs::get().userCachePath() / "server_log.txt").string();
const std::string comm = VCMIDirs::get().serverPath().string() + " --port=" + port + " > \"" + logName + '\"';
const std::string comm = VCMIDirs::get().serverPath().string()
+ " --port=" + port
+ " --run-by-client"
+ (shared ? " --use-shm" : "")
+ " > \"" + logName + '\"';
int result = std::system(comm.c_str());
if (result == 0)
{