mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
fix crash processing multiple packets
When grouping to allow multiple packets per outbound API call I forgot that some are there to mark the end-of-queue: can't be sent! Trying caused a NPE. Now if any EOQ is found in the queue that batch is dropped and the thread's exited.
This commit is contained in:
parent
701e6968de
commit
d1a5a94740
1 changed files with 13 additions and 5 deletions
|
@ -618,13 +618,18 @@ public class RelayService extends XWService
|
|||
for ( ; ; ) {
|
||||
List<PacketData> dataList = null;
|
||||
try {
|
||||
PacketData outData = m_queue.take();
|
||||
if ( null != outData ) {
|
||||
dataList = new ArrayList<>();
|
||||
dataList.add(outData);
|
||||
m_queue.drainTo(dataList);
|
||||
for ( PacketData outData = m_queue.take(); // blocks
|
||||
null != outData;
|
||||
outData = m_queue.poll() ) { // doesn't block
|
||||
if ( outData.isEOQ() ) {
|
||||
dataList = null;
|
||||
break;
|
||||
}
|
||||
dataList.add(outData);
|
||||
Log.d( TAG, "got %d packets; %d more left", dataList.size(),
|
||||
m_queue.size());
|
||||
}
|
||||
Log.d( TAG, "got %d packets; %d more left", dataList.size(), m_queue.size());
|
||||
} catch ( InterruptedException ie ) {
|
||||
Log.w( TAG, "write thread killed" );
|
||||
break;
|
||||
|
@ -665,6 +670,7 @@ public class RelayService extends XWService
|
|||
try {
|
||||
JSONArray dataArray = new JSONArray();
|
||||
for ( PacketData packet : packets ) {
|
||||
Assert.assertFalse( packet.isEOQ() );
|
||||
byte[] datum = packet.assemble();
|
||||
dataArray.put( Utils.base64Encode(datum) );
|
||||
sentLen += datum.length;
|
||||
|
@ -1554,6 +1560,8 @@ public class RelayService extends XWService
|
|||
System.currentTimeMillis() - m_created );
|
||||
}
|
||||
|
||||
public boolean isEOQ() { return 0 == getLength(); }
|
||||
|
||||
public int getLength()
|
||||
{
|
||||
int result = 0;
|
||||
|
|
Loading…
Reference in a new issue