Syncronization issues

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3409 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Alex Wenckus 2006-02-08 18:03:09 +00:00 committed by alex
parent 9d2eafdc49
commit 55d921645d
1 changed files with 19 additions and 9 deletions

View File

@ -79,8 +79,15 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
private List proxies; private List proxies;
private List streamHosts; private List streamHosts;
// locks the proxies during their initialization process
private final Object proxyLock = new Object();
private ProxyProcess proxyProcess; private ProxyProcess proxyProcess;
// locks on the proxy process during its initiatilization process
private final Object processLock = new Object();
public Socks5TransferNegotiator(final XMPPConnection connection) { public Socks5TransferNegotiator(final XMPPConnection connection) {
this.connection = connection; this.connection = connection;
} }
@ -101,7 +108,6 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
Bytestream streamHostsInfo = (Bytestream) streamInitiation; Bytestream streamHostsInfo = (Bytestream) streamInitiation;
if (streamHostsInfo.getType().equals(IQ.Type.ERROR)) { if (streamHostsInfo.getType().equals(IQ.Type.ERROR)) {
throw new XMPPException(streamHostsInfo.getError()); throw new XMPPException(streamHostsInfo.getError());
} }
@ -345,9 +351,11 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
} }
private ProxyProcess establishListeningSocket() throws IOException { private ProxyProcess establishListeningSocket() throws IOException {
if (proxyProcess == null) { synchronized (processLock) {
proxyProcess = new ProxyProcess(new ServerSocket(7777)); if (proxyProcess == null) {
proxyProcess.start(); proxyProcess = new ProxyProcess(new ServerSocket(7777));
proxyProcess.start();
}
} }
proxyProcess.addTransfer(); proxyProcess.addTransfer();
return proxyProcess; return proxyProcess;
@ -396,7 +404,6 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
*/ */
private Bytestream createByteStreamInit(final String from, final String to, private Bytestream createByteStreamInit(final String from, final String to,
final String sid, final String localIP, final int port) { final String sid, final String localIP, final int port) {
Bytestream bs = new Bytestream(); Bytestream bs = new Bytestream();
bs.setTo(to); bs.setTo(to);
bs.setFrom(from); bs.setFrom(from);
@ -406,8 +413,11 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
if (localIP != null && port > 0) { if (localIP != null && port > 0) {
bs.addStreamHost(from, localIP, port); bs.addStreamHost(from, localIP, port);
} }
if (proxies == null) { // make sure the proxies have been initialized completely
initProxies(); synchronized (proxyLock) {
if (proxies == null) {
initProxies();
}
} }
if (streamHosts != null) { if (streamHosts != null) {
Iterator it = streamHosts.iterator(); Iterator it = streamHosts.iterator();
@ -704,7 +714,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
public void stop() { public void stop() {
done = true; done = true;
synchronized(this) { synchronized (this) {
this.notify(); this.notify();
} }
} }
@ -728,7 +738,7 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
synchronized (this) { synchronized (this) {
if (transfers == -1) { if (transfers == -1) {
transfers = 1; transfers = 1;
thread.notify(); this.notify();
} }
else { else {
transfers++; transfers++;