mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Guard against concurrent writes on same asio::socket instance
This commit is contained in:
		| @@ -88,6 +88,7 @@ void NetworkConnection::sendPacket(const std::vector<std::byte> & message) | ||||
| 	// create array with single element - boost::asio::buffer can be constructed from containers, but not from plain integer | ||||
| 	std::array<uint32_t, 1> messageSize{static_cast<uint32_t>(message.size())}; | ||||
|  | ||||
| 	boost::mutex::scoped_lock lock(writeMutex); | ||||
| 	boost::asio::write(*socket, boost::asio::buffer(messageSize), ec ); | ||||
| 	boost::asio::write(*socket, boost::asio::buffer(message), ec ); | ||||
|  | ||||
|   | ||||
| @@ -19,6 +19,7 @@ class NetworkConnection : public INetworkConnection, public std::enable_shared_f | ||||
| 	static const int messageMaxSize = 64 * 1024 * 1024; // arbitrary size to prevent potential massive allocation if we receive garbage input | ||||
|  | ||||
| 	std::shared_ptr<NetworkSocket> socket; | ||||
| 	boost::mutex writeMutex; | ||||
|  | ||||
| 	NetworkBuffer readBuffer; | ||||
| 	INetworkConnectionListener & listener; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user