From 55d921645d774fee0a997bdd021689b5ff2e754a Mon Sep 17 00:00:00 2001 From: Alex Wenckus Date: Wed, 8 Feb 2006 18:03:09 +0000 Subject: [PATCH] Syncronization issues git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3409 b35dd754-fafc-0310-a699-88a17e54d16e --- .../Socks5TransferNegotiator.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java b/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java index 04cfe5635..c460787d8 100644 --- a/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java +++ b/source/org/jivesoftware/smackx/filetransfer/Socks5TransferNegotiator.java @@ -79,8 +79,15 @@ public class Socks5TransferNegotiator extends StreamNegotiator { private List proxies; private List streamHosts; + + // locks the proxies during their initialization process + private final Object proxyLock = new Object(); + private ProxyProcess proxyProcess; + // locks on the proxy process during its initiatilization process + private final Object processLock = new Object(); + public Socks5TransferNegotiator(final XMPPConnection connection) { this.connection = connection; } @@ -101,7 +108,6 @@ public class Socks5TransferNegotiator extends StreamNegotiator { Bytestream streamHostsInfo = (Bytestream) streamInitiation; - if (streamHostsInfo.getType().equals(IQ.Type.ERROR)) { throw new XMPPException(streamHostsInfo.getError()); } @@ -345,9 +351,11 @@ public class Socks5TransferNegotiator extends StreamNegotiator { } private ProxyProcess establishListeningSocket() throws IOException { - if (proxyProcess == null) { - proxyProcess = new ProxyProcess(new ServerSocket(7777)); - proxyProcess.start(); + synchronized (processLock) { + if (proxyProcess == null) { + proxyProcess = new ProxyProcess(new ServerSocket(7777)); + proxyProcess.start(); + } } proxyProcess.addTransfer(); return proxyProcess; @@ -396,7 +404,6 @@ public class Socks5TransferNegotiator extends StreamNegotiator { */ private Bytestream createByteStreamInit(final String from, final String to, final String sid, final String localIP, final int port) { - Bytestream bs = new Bytestream(); bs.setTo(to); bs.setFrom(from); @@ -406,8 +413,11 @@ public class Socks5TransferNegotiator extends StreamNegotiator { if (localIP != null && port > 0) { bs.addStreamHost(from, localIP, port); } - if (proxies == null) { - initProxies(); + // make sure the proxies have been initialized completely + synchronized (proxyLock) { + if (proxies == null) { + initProxies(); + } } if (streamHosts != null) { Iterator it = streamHosts.iterator(); @@ -704,7 +714,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator { public void stop() { done = true; - synchronized(this) { + synchronized (this) { this.notify(); } } @@ -728,7 +738,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator { synchronized (this) { if (transfers == -1) { transfers = 1; - thread.notify(); + this.notify(); } else { transfers++;