Merge remote-tracking branch 'origin/gtk_multigame' into gtk_multigame

This commit is contained in:
Eric House 2013-01-28 06:53:17 -08:00
commit 339ec66844
3 changed files with 26 additions and 6 deletions

View file

@ -23,13 +23,17 @@
UDPAckTrack* UDPAckTrack::s_self = NULL;
/* static*/ bool
UDPAckTrack::shouldAck( XWRelayReg cmd )
{
return ( XWPDEV_ACK != cmd && XWPDEV_ALERT != cmd );
}
/* static*/ uint32_t
UDPAckTrack::nextPacketID( XWRelayReg cmd )
{
uint32_t result;
if ( XWPDEV_ACK == cmd || XWPDEV_ALERT == cmd ) {
result = 0;
} else {
uint32_t result = 0;
if ( shouldAck( cmd ) ) {
result = get()->nextPacketIDImpl();
}
return result;
@ -115,9 +119,10 @@ UDPAckTrack::threadProc()
}
string_printf( leaked, ", " );
}
logf( XW_LOGERROR, "these packets leaked: %s", leaked.c_str() );
logf( XW_LOGERROR, "%s: these packets leaked: %s", __func__,
leaked.c_str() );
} else {
logf( XW_LOGINFO, "no packets leaked" );
logf( XW_LOGINFO, "%s: no packets leaked", __func__ );
}
}
return NULL;

View file

@ -33,6 +33,7 @@ class UDPAckTrack {
public:
static uint32_t nextPacketID( XWRelayReg cmd );
static void recordAck( uint32_t packetID );
static bool shouldAck( XWRelayReg cmd );
private:
static UDPAckTrack* get();

View file

@ -1293,6 +1293,18 @@ msgToStr( XWRelayReg msg )
}
static void
ackPacketIf( const UDPHeader* header, const AddrInfo* addr )
{
if ( UDPAckTrack::shouldAck( header->cmd ) ) {
uint32_t packetID = header->packetID;
logf( XW_LOGINFO, "acking packet %d", packetID );
packetID = htonl( packetID );
send_via_udp( addr->socket(), addr->sockaddr(), XWPDEV_ACK,
&packetID, sizeof(packetID), NULL );
}
}
static void
udp_thread_proc( UdpThreadClosure* utc )
{
@ -1302,6 +1314,7 @@ udp_thread_proc( UdpThreadClosure* utc )
UDPHeader header;
if ( getHeader( &ptr, end, &header ) ) {
logf( XW_LOGINFO, "%s(msg=%s)", __func__, msgToStr( header.cmd ) );
ackPacketIf( &header, utc->addr() );
switch( header.cmd ) {
case XWPDEV_REG: {
DevIDType typ = (DevIDType)*ptr++;
@ -1375,6 +1388,7 @@ udp_thread_proc( UdpThreadClosure* utc )
case XWPDEV_ACK: {
uint32_t packetID;
if ( getNetLong( &ptr, end, &packetID ) ) {
logf( XW_LOGINFO, "ack for packet %d", packetID );
UDPAckTrack::recordAck( packetID );
}
break;