mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
open connection to relay in the network thread, not in UI thread. It
can block for a while.
This commit is contained in:
parent
cbb7f5ff4f
commit
27f65ba39d
1 changed files with 16 additions and 13 deletions
|
@ -118,6 +118,22 @@ public class CommsTransport extends Thread implements TransportProcs {
|
|||
while ( !m_done ) {
|
||||
try {
|
||||
synchronized( this ) {
|
||||
|
||||
// if we have data and no socket, try to connect.
|
||||
if ( null == m_socketChannel
|
||||
&& 0 < m_buffersOut.size() ) {
|
||||
try {
|
||||
m_socketChannel = SocketChannel.open();
|
||||
m_socketChannel.configureBlocking( false );
|
||||
InetSocketAddress isa
|
||||
= new InetSocketAddress( m_addr.ip_relay_hostName,
|
||||
m_addr.ip_relay_port );
|
||||
m_socketChannel.connect( isa );
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
Utils.logf( ioe.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( null != m_socketChannel ) {
|
||||
int ops = figureOps();
|
||||
Utils.logf( "calling with ops=%x", ops );
|
||||
|
@ -184,19 +200,6 @@ public class CommsTransport extends Thread implements TransportProcs {
|
|||
m_buffersOut.add( netbuf );
|
||||
Assert.assertEquals( netbuf.remaining(), 0 );
|
||||
|
||||
if ( null == m_socketChannel ) {
|
||||
try {
|
||||
m_socketChannel = SocketChannel.open();
|
||||
m_socketChannel.configureBlocking( false );
|
||||
InetSocketAddress isa
|
||||
= new InetSocketAddress( m_addr.ip_relay_hostName,
|
||||
m_addr.ip_relay_port );
|
||||
m_socketChannel.connect( isa );
|
||||
} catch ( java.io.IOException ioe ) {
|
||||
Utils.logf( ioe.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( null != m_selector ) {
|
||||
m_selector.wakeup(); // tell it it's got some writing to do
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue