本文整理汇总了C++中Connection::ReceiveMessages方法的典型用法代码示例。如果您正苦于以下问题:C++ Connection::ReceiveMessages方法的具体用法?C++ Connection::ReceiveMessages怎么用?C++ Connection::ReceiveMessages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::ReceiveMessages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReceiveAllMessages
// Go through all connections and read any incoming commands from the sockets.
// The messages are sent to the callback registered with the connection when it was created (ReceivedCall currently).
// Those calls could take a long time to execute (e.g. a call to Run Soar).
// Returns true if we received at least one message.
bool ConnectionManager::ReceiveAllMessages()
{
int index = 0 ;
bool receivedOneMessage = false ;
// We need to search this list of connections and call each in turn.
// But we also want to allow the listener thread to add new connections while we're doing this.
// (E.g. we might want to attach a debugger to a process that's already executing a "run" command inside "receiveMessages").
// So we use this slightly cumbersome approach of looking up the connection based on an integer index.
// The lookup is thread safe and if the connection list changes between lookups that's fine as this function
// will return NULL once we go out of bounds. (You could argue that we might miss calling a connection on a particular pass using this method
// but that should be ok).
Connection* pConnection = GetConnectionByIndex(index++) ;
while (pConnection)
{
// Check to see if this connection has already been closed
// (which includes if the other side has dropped its half of the socket)
if (!pConnection->IsClosed())
{
receivedOneMessage = pConnection->ReceiveMessages(true) || receivedOneMessage ;
}
else
{
// If the connection has closed, delete it from the list of active connections
RemoveConnection(pConnection) ;
// Remove any events that this connection is listening to
KernelSML* pKernelSML = static_cast<KernelSML*>(pConnection->GetUserData());
pKernelSML->RemoveAllListeners(pConnection) ;
// Not clear that we can just delete connections as we might be inside a connection callback
// when the shutdown comes. So for safety, move connections to a closed list instead of deleting.
// For now this will leak the connection object. Later if we are confident we can delete this list.
//delete pConnection ;
m_ClosedConnections.push_back(pConnection) ;
// Since we just removed this connection we should look up the same index value again
// so we don't skip any. This isn't really that important.
index-- ;
}
// Get the next connection (will return NULL once we reach the end of the list)
pConnection = GetConnectionByIndex(index++) ;
}
// So far we don't have some sort of shutdown message the remote connections
// can send, but if we decide to implement it this allows us to return it.
return receivedOneMessage ;
}