From d1621c8d4bad556a1b5cba150d2b5ec6fe6a1dbc Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 27 Jan 2013 21:29:36 -0800 Subject: [PATCH] track and log all packetIDs and acks, including number (but not type) of unacked packets. --- .../org/eehouse/android/xw4/RelayService.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java index 1b5a0d7d0..04afdcf0b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java @@ -33,6 +33,7 @@ import java.net.InetAddress; import java.net.Socket; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.concurrent.LinkedBlockingQueue; @@ -55,6 +56,9 @@ public class RelayService extends XWService { private static final String ROWID = "ROWID"; private static final String BINBUFFER = "BINBUFFER"; + private static HashSet s_packetsSent = new HashSet(); + private static int s_nextPacketID = 1; + private Thread m_fetchThread = null; private Thread m_UDPReadThread = null; private Thread m_UDPWriteThread = null; @@ -378,6 +382,9 @@ public class RelayService extends XWService { dis.read( msg ); postData( RelayService.this, token, msg ); break; + case XWPDEV_ACK: + noteAck( dis.readInt() ); + break; default: DbgUtils.logf( "RelayService: Unhandled cmd: %d", header.m_cmd ); @@ -503,7 +510,7 @@ public class RelayService extends XWService { { DataOutputStream out = new DataOutputStream( bas ); out.writeByte( XWPDEV_PROTO_VERSION ); - out.writeInt( 0 ); // packetID + out.writeInt( nextPacketID( cmd ) ); // packetID out.writeByte( cmd.ordinal() ); return out; } @@ -711,6 +718,28 @@ public class RelayService extends XWService { } } + private static int nextPacketID( XWRelayReg cmd ) + { + int nextPacketID = 0; + synchronized( s_packetsSent ) { + if ( XWRelayReg.XWPDEV_ACK != cmd ) { + nextPacketID = s_nextPacketID++; + s_packetsSent.add( nextPacketID ); + } + } + DbgUtils.logf( "nextPacketID(%s)=>%d", cmd.toString(), nextPacketID ); + return nextPacketID; + } + + private static void noteAck( int packetID ) + { + synchronized( s_packetsSent ) { + s_packetsSent.remove( packetID ); + DbgUtils.logf( "Got ack for %d; there are %d unacked packets", + packetID, s_packetsSent.size() ); + } + } + private class PacketHeader { public int m_packetID; public XWRelayReg m_cmd;