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

Refactoring of networking code on server and client

* Avoid server crash on dummy connect / disconnect.
* Avoid server crash when host left from PreGame.
* Server print it's state with name when it's waiting for connection or in pregame.
* Server will use random port if specified port is busy.
This commit is contained in:
Arseniy Shestakov
2016-12-04 12:54:26 +03:00
parent 9b867808a7
commit cc163c4e05
9 changed files with 120 additions and 79 deletions

View File

@@ -19,19 +19,22 @@
struct ServerReady
{
bool ready;
uint16_t port; //ui16?
boost::interprocess::interprocess_mutex mutex;
boost::interprocess::interprocess_condition cond;
ServerReady()
{
ready = false;
port = 0;
}
void setToTrueAndNotify()
void setToTrueAndNotify(uint16_t Port)
{
{
boost::unique_lock<boost::interprocess::interprocess_mutex> lock(mutex);
ready = true;
port = Port;
}
cond.notify_all();
}

View File

@@ -424,4 +424,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@@ -669,4 +669,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>

View File

@@ -191,8 +191,7 @@ void CConnection::close()
if(socket)
{
socket->close();
delete socket;
socket = nullptr;
vstd::clear_pointer(socket);
}
}