mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
put Killer back: device can receive but never process
A device where the OS isn't servicing enqueueWork() requests won't write back to sockets it accept()s, causing the sender's writer to block forever. So give it 30 seconds then kill the socket.
This commit is contained in:
parent
274e7c6c4b
commit
c822f4b1a6
1 changed files with 31 additions and 2 deletions
|
@ -1075,6 +1075,35 @@ public class BTService extends XWJIService {
|
|||
.updateStatusIn( context, null, CommsConnType.COMMS_CONN_BT, success );
|
||||
}
|
||||
|
||||
private static class KillerIn extends Thread implements AutoCloseable {
|
||||
private int mSeconds;
|
||||
private java.io.Closeable mSocket;
|
||||
|
||||
KillerIn( final java.io.Closeable socket, final int seconds )
|
||||
{
|
||||
mSeconds = seconds;
|
||||
mSocket = socket;
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try {
|
||||
Thread.sleep( 1000 * mSeconds );
|
||||
Log.d( TAG, "KillerIn(): time's up; closing socket" );
|
||||
mSocket.close();
|
||||
} catch ( InterruptedException ie ) {
|
||||
// Log.d( TAG, "KillerIn: killed by owner" );
|
||||
} catch( IOException ioe ) {
|
||||
Log.ex( TAG, ioe );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() { interrupt(); }
|
||||
}
|
||||
|
||||
private class BTMsgSink extends MultiMsgSink {
|
||||
|
||||
public BTMsgSink() { super( BTService.this ); }
|
||||
|
@ -1295,7 +1324,7 @@ public class BTService extends XWJIService {
|
|||
int nDone = 0;
|
||||
if ( null != localElems ) {
|
||||
Log.d( TAG, "writeAndCheck(): reading %d replies", localElems.size() );
|
||||
try {
|
||||
try ( KillerIn ki = new KillerIn( socket, 30 ) ) {
|
||||
DataInputStream inStream =
|
||||
new DataInputStream( socket.getInputStream() );
|
||||
for ( int ii = 0; ii < localElems.size(); ++ii ) {
|
||||
|
@ -1314,7 +1343,7 @@ public class BTService extends XWJIService {
|
|||
++nDone;
|
||||
}
|
||||
} catch ( IOException ioe ) {
|
||||
Log.d( TAG, "failed reading replies: %s", ioe.getMessage() );
|
||||
Log.d( TAG, "failed reading replies for %s: %s", this, ioe.getMessage() );
|
||||
}
|
||||
}
|
||||
unappend( nDone );
|
||||
|
|
Loading…
Add table
Reference in a new issue