Fixed consecutive message writing
This commit is contained in:
parent
27ac6b43c0
commit
5cf2959e1a
@ -68,7 +68,7 @@ public class Message {
|
|||||||
if (!this.messageBuffer.expandMessage(this)) return -1;
|
if (!this.messageBuffer.expandMessage(this)) return -1;
|
||||||
|
|
||||||
int bytesToCopy = Math.min(remaining, capacity - length);
|
int bytesToCopy = Math.min(remaining, capacity - length);
|
||||||
System.arraycopy(byteArray, offset, sharedArray, offset + this.length, bytesToCopy);
|
System.arraycopy(byteArray, offset, sharedArray, this.offset + this.length, bytesToCopy);
|
||||||
this.length += bytesToCopy;
|
this.length += bytesToCopy;
|
||||||
return bytesToCopy;
|
return bytesToCopy;
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,10 @@ public class MessageWriter {
|
|||||||
private int bytesWritten;
|
private int bytesWritten;
|
||||||
|
|
||||||
public void enqueue(Message message) {
|
public void enqueue(Message message) {
|
||||||
if (messageInProgress == null) messageInProgress = message;
|
if (messageInProgress == null) {
|
||||||
else writeQueue.add(message);
|
messageInProgress = message;
|
||||||
|
bytesWritten = 0;
|
||||||
|
} else writeQueue.add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(Socket socket, ByteBuffer byteBuffer) throws IOException {
|
public void write(Socket socket, ByteBuffer byteBuffer) throws IOException {
|
||||||
@ -31,8 +33,10 @@ public class MessageWriter {
|
|||||||
byteBuffer.clear();
|
byteBuffer.clear();
|
||||||
|
|
||||||
if (bytesWritten >= messageInProgress.length) {
|
if (bytesWritten >= messageInProgress.length) {
|
||||||
if (writeQueue.size() > 0) messageInProgress = writeQueue.remove(0);
|
if (writeQueue.size() > 0) {
|
||||||
else messageInProgress = null;
|
messageInProgress = writeQueue.remove(0);
|
||||||
|
bytesWritten = 0;
|
||||||
|
} else messageInProgress = null;
|
||||||
// TODO: unregister from selector
|
// TODO: unregister from selector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user