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:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -424,4 +424,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -669,4 +669,4 @@
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -191,8 +191,7 @@ void CConnection::close()
|
||||
if(socket)
|
||||
{
|
||||
socket->close();
|
||||
delete socket;
|
||||
socket = nullptr;
|
||||
vstd::clear_pointer(socket);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user