move socket creation inside Thread's run() in attempt to fix too-long

UI freeze when deleting individual games.
This commit is contained in:
Andy2 2011-06-07 20:51:26 -07:00 committed by Andy2
parent ae0860a047
commit 248b341aac

View file

@ -65,18 +65,16 @@ public class NetUtils {
private static class InformThread extends Thread { private static class InformThread extends Thread {
Context m_context; Context m_context;
private Socket m_socket;
DBUtils.Obit[] m_obits; DBUtils.Obit[] m_obits;
public InformThread( Context context, DBUtils.Obit[] obits, public InformThread( Context context, DBUtils.Obit[] obits )
Socket socket )
{ {
m_context = context; m_context = context;
m_obits = obits; m_obits = obits;
m_socket = socket;
} }
public void run() { public void run() {
Socket socket = MakeProxySocket( m_context, 10000 );
if ( null != socket ) {
int strLens = 0; int strLens = 0;
for ( int ii = 0; ii < m_obits.length; ++ii ) { for ( int ii = 0; ii < m_obits.length; ++ii ) {
strLens += m_obits[ii].m_relayID.length() + 1; // 1 for /n strLens += m_obits[ii].m_relayID.length() + 1; // 1 for /n
@ -84,7 +82,7 @@ public class NetUtils {
try { try {
DataOutputStream outStream = DataOutputStream outStream =
new DataOutputStream( m_socket.getOutputStream() ); new DataOutputStream( socket.getOutputStream() );
outStream.writeShort( 2 + 2 + (2*m_obits.length) + strLens ); outStream.writeShort( 2 + 2 + (2*m_obits.length) + strLens );
outStream.writeByte( NetUtils.PROTOCOL_VERSION ); outStream.writeByte( NetUtils.PROTOCOL_VERSION );
outStream.writeByte( NetUtils.PRX_DEVICE_GONE ); outStream.writeByte( NetUtils.PRX_DEVICE_GONE );
@ -99,9 +97,9 @@ public class NetUtils {
outStream.flush(); outStream.flush();
DataInputStream dis = DataInputStream dis =
new DataInputStream( m_socket.getInputStream() ); new DataInputStream( socket.getInputStream() );
short resLen = dis.readShort(); short resLen = dis.readShort();
m_socket.close(); socket.close();
if ( resLen == 0 ) { if ( resLen == 0 ) {
DBUtils.clearObits( m_context, m_obits ); DBUtils.clearObits( m_context, m_obits );
@ -109,7 +107,7 @@ public class NetUtils {
} catch ( java.io.IOException ioe ) { } catch ( java.io.IOException ioe ) {
Utils.logf( ioe.toString() ); Utils.logf( ioe.toString() );
} }
}
} }
} }
@ -117,13 +115,10 @@ public class NetUtils {
{ {
DBUtils.Obit[] obits = DBUtils.listObits( context ); DBUtils.Obit[] obits = DBUtils.listObits( context );
if ( null != obits && 0 < obits.length ) { if ( null != obits && 0 < obits.length ) {
Socket socket = MakeProxySocket( context, 10000 ); InformThread thread = new InformThread( context, obits );
if ( null != socket ) {
InformThread thread = new InformThread( context, obits, socket );
thread.start(); thread.start();
} }
} }
}
public static String[] QueryRelay( Context context ) public static String[] QueryRelay( Context context )
{ {