mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
wip: toward being able to resend ACKs again
This commit is contained in:
parent
d134077d87
commit
7099a7627a
1 changed files with 42 additions and 23 deletions
|
@ -100,8 +100,8 @@ public class RelayService extends XWService
|
||||||
private static final String ROWID = "ROWID";
|
private static final String ROWID = "ROWID";
|
||||||
private static final String BINBUFFER = "BINBUFFER";
|
private static final String BINBUFFER = "BINBUFFER";
|
||||||
|
|
||||||
private static Map<Integer, PacketData> s_packetsSentUDP = new HashMap<>();
|
private static List<PacketData> s_packetsSentUDP = new ArrayList<>();
|
||||||
private static Map<Integer, PacketData> s_packetsSentWeb = new HashMap<>();
|
private static List<PacketData> s_packetsSentWeb = new ArrayList<>();
|
||||||
private static AtomicInteger s_nextPacketID = new AtomicInteger();
|
private static AtomicInteger s_nextPacketID = new AtomicInteger();
|
||||||
private static boolean s_gcmWorking = false;
|
private static boolean s_gcmWorking = false;
|
||||||
private static boolean s_registered = false;
|
private static boolean s_registered = false;
|
||||||
|
@ -619,7 +619,7 @@ public class RelayService extends XWService
|
||||||
private boolean skipNativeSend()
|
private boolean skipNativeSend()
|
||||||
{
|
{
|
||||||
boolean skip = m_nativeFailScore > 10 || m_skipUPDSet;
|
boolean skip = m_nativeFailScore > 10 || m_skipUPDSet;
|
||||||
// Log.d( TAG, "skipNativeSend(score=%d)) => %b", m_nativeFailScore, skip );
|
Log.d( TAG, "skipNativeSend(score=%d)) => %b", m_nativeFailScore, skip );
|
||||||
return skip;
|
return skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,14 +776,20 @@ public class RelayService extends XWService
|
||||||
m_lastRunMS = nowMS;
|
m_lastRunMS = nowMS;
|
||||||
|
|
||||||
long minSentMS = nowMS - 10000; // 10 seconds ago
|
long minSentMS = nowMS - 10000; // 10 seconds ago
|
||||||
|
long prevSentMS = 0;
|
||||||
List<PacketData> forResend = new ArrayList<>();
|
List<PacketData> forResend = new ArrayList<>();
|
||||||
boolean foundNonAck = false;
|
boolean foundNonAck = false;
|
||||||
synchronized ( s_packetsSentUDP ) {
|
synchronized ( s_packetsSentUDP ) {
|
||||||
Iterator<Map.Entry<Integer, PacketData>> iter;
|
Iterator<PacketData> iter;
|
||||||
for ( iter = s_packetsSentUDP.entrySet().iterator(); iter.hasNext(); ) {
|
for ( iter = s_packetsSentUDP.iterator(); iter.hasNext(); ) {
|
||||||
Map.Entry<Integer, PacketData> entry = iter.next();
|
PacketData packet = iter.next();
|
||||||
PacketData packet = entry.getValue();
|
long sentMS = packet.getSentMS();
|
||||||
if ( packet.getSentMS() < minSentMS ) {
|
Assert.assertTrue( prevSentMS <= sentMS );
|
||||||
|
prevSentMS = sentMS;
|
||||||
|
if ( sentMS > minSentMS ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
forResend.add( packet );
|
forResend.add( packet );
|
||||||
if ( packet.m_cmd != XWRelayReg.XWPDEV_ACK ) {
|
if ( packet.m_cmd != XWRelayReg.XWPDEV_ACK ) {
|
||||||
foundNonAck = true;
|
foundNonAck = true;
|
||||||
|
@ -791,7 +797,6 @@ public class RelayService extends XWService
|
||||||
}
|
}
|
||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Log.d( TAG, "runUDPAckTimer(): %d too-new packets remaining",
|
Log.d( TAG, "runUDPAckTimer(): %d too-new packets remaining",
|
||||||
s_packetsSentUDP.size() );
|
s_packetsSentUDP.size() );
|
||||||
}
|
}
|
||||||
|
@ -809,22 +814,25 @@ public class RelayService extends XWService
|
||||||
|
|
||||||
private void noteSent( PacketData packet, boolean fromUDP )
|
private void noteSent( PacketData packet, boolean fromUDP )
|
||||||
{
|
{
|
||||||
Map<Integer, PacketData> map = fromUDP ? s_packetsSentUDP : s_packetsSentWeb;
|
|
||||||
int pid = packet.m_packetID;
|
|
||||||
Log.d( TAG, "Sent [udp?] packet: cmd=%s, id=%d",
|
Log.d( TAG, "Sent [udp?] packet: cmd=%s, id=%d",
|
||||||
packet.m_cmd.toString(), pid );
|
packet.m_cmd.toString(), packet.m_packetID );
|
||||||
if ( !fromUDP || packet.m_cmd != XWRelayReg.XWPDEV_ACK ) {
|
if ( !fromUDP || packet.m_cmd != XWRelayReg.XWPDEV_ACK ) {
|
||||||
synchronized( map ) {
|
List<PacketData> list = fromUDP ? s_packetsSentUDP : s_packetsSentWeb;
|
||||||
map.put( pid, packet );
|
synchronized( list ) {
|
||||||
|
list.add(packet );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void noteSent( List<PacketData> packets, boolean fromUDP )
|
private void noteSent( List<PacketData> packets, boolean fromUDP )
|
||||||
{
|
{
|
||||||
|
List<PacketData> map = fromUDP ? s_packetsSentUDP : s_packetsSentWeb;
|
||||||
|
Log.d( TAG, "noteSent(): adding %d; size before: %d",
|
||||||
|
packets.size(), map.size() );
|
||||||
for ( PacketData packet : packets ) {
|
for ( PacketData packet : packets ) {
|
||||||
noteSent( packet, fromUDP );
|
noteSent( packet, fromUDP );
|
||||||
}
|
}
|
||||||
|
Log.d( TAG, "noteSent(): size after: %d", map.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopUDPThreadsIf()
|
private void stopUDPThreadsIf()
|
||||||
|
@ -1385,9 +1393,20 @@ public class RelayService extends XWService
|
||||||
|
|
||||||
private void noteAck( int packetID, boolean fromUDP )
|
private void noteAck( int packetID, boolean fromUDP )
|
||||||
{
|
{
|
||||||
Map<Integer, PacketData> map = fromUDP ? s_packetsSentUDP : s_packetsSentWeb;
|
Assert.assertTrue( packetID != 0 );
|
||||||
|
List<PacketData> map = fromUDP ? s_packetsSentUDP : s_packetsSentWeb;
|
||||||
synchronized( map ) {
|
synchronized( map ) {
|
||||||
PacketData packet = map.remove( packetID );
|
PacketData packet = null;
|
||||||
|
Iterator<PacketData> iter = map.iterator();
|
||||||
|
for ( iter = map.iterator(); iter.hasNext(); ) {
|
||||||
|
PacketData next = iter.next();
|
||||||
|
if ( next.m_packetID == packetID ) {
|
||||||
|
packet = next;
|
||||||
|
iter.remove();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( packet != null ) {
|
if ( packet != null ) {
|
||||||
// Log.d( TAG, "noteAck(fromUDP=%b): removed for id %d: %s",
|
// Log.d( TAG, "noteAck(fromUDP=%b): removed for id %d: %s",
|
||||||
// fromUDP, packetID, packet );
|
// fromUDP, packetID, packet );
|
||||||
|
@ -1399,8 +1418,8 @@ public class RelayService extends XWService
|
||||||
}
|
}
|
||||||
if ( BuildConfig.DEBUG ) {
|
if ( BuildConfig.DEBUG ) {
|
||||||
ArrayList<String> pstrs = new ArrayList<>();
|
ArrayList<String> pstrs = new ArrayList<>();
|
||||||
for ( Integer pkid : map.keySet() ) {
|
for ( PacketData datum : map ) {
|
||||||
pstrs.add( map.get(pkid).toString() );
|
pstrs.add( String.format("%d", datum.m_packetID ) );
|
||||||
}
|
}
|
||||||
Log.d( TAG, "noteAck(fromUDP=%b): Got ack for %d; there are %d unacked packets: %s",
|
Log.d( TAG, "noteAck(fromUDP=%b): Got ack for %d; there are %d unacked packets: %s",
|
||||||
fromUDP, packetID, map.size(), TextUtils.join( ",", pstrs ) );
|
fromUDP, packetID, map.size(), TextUtils.join( ",", pstrs ) );
|
||||||
|
|
Loading…
Reference in a new issue