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,51 +65,49 @@ 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 );
int strLens = 0; if ( null != socket ) {
for ( int ii = 0; ii < m_obits.length; ++ii ) { int strLens = 0;
strLens += m_obits[ii].m_relayID.length() + 1; // 1 for /n
}
try {
DataOutputStream outStream =
new DataOutputStream( m_socket.getOutputStream() );
outStream.writeShort( 2 + 2 + (2*m_obits.length) + strLens );
outStream.writeByte( NetUtils.PROTOCOL_VERSION );
outStream.writeByte( NetUtils.PRX_DEVICE_GONE );
outStream.writeShort( m_obits.length );
for ( int ii = 0; ii < m_obits.length; ++ii ) { for ( int ii = 0; ii < m_obits.length; ++ii ) {
outStream.writeShort( m_obits[ii].m_seed ); strLens += m_obits[ii].m_relayID.length() + 1; // 1 for /n
outStream.writeBytes( m_obits[ii].m_relayID );
outStream.write( '\n' );
} }
outStream.flush(); try {
DataOutputStream outStream =
new DataOutputStream( socket.getOutputStream() );
outStream.writeShort( 2 + 2 + (2*m_obits.length) + strLens );
outStream.writeByte( NetUtils.PROTOCOL_VERSION );
outStream.writeByte( NetUtils.PRX_DEVICE_GONE );
outStream.writeShort( m_obits.length );
DataInputStream dis = for ( int ii = 0; ii < m_obits.length; ++ii ) {
new DataInputStream( m_socket.getInputStream() ); outStream.writeShort( m_obits[ii].m_seed );
short resLen = dis.readShort(); outStream.writeBytes( m_obits[ii].m_relayID );
m_socket.close(); outStream.write( '\n' );
}
if ( resLen == 0 ) { outStream.flush();
DBUtils.clearObits( m_context, m_obits );
DataInputStream dis =
new DataInputStream( socket.getInputStream() );
short resLen = dis.readShort();
socket.close();
if ( resLen == 0 ) {
DBUtils.clearObits( m_context, m_obits );
}
} catch ( java.io.IOException ioe ) {
Utils.logf( ioe.toString() );
} }
} catch ( java.io.IOException ioe ) {
Utils.logf( ioe.toString() );
} }
} }
} }
@ -117,11 +115,8 @@ 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 ) { thread.start();
InformThread thread = new InformThread( context, obits, socket );
thread.start();
}
} }
} }