ソースを参照

Merge pull request #2432 from IvanSavenko/remove_boost_interprocess

(develop) Remove boost::interprocess usage
Ivan Savenko 2 年 前
コミット
323537e4bd

+ 1 - 7
client/CMT.cpp

@@ -117,8 +117,6 @@ int main(int argc, char * argv[])
 	opts.add_options()
 		("help,h", "display help and exit")
 		("version,v", "display version information and exit")
-		("disable-shm", "force disable shared memory usage")
-		("enable-shm-uuid", "use UUID for shared memory identifier")
 		("testmap", po::value<std::string>(), "")
 		("testsave", po::value<std::string>(), "")
 		("spectate,s", "enable spectator interface for AI-only games")
@@ -153,7 +151,7 @@ int main(int argc, char * argv[])
 		{
 			po::store(po::parse_command_line(argc, argv, opts, po_style::unix_style|po_style::case_insensitive), vm);
 		}
-		catch(std::exception &e)
+		catch(boost::program_options::error &e)
 		{
 			std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl;
 		}
@@ -241,10 +239,6 @@ int main(int argc, char * argv[])
 	// Server settings
 	setSettingBool("session/donotstartserver", "donotstartserver");
 
-	// Shared memory options
-	setSettingBool("session/disable-shm", "disable-shm");
-	setSettingBool("session/enable-shm-uuid", "enable-shm-uuid");
-
 	// Init special testing settings
 	setSettingInteger("session/serverport", "serverport", 0);
 	setSettingInteger("general/saveFrequency", "savefrequency", 1);

+ 5 - 44
client/CServerHandler.cpp

@@ -28,8 +28,6 @@
 #elif defined(VCMI_IOS)
 #include "ios/utils.h"
 #include <dispatch/dispatch.h>
-#else
-#include "../lib/Interprocess.h"
 #endif
 
 #ifdef SINGLE_PROCESS_APP
@@ -154,29 +152,6 @@ void CServerHandler::resetStateForLobby(const StartInfo::EMode mode, const std::
 		myNames = *names;
 	else
 		myNames.push_back(settings["general"]["playerName"].String());
-
-#if !defined(VCMI_ANDROID) && !defined(SINGLE_PROCESS_APP)
-	shm.reset();
-
-	if(!settings["session"]["disable-shm"].Bool())
-	{
-		std::string sharedMemoryName = "vcmi_memory";
-		if(settings["session"]["enable-shm-uuid"].Bool())
-		{
-			//used or automated testing when multiple clients start simultaneously
-			sharedMemoryName += "_" + uuid;
-		}
-		try
-		{
-			shm = std::make_shared<SharedMemory>(sharedMemoryName, true);
-		}
-		catch(...)
-		{
-			shm.reset();
-			logNetwork->error("Cannot open interprocess memory. Continue without it...");
-		}
-	}
-#endif
 }
 
 void CServerHandler::startLocalServerAndConnect()
@@ -194,7 +169,7 @@ void CServerHandler::startLocalServerAndConnect()
 		CInfoWindow::showInfoDialog(errorMsg, {});
 		return;
 	}
-	catch(...)
+	catch(std::runtime_error & error)
 	{
 		//no connection means that port is not busy and we can start local server
 	}
@@ -256,20 +231,12 @@ void CServerHandler::startLocalServerAndConnect()
 	}
 	logNetwork->info("waiting for server finished...");
 	androidTestServerReadyFlag = false;
-#else
-	if(shm)
-		shm->sr->waitTillReady();
 #endif
 	logNetwork->trace("Waiting for server: %d ms", th->getDiff());
 
 	th->update(); //put breakpoint here to attach to server before it does something stupid
 
-#if !defined(VCMI_MOBILE)
-	const ui16 port = shm ? shm->sr->port : 0;
-#else
-	const ui16 port = 0;
-#endif
-	justConnectToServer(localhostAddress, port);
+	justConnectToServer(localhostAddress, 0);
 
 	logNetwork->trace("\tConnecting to the server: %d ms", th->getDiff());
 }
@@ -287,9 +254,9 @@ void CServerHandler::justConnectToServer(const std::string & addr, const ui16 po
 					port ? port : getHostPort(),
 					NAME, uuid);
 		}
-		catch(...)
+		catch(std::runtime_error & error)
 		{
-			logNetwork->error("\nCannot establish connection! Retrying within 1 second");
+			logNetwork->warn("\nCannot establish connection. %s Retrying in 1 second", error.what());
 			boost::this_thread::sleep(boost::posix_time::seconds(1));
 		}
 	}
@@ -925,13 +892,7 @@ void CServerHandler::threadRunServer()
 		comm += " --lobby-port=" + std::to_string(settings["session"]["port"].Integer());
 		comm += " --lobby-uuid=" + settings["session"]["hostUuid"].String();
 	}
-		
-	if(shm)
-	{
-		comm += " --enable-shm";
-		if(settings["session"]["enable-shm-uuid"].Bool())
-			comm += " --enable-shm-uuid";
-	}
+
 	comm += " > \"" + logName + '\"';
     logGlobal->info("Server command line: %s", comm);
 

+ 1 - 1
client/CServerHandler.h

@@ -115,7 +115,7 @@ public:
 
 	void resetStateForLobby(const StartInfo::EMode mode, const std::vector<std::string> * names = nullptr);
 	void startLocalServerAndConnect();
-	void justConnectToServer(const std::string &addr = "", const ui16 port = 0);
+	void justConnectToServer(const std::string & addr, const ui16 port);
 	void applyPacksOnLobbyScreen();
 	void stopServerConnection();
 

+ 0 - 1
cmake_modules/VCMI_lib.cmake

@@ -585,7 +585,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
 		${MAIN_LIB_DIR}/IGameEventsReceiver.h
 		${MAIN_LIB_DIR}/IHandlerBase.h
 		${MAIN_LIB_DIR}/int3.h
-		${MAIN_LIB_DIR}/Interprocess.h
 		${MAIN_LIB_DIR}/JsonDetail.h
 		${MAIN_LIB_DIR}/JsonNode.h
 		${MAIN_LIB_DIR}/JsonRandom.h

+ 0 - 84
lib/Interprocess.h

@@ -1,84 +0,0 @@
-/*
- * Interprocess.h, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
-#pragma once
-
-#include <boost/interprocess/sync/scoped_lock.hpp>
-#include <boost/interprocess/sync/interprocess_mutex.hpp>
-#include <boost/interprocess/sync/interprocess_condition.hpp>
-#include <boost/interprocess/mapped_region.hpp>
-#include <boost/interprocess/shared_memory_object.hpp>
-
-VCMI_LIB_NAMESPACE_BEGIN
-
-struct ServerReady
-{
-	bool ready;
-	uint16_t port; //ui16?
-	boost::interprocess::interprocess_mutex mutex;
-	boost::interprocess::interprocess_condition cond;
-
-	ServerReady()
-	{
-		ready = false;
-		port = 0;
-	}
-
-	void waitTillReady()
-	{
-		boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> slock(mutex);
-		while(!ready)
-		{
-			cond.wait(slock);
-		}
-	}
-
-	void setToReadyAndNotify(const uint16_t Port)
-	{
-		{
-			boost::unique_lock<boost::interprocess::interprocess_mutex> lock(mutex);
-			ready = true;
-			port = Port;
-		}
-		cond.notify_all();
-	}
-};
-
-struct SharedMemory
-{
-	std::string name;
-	boost::interprocess::shared_memory_object smo;
-	boost::interprocess::mapped_region * mr;
-	ServerReady * sr;
-
-	SharedMemory(const std::string & Name, bool initialize = false)
-		: name(Name)
-	{
-		if(initialize)
-		{
-			//if the application has previously crashed, the memory may not have been removed. to avoid problems - try to destroy it
-			boost::interprocess::shared_memory_object::remove(name.c_str());
-		}
-		smo = boost::interprocess::shared_memory_object(boost::interprocess::open_or_create, name.c_str(), boost::interprocess::read_write);
-		smo.truncate(sizeof(ServerReady));
-		mr = new boost::interprocess::mapped_region(smo,boost::interprocess::read_write);
-		if(initialize)
-			sr = new(mr->get_address())ServerReady();
-		else
-			sr = reinterpret_cast<ServerReady*>(mr->get_address());
-	};
-
-	~SharedMemory()
-	{
-		delete mr;
-		boost::interprocess::shared_memory_object::remove(name.c_str());
-	}
-};
-
-VCMI_LIB_NAMESPACE_END

+ 0 - 2
lib/StartInfo.h

@@ -19,7 +19,6 @@ class CampaignState;
 class CMapInfo;
 struct PlayerInfo;
 class PlayerColor;
-struct SharedMemory;
 
 /// Struct which describes the name, the color, the starting bonus of a player
 struct DLL_LINKAGE PlayerSettings
@@ -157,7 +156,6 @@ struct DLL_LINKAGE LobbyInfo : public LobbyState
 {
 	boost::mutex stateMutex;
 	std::string uuid;
-	std::shared_ptr<SharedMemory> shm;
 
 	LobbyInfo() {}
 

+ 0 - 1
lib/rmg/modificators/ConnectionsPlacer.cpp

@@ -25,7 +25,6 @@
 #include "WaterAdopter.h"
 #include "WaterProxy.h"
 #include "TownPlacer.h"
-#include <boost/interprocess/sync/scoped_lock.hpp>
 
 VCMI_LIB_NAMESPACE_BEGIN
 

+ 3 - 3
lib/serializer/Connection.cpp

@@ -82,7 +82,7 @@ CConnection::CConnection(const std::string & host, ui16 port, std::string Name,
 	if(error)
 	{
 		logNetwork->error("Problem with resolving: \n%s", error.message());
-		throw std::runtime_error("Can't establish connection: Problem with resolving");
+		throw std::runtime_error("Problem with resolving");
 	}
 	pom = endpoint_iterator;
 	if(pom != end)
@@ -90,7 +90,7 @@ CConnection::CConnection(const std::string & host, ui16 port, std::string Name,
 	else
 	{
 		logNetwork->error("Critical problem: No endpoints found!");
-		throw std::runtime_error("Can't establish connection: No endpoints found!");
+		throw std::runtime_error("No endpoints found!");
 	}
 	while(pom != end)
 	{
@@ -109,7 +109,7 @@ CConnection::CConnection(const std::string & host, ui16 port, std::string Name,
 		}
 		else
 		{
-			throw std::runtime_error("Can't establish connection: Failed to connect!");
+			throw std::runtime_error("Failed to connect!");
 		}
 		endpoint_iterator++;
 	}

+ 2 - 2
mapeditor/resourceExtractor/ResourceConverter.cpp

@@ -19,8 +19,8 @@
 #include "BitmapHandler.h"
 #include "Animation.h"
 
-#include "boost/filesystem/path.hpp"
-#include "boost/locale.hpp"
+#include <boost/filesystem/path.hpp>
+#include <boost/locale.hpp>
 
 void ResourceConverter::convertExtractedResourceFiles(ConversionOptions conversionOptions)
 {

+ 3 - 23
server/CVCMIServer.cpp

@@ -33,8 +33,6 @@
 #include <jni.h>
 #include <android/log.h>
 #include "lib/CAndroidVMHelper.h"
-#elif !defined(VCMI_IOS)
-#include "../lib/Interprocess.h"
 #endif
 #include "../lib/VCMI_Lib.h"
 #include "../lib/VCMIDirs.h"
@@ -142,9 +140,9 @@ CVCMIServer::CVCMIServer(boost::program_options::variables_map & opts)
 	catch(...)
 	{
 		logNetwork->info("Port %d is busy, trying to use random port instead", port);
-		if(cmdLineOptions.count("run-by-client") && !cmdLineOptions.count("enable-shm"))
+		if(cmdLineOptions.count("run-by-client"))
 		{
-			logNetwork->error("Cant pass port number to client without shared memory!", port);
+			logNetwork->error("Port must be specified when run-by-client is used!!");
 			exit(0);
 		}
 		acceptor = std::make_shared<TAcceptor>(*io, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 0));
@@ -166,17 +164,6 @@ void CVCMIServer::run()
 	if(!restartGameplay)
 	{
 		this->announceLobbyThread = std::make_unique<boost::thread>(&CVCMIServer::threadAnnounceLobby, this);
-#if !defined(VCMI_MOBILE)
-		if(cmdLineOptions.count("enable-shm"))
-		{
-			std::string sharedMemoryName = "vcmi_memory";
-			if(cmdLineOptions.count("enable-shm-uuid") && cmdLineOptions.count("uuid"))
-			{
-				sharedMemoryName += "_" + cmdLineOptions["uuid"].as<std::string>();
-			}
-			shm = std::make_shared<SharedMemory>(sharedMemoryName);
-		}
-#endif
 
 		startAsyncAccept();
 		if(!remoteConnectionsThread && cmdLineOptions.count("lobby"))
@@ -189,11 +176,6 @@ void CVCMIServer::run()
 		CAndroidVMHelper vmHelper;
 		vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "onServerReady");
 #endif
-#elif !defined(VCMI_IOS)
-		if(shm)
-		{
-			shm->sr->setToReadyAndNotify(port);
-		}
 #endif
 	}
 
@@ -993,8 +975,6 @@ static void handleCommandOptions(int argc, const char * argv[], boost::program_o
 	("version,v", "display version information and exit")
 	("run-by-client", "indicate that server launched by client on same machine")
 	("uuid", po::value<std::string>(), "")
-	("enable-shm-uuid", "use UUID for shared memory identifier")
-	("enable-shm", "enable usage of shared memory")
 	("port", po::value<ui16>(), "port at which server will listen to connections from client")
 	("lobby", po::value<std::string>(), "address to remote lobby")
 	("lobby-port", po::value<ui16>(), "port at which server connect to remote lobby")
@@ -1007,7 +987,7 @@ static void handleCommandOptions(int argc, const char * argv[], boost::program_o
 		{
 			po::store(po::parse_command_line(argc, argv, opts), options);
 		}
-		catch(po::error & e)
+		catch(boost::program_options::error & e)
 		{
 			std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl;
 		}

+ 0 - 1
server/CVCMIServer.h

@@ -23,7 +23,6 @@ VCMI_LIB_NAMESPACE_BEGIN
 class CMapInfo;
 
 struct CPackForLobby;
-struct SharedMemory;
 
 struct StartInfo;
 struct LobbyInfo;