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 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.GameSummary;
|
||||||
import org.eehouse.android.xw4.jni.UtilCtxt;
|
import org.eehouse.android.xw4.jni.UtilCtxt;
|
||||||
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
|
||||||
|
|
||||||
public class RelayService extends XWService {
|
public class RelayService extends XWService {
|
||||||
private static final int MAX_SEND = 1024;
|
private static final int MAX_SEND = 1024;
|
||||||
|
@ -149,7 +150,7 @@ public class RelayService extends XWService {
|
||||||
DbgUtils.logf( "RelayService::onStartCommand::UDP_CHANGED" );
|
DbgUtils.logf( "RelayService::onStartCommand::UDP_CHANGED" );
|
||||||
if ( XWPrefs.getUDPEnabled( this ) ) {
|
if ( XWPrefs.getUDPEnabled( this ) ) {
|
||||||
stopFetchThreadIf();
|
stopFetchThreadIf();
|
||||||
startUDPThreads();
|
startUDPThreadsIfNot();
|
||||||
registerWithRelay();
|
registerWithRelay();
|
||||||
} else {
|
} else {
|
||||||
stopUDPThreadsIf();
|
stopUDPThreadsIf();
|
||||||
|
@ -158,6 +159,7 @@ public class RelayService extends XWService {
|
||||||
break;
|
break;
|
||||||
case SEND:
|
case SEND:
|
||||||
case RECEIVE:
|
case RECEIVE:
|
||||||
|
startUDPThreadsIfNot();
|
||||||
long rowid = intent.getLongExtra( ROWID, -1 );
|
long rowid = intent.getLongExtra( ROWID, -1 );
|
||||||
byte[] msg = intent.getByteArrayExtra( BINBUFFER );
|
byte[] msg = intent.getByteArrayExtra( BINBUFFER );
|
||||||
if ( SEND == cmd ) {
|
if ( SEND == cmd ) {
|
||||||
|
@ -220,18 +222,16 @@ public class RelayService extends XWService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startUDPThreads()
|
private void startUDPThreadsIfNot()
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "startUDPThreads" );
|
if ( XWPrefs.getUDPEnabled( this ) ) {
|
||||||
Assert.assertTrue( XWPrefs.getUDPEnabled( this ) );
|
|
||||||
|
|
||||||
if ( null == m_UDPSocket ) {
|
if ( null == m_UDPSocket ) {
|
||||||
int port = XWPrefs.getDefaultRelayPort( RelayService.this );
|
int port = XWPrefs.getDefaultRelayPort( RelayService.this );
|
||||||
String host = XWPrefs.getDefaultRelayHost( RelayService.this );
|
String host = XWPrefs.getDefaultRelayHost( RelayService.this );
|
||||||
try {
|
try {
|
||||||
m_UDPSocket = new DatagramSocket();
|
m_UDPSocket = new DatagramSocket();
|
||||||
InetAddress addr = InetAddress.getByName( host );
|
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 ) {
|
} catch( java.net.SocketException se ) {
|
||||||
DbgUtils.loge( se );
|
DbgUtils.loge( se );
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
|
@ -303,6 +303,7 @@ public class RelayService extends XWService {
|
||||||
DbgUtils.logf( "m_UDPWriteThread not null and assumed to be running" );
|
DbgUtils.logf( "m_UDPWriteThread not null and assumed to be running" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void stopUDPThreadsIf()
|
private void stopUDPThreadsIf()
|
||||||
{
|
{
|
||||||
|
@ -682,6 +683,14 @@ public class RelayService extends XWService {
|
||||||
|
|
||||||
/***** TransportProcs interface *****/
|
/***** 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 )
|
public boolean relayNoConnProc( byte[] buf, String relayID )
|
||||||
{
|
{
|
||||||
if ( -1 != m_rowid ) {
|
if ( -1 != m_rowid ) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue