This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

xmpp socket fix

  • Loading branch information...
kryukov committed Nov 27, 2013
1 parent 1f1185c commit c2c69ab24a0846c76f720e6d22d54b87139f781a
Showing with 27 additions and 46 deletions.
  1. +21 −28 networking/src/protocol/xmpp/Socket.java
  2. +6 −18 networking/src/protocol/xmpp/XmppConnection.java
@@ -33,7 +33,6 @@
private boolean secured;
// #sijapp cond.end #
private final Vector<Object> read = new Vector<Object>();
private final Object readLock = new Object();

/**
* Creates a new instance of Socket
@@ -173,49 +172,43 @@ boolean isSecured() {
return secured;
}

private Object readObject() throws JimmException {
Object readObject = null;
while (connected && null == readObject) {
readObject = XmlNode.parse(this);
if (null == readObject) sleep(100);
}
return readObject;
}

@Override
public void run() {
Object readObject;
while (connected) {
synchronized (readLock) {
try {
readLock.wait();
} catch (InterruptedException ignored) {
}
}
Object readObject;
try {
readObject = XmlNode.parse(this);
if (null == readObject) continue;
readObject = readObject();
} catch (JimmException e) {
readObject = e;
}
synchronized (read) {
read.addElement(readObject);
read.notifyAll();
if (null != readObject) {
synchronized (read) {
read.addElement(readObject);
}
}
}
synchronized (read) {
read.notifyAll();
}
}

public XmlNode readNode(boolean wait) throws JimmException {
Object readObject = null;
synchronized (readLock) {
readLock.notify();
}
synchronized (read) {
do {
if (wait) {
readObject = readObject();
} else {
synchronized (read) {
if (0 < read.size()) {
readObject = read.elementAt(0);
read.removeElementAt(0);
wait = false;
} else if (wait) {
try {
read.wait();
} catch (InterruptedException ignored) {
}
}
} while (wait);
}
}
if (readObject instanceof JimmException) throw (JimmException) readObject;
return (XmlNode) readObject;
@@ -206,7 +206,6 @@ private void write(byte[] data) throws JimmException {
private void connectTo(String url) throws JimmException {
socket = new Socket();
socket.connectTo(url);
socket.start();
}

public final void disconnect() {
@@ -275,20 +274,10 @@ private void writePacket(String packet) throws JimmException {
write(packet);
}
private XmlNode readXmlNode(boolean notEmpty) throws JimmException {
for (;;) {
XmlNode x = socket.readNode(notEmpty);
if (null != x) {
// #sijapp cond.if modules_DEBUGLOG is "true" #
//DebugLog.systemPrintln("[IN]:\n" + x.toString());
// #sijapp cond.end #
return x;
}
if (notEmpty) {
socket.sleep(100);
} else {
return null;
}
}
// #sijapp cond.if modules_DEBUGLOG is "true" #
//DebugLog.systemPrintln("[IN]:\n" + x.toString());
// #sijapp cond.end #
return socket.readNode(notEmpty);
}

// -----------------------------------------------------------------------
@@ -386,6 +375,7 @@ protected final void connect() throws JimmException {
}

setProgress(50);
socket.start();
write(GET_ROSTER_XML);
usePong();
}
@@ -624,9 +614,7 @@ private void sendIqError(String query, String xmlns, String from, String id) {
+ "</iq>");
}
private boolean isMy(String from) {
if (StringUtils.isEmpty(from)) return true;
if (getJabber().getUserId().equals(Jid.getBareJid(from))) return true;
return false;
return StringUtils.isEmpty(from) || getJabber().getUserId().equals(Jid.getBareJid(from));
}

private void processEmptyId(String id, byte iqType, String from) {

0 comments on commit c2c69ab

Please sign in to comment.