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