Working on reading multiple messages at once
The ObjectMessageReader does function normally for single messages but will deliver corrupted objects when a message consisting of multiple objects is received.
This commit is contained in:
parent
be1fc1e502
commit
23c4fd8f67
@ -86,7 +86,7 @@ public class User {
|
|||||||
public String getName() { return name; }
|
public String getName() { return name; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name the user name to set
|
* @param name the username to set
|
||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
* @see User#getName()
|
* @see User#getName()
|
||||||
*/
|
*/
|
||||||
|
@ -5,10 +5,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jenkov.nioserver.IMessageReader;
|
import com.jenkov.nioserver.*;
|
||||||
import com.jenkov.nioserver.Message;
|
|
||||||
import com.jenkov.nioserver.MessageBuffer;
|
|
||||||
import com.jenkov.nioserver.Socket;
|
|
||||||
|
|
||||||
import envoy.util.SerializationUtils;
|
import envoy.util.SerializationUtils;
|
||||||
|
|
||||||
@ -48,18 +45,26 @@ public class ObjectMessageReader implements IMessageReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nextMessage.writeToMessage(buffer);
|
nextMessage.writeToMessage(buffer);
|
||||||
|
buffer.clear();
|
||||||
|
|
||||||
// Get message length
|
// Get message length
|
||||||
if (nextMessage.length < 4) return;
|
if (nextMessage.length < 4) return;
|
||||||
int length = SerializationUtils.bytesToInt(nextMessage.sharedArray, nextMessage.offset) + 4;
|
int length = SerializationUtils.bytesToInt(nextMessage.sharedArray, nextMessage.offset) + 4;
|
||||||
|
do {
|
||||||
|
|
||||||
if (nextMessage.length >= length) {
|
// Separate first complete message
|
||||||
Message message = messageBuffer.getMessage();
|
if (nextMessage.length >= length) {
|
||||||
message.writePartialMessageToMessage(nextMessage, nextMessage.offset + length);
|
Message message = messageBuffer.getMessage();
|
||||||
completeMessages.add(nextMessage);
|
message.writePartialMessageToMessage(nextMessage, nextMessage.offset + length);
|
||||||
nextMessage = message;
|
message.length = nextMessage.length - length;
|
||||||
}
|
completeMessages.add(nextMessage);
|
||||||
|
nextMessage = message;
|
||||||
|
}
|
||||||
|
|
||||||
buffer.clear();
|
// Get message length
|
||||||
|
if (nextMessage.length < 4) return;
|
||||||
|
length = SerializationUtils.bytesToInt(nextMessage.sharedArray, nextMessage.offset) + 4;
|
||||||
|
|
||||||
|
} while (nextMessage.length >= length);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ import envoy.server.net.ObjectWriteProxy;
|
|||||||
* File: <strong>IdGeneratorRequestProcessor.java</strong><br>
|
* File: <strong>IdGeneratorRequestProcessor.java</strong><br>
|
||||||
* Created: <strong>28 Jan 2020</strong><br>
|
* Created: <strong>28 Jan 2020</strong><br>
|
||||||
*
|
*
|
||||||
* @author KSKE
|
* @author Kai S. K. Engelbart
|
||||||
* @since Envoy Server Standalone v0.1-alpha
|
* @since Envoy Server Standalone v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public class IdGeneratorRequestProcessor implements ObjectProcessor<IdGeneratorRequest> {
|
public class IdGeneratorRequestProcessor implements ObjectProcessor<IdGeneratorRequest> {
|
||||||
|
Reference in New Issue
Block a user