1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 23:42:06 +01:00

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

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,10 +351,12 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
} }
private ProxyProcess establishListeningSocket() throws IOException { private ProxyProcess establishListeningSocket() throws IOException {
synchronized (processLock) {
if (proxyProcess == null) { if (proxyProcess == null) {
proxyProcess = new ProxyProcess(new ServerSocket(7777)); proxyProcess = new ProxyProcess(new ServerSocket(7777));
proxyProcess.start(); 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,9 +413,12 @@ 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);
} }
// make sure the proxies have been initialized completely
synchronized (proxyLock) {
if (proxies == null) { if (proxies == null) {
initProxies(); initProxies();
} }
}
if (streamHosts != null) { if (streamHosts != null) {
Iterator it = streamHosts.iterator(); Iterator it = streamHosts.iterator();
while (it.hasNext()) { while (it.hasNext()) {
@ -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++;