J
John
Hi, all
This is a question about the iterator on list
In this code below, I check the time out for all the connected socket in a
list. The list keep the point of each connected socket object, i.e,
list<CChatSocket*> In code CheckConnections(), if the connection time out,
it call process_time_out.
The problem I am facing is,
The program assert on line B, if line C is not comment out. Is shows that
iter is not valid anymore after calling process_time_out(). However, when I
comment out line C, the program runs OK.
Dose anyone can tell why cout has effect on the iterator? Or I just totally
missed something.
static void CChatSocket::CheckConnections(
PVOID lpParameter,
BOOLEAN TimerOrWaitFired
)
{
ASSERT(lpParameter == NULL);
ASSERT(TimerOrWaitFired);
list<CChatSocket*>::iterator iter;
for (iter = m_socketList.begin(); iter != m_socketList.end(); )
{
CChatSocket* pSocket = *iter;
if (is_time_out(pSocket))
{
process_time_out(pSocket); // *** line A
iter = m_socketList.erase(iter); // *** line B
}
else
{
++ iter;
}
}
}
static void CChatSocket:rocess_time_out(CChatSocket* pSocket)
{
pSocket->Shutdown();
pSocket->Close();
pSocket->Release();
cout << "socket disconnected becasue of timeout" << endl; // *** line C
}
Thank,
John
This is a question about the iterator on list
In this code below, I check the time out for all the connected socket in a
list. The list keep the point of each connected socket object, i.e,
list<CChatSocket*> In code CheckConnections(), if the connection time out,
it call process_time_out.
The problem I am facing is,
The program assert on line B, if line C is not comment out. Is shows that
iter is not valid anymore after calling process_time_out(). However, when I
comment out line C, the program runs OK.
Dose anyone can tell why cout has effect on the iterator? Or I just totally
missed something.
static void CChatSocket::CheckConnections(
PVOID lpParameter,
BOOLEAN TimerOrWaitFired
)
{
ASSERT(lpParameter == NULL);
ASSERT(TimerOrWaitFired);
list<CChatSocket*>::iterator iter;
for (iter = m_socketList.begin(); iter != m_socketList.end(); )
{
CChatSocket* pSocket = *iter;
if (is_time_out(pSocket))
{
process_time_out(pSocket); // *** line A
iter = m_socketList.erase(iter); // *** line B
}
else
{
++ iter;
}
}
}
static void CChatSocket:rocess_time_out(CChatSocket* pSocket)
{
pSocket->Shutdown();
pSocket->Close();
pSocket->Release();
cout << "socket disconnected becasue of timeout" << endl; // *** line C
}
Thank,
John