Game Development Reference
In-Depth Information
}
void BaseSocketManager::Shutdown()
{
// Get rid of all those pesky kids...
while (!m_SockList.empty())
{
delete *m_SockList.begin();
m_SockList.pop_front();
}
WSACleanup();
}
You
ve seen before that performing any task that can fail in a constructor is generally
a bad idea. Therefore, the socket manager class uses an initialization method that can
return a Boolean value. It also uses a Shutdown() method apart from the destructor
so you can have more control over the life and death of sockets in your application.
Once a NetSocket object exists, it is added to the socket manager with the
AddSocket() method. It adds the socket to the socket list, updates the map of
socket IDs to socket handles, and updates the maximum number of sockets opened.
The RemoveSocket() method removes the socket from the list and the map, and
then it frees the socket.
'
int BaseSocketManager::AddSocket(NetSocket *socket)
{
socket->m_id = m_NextSocketId;
m_SockMap[m_NextSocketId] = socket;
++m_NextSocketId;
m_SockList.push_front(socket);
if (m_SockList.size()) > m_MaxOpenSockets)
++m_MaxOpenSockets;
return socket->m_id;
}
void BaseSocketManager::RemoveSocket(NetSocket *socket)
{
m_SockList.remove(socket);
m_SockMap.erase(socket->m_id);
SAFE_DELETE(socket);
}
Your game needs a high-level function to send a packet to a particular socket ID.
High-level game systems certainly won
'
t care to have a direct reference to a socket
Search WWH ::




Custom Search