mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
wifi tweaks
Show net status as failing when no sockets available, and notice when they're closed.
This commit is contained in:
parent
4389c63718
commit
930146cf11
2 changed files with 24 additions and 5 deletions
|
@ -133,7 +133,7 @@ public class BiDiSockWrap {
|
||||||
DbgUtils.logex( ioe );
|
DbgUtils.logex( ioe );
|
||||||
}
|
}
|
||||||
mIface.connectStateChanged( this, false );
|
mIface.connectStateChanged( this, false );
|
||||||
mQueue.add(null);
|
mQueue.add( new byte[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startThreads()
|
private void startThreads()
|
||||||
|
@ -150,7 +150,8 @@ public class BiDiSockWrap {
|
||||||
DbgUtils.logd( BiDiSockWrap.class,
|
DbgUtils.logd( BiDiSockWrap.class,
|
||||||
"write thread got packet of len %d",
|
"write thread got packet of len %d",
|
||||||
packet.length );
|
packet.length );
|
||||||
if ( null == packet || 0 == packet.length ) {
|
Assert.assertNotNull( packet );
|
||||||
|
if ( 0 == packet.length ) {
|
||||||
closeSocket();
|
closeSocket();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,9 +192,10 @@ public class WiDirService extends XWService {
|
||||||
|
|
||||||
public static String formatNetStateInfo()
|
public static String formatNetStateInfo()
|
||||||
{
|
{
|
||||||
return String.format( "name: %s; mac: %s; role: %s",
|
return String.format( "name: %s; mac: %s; role: %s; nThreads: %d",
|
||||||
sDeviceName, getMyMacAddress(),
|
sDeviceName, getMyMacAddress(),
|
||||||
sAmServer ? "group owner" : "guest" );
|
sAmServer ? "owner" : "guest",
|
||||||
|
Thread.activeCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getMyMacAddress() { return getMyMacAddress(null); }
|
private static String getMyMacAddress() { return getMyMacAddress(null); }
|
||||||
|
@ -232,6 +233,7 @@ public class WiDirService extends XWService {
|
||||||
public static int sendPacket( Context context, String macAddr, int gameID,
|
public static int sendPacket( Context context, String macAddr, int gameID,
|
||||||
byte[] buf )
|
byte[] buf )
|
||||||
{
|
{
|
||||||
|
DbgUtils.logd( CLAZZ, "sendPacket(len=%d,addr=%s)", buf.length, macAddr );
|
||||||
int nSent = -1;
|
int nSent = -1;
|
||||||
|
|
||||||
boolean[] forwarding = { false };
|
boolean[] forwarding = { false };
|
||||||
|
@ -314,6 +316,7 @@ public class WiDirService extends XWService {
|
||||||
|
|
||||||
public void connectStateChanged( BiDiSockWrap wrap, boolean nowConnected )
|
public void connectStateChanged( BiDiSockWrap wrap, boolean nowConnected )
|
||||||
{
|
{
|
||||||
|
DbgUtils.logd( CLAZZ, "connectStateChanged(con=%b)", nowConnected );
|
||||||
if ( nowConnected ) {
|
if ( nowConnected ) {
|
||||||
try {
|
try {
|
||||||
wrap.send( new JSONObject()
|
wrap.send( new JSONObject()
|
||||||
|
@ -323,6 +326,15 @@ public class WiDirService extends XWService {
|
||||||
} catch ( JSONException jse ) {
|
} catch ( JSONException jse ) {
|
||||||
DbgUtils.logex( jse );
|
DbgUtils.logex( jse );
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
int sizeBefore = sSocketWrapMap.size();
|
||||||
|
sSocketWrapMap.values().remove( wrap );
|
||||||
|
DbgUtils.logd( CLAZZ, "removed wrap; had %d, now have %d",
|
||||||
|
sizeBefore, sSocketWrapMap.size() );
|
||||||
|
if ( 0 == sSocketWrapMap.size() ) {
|
||||||
|
updateStatusIn( false );
|
||||||
|
updateStatusOut( false );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,6 +369,7 @@ public class WiDirService extends XWService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DbgUtils.logd( CLAZZ, "thread count: %d", Thread.activeCount() );
|
||||||
new Handler().postDelayed( new Runnable() {
|
new Handler().postDelayed( new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -470,7 +483,9 @@ public class WiDirService extends XWService {
|
||||||
discoverServices();
|
discoverServices();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(int code) { Assert.fail(); }
|
public void onFailure(int code) {
|
||||||
|
tryAgain( "discoverPeers", code );
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,6 +803,9 @@ public class WiDirService extends XWService {
|
||||||
forwarding[0] = true;
|
forwarding[0] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( null == wrap ) {
|
||||||
|
updateStatusOut( false );
|
||||||
|
}
|
||||||
return wrap;
|
return wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue