When creating a network game, a client is also started.
Network errors are handled globally. Fixed last network thread issue by using a notification queue, should work fine now.
This commit is contained in:
@@ -54,13 +54,6 @@ ServerRecvThread::~ServerRecvThread()
|
||||
CleanupSessionMap();
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvThread::StartGame()
|
||||
{
|
||||
// TODO: not thread safe. use flag or something.
|
||||
SetState(SERVER_START_GAME_STATE::Instance());
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvThread::SendToAllPlayers(boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
@@ -85,6 +78,13 @@ ServerRecvThread::AddConnection(boost::shared_ptr<ConnectData> data)
|
||||
m_connectQueue.push_back(data);
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvThread::AddNotification(unsigned notification)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_notificationQueueMutex);
|
||||
m_notificationQueue.push_back(notification);
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvThread::Main()
|
||||
{
|
||||
@@ -96,6 +96,7 @@ ServerRecvThread::Main()
|
||||
while (!ShouldTerminate())
|
||||
{
|
||||
{
|
||||
// Handle one incoming connection at a time.
|
||||
boost::shared_ptr<ConnectData> tmpData;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_connectQueueMutex);
|
||||
@@ -108,7 +109,10 @@ ServerRecvThread::Main()
|
||||
if (tmpData.get())
|
||||
GetState().HandleNewConnection(*this, tmpData);
|
||||
}
|
||||
// Process current state.
|
||||
GetState().Process(*this);
|
||||
// Process thread-safe notifications.
|
||||
NotificationLoop();
|
||||
}
|
||||
} catch (const NetException &)
|
||||
{
|
||||
@@ -121,6 +125,25 @@ ServerRecvThread::Main()
|
||||
CleanupSessionMap();
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvThread::NotificationLoop()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_notificationQueueMutex);
|
||||
// Process all notifications.
|
||||
while (!m_notificationQueue.empty())
|
||||
{
|
||||
unsigned notification = m_notificationQueue.front();
|
||||
m_notificationQueue.pop_front();
|
||||
|
||||
switch(notification)
|
||||
{
|
||||
case NOTIFY_GAME_START:
|
||||
SetState(SERVER_START_GAME_STATE::Instance());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SOCKET
|
||||
ServerRecvThread::Select()
|
||||
{
|
||||
@@ -139,7 +162,7 @@ ServerRecvThread::Select()
|
||||
{
|
||||
SOCKET tmpSock = i->first;
|
||||
FD_SET(tmpSock, &rdset);
|
||||
if (tmpSock > maxSock)
|
||||
if (tmpSock > maxSock || maxSock == INVALID_SOCKET)
|
||||
maxSock = tmpSock;
|
||||
++i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user