Re: A problem of UDP
Looks like you're not checking the return value from recvfrom. Even though
it's UDP you can get socket errors, e.g. if the other side has closed the
socket you're trying to send to. Probably the other side sends "ICMP
destination unreachable" and your read thread unblocks and just redisplays
the last message. In reality no data has been received. If you unplug the
cable you don't get the "unreachable" reply and nothing at all happens.
I recommend running Wireshark and looking at the packets going back and
forth.
Andrew
[...]
j=recvfrom(socket, (char *)buf, lenbuf, 0, (sockaddr *)&sa, (int
*)&i);
[ add this:]
if (j == 0)
{
// handle closed socket (may not happen in UDP)
}
else if (j== SOCKET_ERROR)
{
// handle socket errors
}
packet=(packet_t *)buf;
wcscpy(packet->m_peer.m_addr, M2W(inet_ntoa(sa.sin_addr)));
switch(packet->m_mark)
{
[snip]
default:
DBG(_T("MESSAGE, %s, %s, %s\n"), packet->m_peer.m_name, packet-
m_peer.m_addr, packet->m_msg);
SendMessage(wnd, WM_GOTMSG, 0, (LPARAM)&packet->m_id);
}
}
}
me->peer_op(htonl(-1), REMOVE_MARK, GUID_NULL);
DBG(_T("Pooling thread is exiting.\n"));
EXCEPTION_HANDLER_BEGIN(CChating_pooling_func_Fail, 0)
DBG(_T("Pooling thread will not continue due to the following
problems.\n"));
DBG(_T("%s\n"), M2T((char const *)*___e));
delete ___e;
return -1;
}