From dabadc693220858ecb34af7e8df5f4e0b32461fc Mon Sep 17 00:00:00 2001 From: Nick Hudson Date: Fri, 29 Aug 2014 11:26:39 +0100 Subject: Fix JavaConnection to emit onDataWritten when it writes data to the socket The java code was never emitting the onDataWritten signal, although the corresponding C++ code in Swiften does do this. This change causes the signal to be emitted whenever a data is successfully written to the socket. Test-information: Tested using an application which was registering for the signal; previously it never saw "onDataWritten"; now it does. Tested using an application which doesn't register for the signal; it works as before. Change-Id: I1399af0721ef8226c0c4d2420bbe23f53ad3494f diff --git a/src/com/isode/stroke/network/JavaConnection.java b/src/com/isode/stroke/network/JavaConnection.java index 3f768dc..807d971 100644 --- a/src/com/isode/stroke/network/JavaConnection.java +++ b/src/com/isode/stroke/network/JavaConnection.java @@ -177,13 +177,21 @@ public class JavaConnection extends Connection implements EventOwner { */ boolean finishedWriting = false; int bytesWritten = socketChannel_.write(byteBuffer); + final boolean somethingWasWritten = (bytesWritten != 0); + if (somethingWasWritten) { + eventLoop_.postEvent(new Callback() { + public void run() { + onDataWritten.emit(); + } + }); + } finishedWriting = (byteBuffer.remaining() == 0); if (finishedWriting) { writeBuffer_.remove(0); return; } /* Was anything written at all? */ - if (bytesWritten == 0) { + if (!somethingWasWritten) { /* Leave the buffer in the array so that it'll get tried * again later */ -- cgit v0.10.2-6-g49f6