mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-01 19:57:11 +01:00
always try starting UDP threads in case Service has been stopped;
implement transportSend in RelayMsgSink since relay-connection packets need it.
This commit is contained in:
parent
c8b3050c8d
commit
f91af77438
1 changed files with 84 additions and 75 deletions
|
@ -38,9 +38,10 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||
import org.eehouse.android.xw4.jni.GameSummary;
|
||||
import org.eehouse.android.xw4.jni.UtilCtxt;
|
||||
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
||||
|
||||
public class RelayService extends XWService {
|
||||
private static final int MAX_SEND = 1024;
|
||||
|
@ -149,7 +150,7 @@ public class RelayService extends XWService {
|
|||
DbgUtils.logf( "RelayService::onStartCommand::UDP_CHANGED" );
|
||||
if ( XWPrefs.getUDPEnabled( this ) ) {
|
||||
stopFetchThreadIf();
|
||||
startUDPThreads();
|
||||
startUDPThreadsIfNot();
|
||||
registerWithRelay();
|
||||
} else {
|
||||
stopUDPThreadsIf();
|
||||
|
@ -158,6 +159,7 @@ public class RelayService extends XWService {
|
|||
break;
|
||||
case SEND:
|
||||
case RECEIVE:
|
||||
startUDPThreadsIfNot();
|
||||
long rowid = intent.getLongExtra( ROWID, -1 );
|
||||
byte[] msg = intent.getByteArrayExtra( BINBUFFER );
|
||||
if ( SEND == cmd ) {
|
||||
|
@ -220,18 +222,16 @@ public class RelayService extends XWService {
|
|||
}
|
||||
}
|
||||
|
||||
private void startUDPThreads()
|
||||
private void startUDPThreadsIfNot()
|
||||
{
|
||||
DbgUtils.logf( "startUDPThreads" );
|
||||
Assert.assertTrue( XWPrefs.getUDPEnabled( this ) );
|
||||
|
||||
if ( XWPrefs.getUDPEnabled( this ) ) {
|
||||
if ( null == m_UDPSocket ) {
|
||||
int port = XWPrefs.getDefaultRelayPort( RelayService.this );
|
||||
String host = XWPrefs.getDefaultRelayHost( RelayService.this );
|
||||
try {
|
||||
m_UDPSocket = new DatagramSocket();
|
||||
InetAddress addr = InetAddress.getByName( host );
|
||||
m_UDPSocket.connect( addr, port ); // meaning: remember this address
|
||||
m_UDPSocket.connect( addr, port ); // remember this address
|
||||
} catch( java.net.SocketException se ) {
|
||||
DbgUtils.loge( se );
|
||||
Assert.fail();
|
||||
|
@ -303,6 +303,7 @@ public class RelayService extends XWService {
|
|||
DbgUtils.logf( "m_UDPWriteThread not null and assumed to be running" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void stopUDPThreadsIf()
|
||||
{
|
||||
|
@ -682,6 +683,14 @@ public class RelayService extends XWService {
|
|||
|
||||
/***** TransportProcs interface *****/
|
||||
|
||||
public int transportSend( byte[] buf, final CommsAddrRec addr,
|
||||
int gameID )
|
||||
{
|
||||
Assert.assertTrue( -1 != m_rowid );
|
||||
sendPacket( RelayService.this, m_rowid, buf );
|
||||
return buf.length;
|
||||
}
|
||||
|
||||
public boolean relayNoConnProc( byte[] buf, String relayID )
|
||||
{
|
||||
if ( -1 != m_rowid ) {
|
||||
|
|
Loading…
Add table
Reference in a new issue