Send from resend asyncTask using factored-out code in CommsTransport. Works for SMS at least.

This commit is contained in:
Eric House 2014-03-05 07:15:34 -08:00
parent 923ac6db98
commit 3daa877bee
2 changed files with 35 additions and 29 deletions

View file

@ -387,32 +387,18 @@ public class CommsTransport implements TransportProcs,
m_relayAddr = new CommsAddrRec( addr );
}
switch ( addr.conType ) {
case COMMS_CONN_RELAY:
if ( XWApp.UDP_ENABLED ) {
nSent = RelayService.sendPacket( m_context, m_rowid, buf );
} else {
if ( NetStateCache.netAvail( m_context ) ) {
putOut( buf ); // add to queue
if ( null == m_thread ) {
m_thread = new CommsThread();
m_thread.start();
}
nSent = buf.length;
if ( !XWApp.UDP_ENABLED
&& CommsConnType.COMMS_CONN_RELAY == addr.conType ) {
if ( NetStateCache.netAvail( m_context ) ) {
putOut( buf ); // add to queue
if ( null == m_thread ) {
m_thread = new CommsThread();
m_thread.start();
}
nSent = buf.length;
}
break;
case COMMS_CONN_SMS:
nSent = SMSService.sendPacket( m_context, addr.sms_phone,
gameID, buf );
break;
case COMMS_CONN_BT:
nSent = BTService.enqueueFor( m_context, buf, addr.bt_hostName,
addr.bt_btAddr, gameID );
break;
default:
Assert.fail();
break;
} else {
nSent = sendForAddr( m_context, addr, m_rowid, gameID, buf );
}
// Keep this while debugging why the resend_all that gets
@ -468,6 +454,30 @@ public class CommsTransport implements TransportProcs,
return false;
}
public static int sendForAddr( Context context, CommsAddrRec addr,
long rowID, int gameID, byte[] buf )
{
int nSent = -1;
switch ( addr.conType ) {
case COMMS_CONN_RELAY:
Assert.assertTrue( XWApp.UDP_ENABLED );
nSent = RelayService.sendPacket( context, rowID, buf );
break;
case COMMS_CONN_SMS:
nSent = SMSService.sendPacket( context, addr.sms_phone,
gameID, buf );
break;
case COMMS_CONN_BT:
nSent = BTService.enqueueFor( context, buf, addr.bt_hostName,
addr.bt_btAddr, gameID );
break;
default:
Assert.fail();
break;
}
return nSent;
}
/* NPEs in m_selector calls: sometimes my Moment gets into a state
* where after 15 or so seconds of Crosswords trying to connect to
* the relay I get a crash. Logs show it's inside one or both of
@ -477,5 +487,4 @@ public class CommsTransport implements TransportProcs,
* perhaps catch NPEs here just to be safe. But then do what?
* Tell user to restart device?
*/
}

View file

@ -1067,10 +1067,7 @@ public class GameUtils {
public int transportSend( byte[] buf, final CommsAddrRec addr, int gameID )
{
DbgUtils.logf( "ResendTask.MsgSink.transportSend: dropping message "
+ "of len %d on addr type %s", buf.length,
addr.conType.toString() );
return -1;
return CommsTransport.sendForAddr( m_context, addr, m_rowid, gameID, buf );
}
}
}