mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +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 );
|
||||
}
|
||||
mIface.connectStateChanged( this, false );
|
||||
mQueue.add(null);
|
||||
mQueue.add( new byte[0] );
|
||||
}
|
||||
|
||||
private void startThreads()
|
||||
|
@ -150,7 +150,8 @@ public class BiDiSockWrap {
|
|||
DbgUtils.logd( BiDiSockWrap.class,
|
||||
"write thread got packet of len %d",
|
||||
packet.length );
|
||||
if ( null == packet || 0 == packet.length ) {
|
||||
Assert.assertNotNull( packet );
|
||||
if ( 0 == packet.length ) {
|
||||
closeSocket();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -192,9 +192,10 @@ public class WiDirService extends XWService {
|
|||
|
||||
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(),
|
||||
sAmServer ? "group owner" : "guest" );
|
||||
sAmServer ? "owner" : "guest",
|
||||
Thread.activeCount() );
|
||||
}
|
||||
|
||||
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,
|
||||
byte[] buf )
|
||||
{
|
||||
DbgUtils.logd( CLAZZ, "sendPacket(len=%d,addr=%s)", buf.length, macAddr );
|
||||
int nSent = -1;
|
||||
|
||||
boolean[] forwarding = { false };
|
||||
|
@ -314,6 +316,7 @@ public class WiDirService extends XWService {
|
|||
|
||||
public void connectStateChanged( BiDiSockWrap wrap, boolean nowConnected )
|
||||
{
|
||||
DbgUtils.logd( CLAZZ, "connectStateChanged(con=%b)", nowConnected );
|
||||
if ( nowConnected ) {
|
||||
try {
|
||||
wrap.send( new JSONObject()
|
||||
|
@ -323,6 +326,15 @@ public class WiDirService extends XWService {
|
|||
} catch ( JSONException 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() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -470,7 +483,9 @@ public class WiDirService extends XWService {
|
|||
discoverServices();
|
||||
}
|
||||
@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;
|
||||
}
|
||||
|
||||
if ( null == wrap ) {
|
||||
updateStatusOut( false );
|
||||
}
|
||||
return wrap;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue