drop PVA_ALIGNMENT constant
This will forevermore be 1, so no reason to incur complexity of testing this. size % PVA_ALIGNMENT -> 0 alignBuffer(PVA_ALIGNMENT) -> no-op alignedValue(val, PVA_ALIGNMENT) -> val
This commit is contained in:
@@ -40,13 +40,6 @@ const epics::pvData::int32 PVA_BROADCAST_PORT = 5076;
|
||||
/** PVA protocol message header size. */
|
||||
const epics::pvData::int16 PVA_MESSAGE_HEADER_SIZE = 8;
|
||||
|
||||
/**
|
||||
* All messages must be aligned to 8-bytes (64-bit).
|
||||
* MUST be 1. Code does not handle well alignment in some situations (e.g. direct deserialize).
|
||||
* Alignment is not worth additional code complexity.
|
||||
*/
|
||||
const epics::pvData::int32 PVA_ALIGNMENT = 1;
|
||||
|
||||
/**
|
||||
* UDP maximum send message size.
|
||||
* MAX_UDP: 1500 (max of ethernet and 802.{2,3} MTU) - 20/40(IPv4/IPv6)
|
||||
|
||||
@@ -207,8 +207,6 @@ void BlockingUDPTransport::startMessage(int8 command, size_t /*ensureCapacity*/,
|
||||
}
|
||||
|
||||
void BlockingUDPTransport::endMessage() {
|
||||
//we always (for now) send by packet, so no need for this here...
|
||||
//alignBuffer(PVA_ALIGNMENT);
|
||||
_sendBuffer.putInt(
|
||||
_lastMessageStartPosition+(sizeof(int16)+2),
|
||||
_sendBuffer.getPosition()-_lastMessageStartPosition-PVA_MESSAGE_HEADER_SIZE);
|
||||
|
||||
@@ -98,22 +98,9 @@ AbstractCodec::AbstractCodec(
|
||||
throw std::invalid_argument(
|
||||
"receiveBuffer.capacity() < 2*MAX_ENSURE_SIZE");
|
||||
|
||||
// require aligned buffer size
|
||||
//(not condition, but simplifies alignment code)
|
||||
|
||||
if (_socketBuffer.getSize() % PVA_ALIGNMENT != 0)
|
||||
throw std::invalid_argument(
|
||||
"receiveBuffer.capacity() % PVAConstants.PVA_ALIGNMENT != 0");
|
||||
|
||||
if (_sendBuffer.getSize() < 2*MAX_ENSURE_SIZE)
|
||||
throw std::invalid_argument("sendBuffer() < 2*MAX_ENSURE_SIZE");
|
||||
|
||||
// require aligned buffer size
|
||||
//(not condition, but simplifies alignment code)
|
||||
if (_sendBuffer.getSize() % PVA_ALIGNMENT != 0)
|
||||
throw std::invalid_argument(
|
||||
"sendBuffer() % PVAConstants.PVA_ALIGNMENT != 0");
|
||||
|
||||
// initialize to be empty
|
||||
_socketBuffer.setPosition(_socketBuffer.getLimit());
|
||||
_startPosition = _socketBuffer.getPosition();
|
||||
@@ -219,8 +206,7 @@ void AbstractCodec::processReadNormal() {
|
||||
_storedPayloadSize = _payloadSize;
|
||||
_storedPosition = _socketBuffer.getPosition();
|
||||
_storedLimit = _socketBuffer.getLimit();
|
||||
_socketBuffer.setLimit(std::min<std::size_t>
|
||||
(_storedPosition + _storedPayloadSize, _storedLimit));
|
||||
_socketBuffer.setLimit(std::min(_storedPosition + _storedPayloadSize, _storedLimit));
|
||||
bool postProcess = true;
|
||||
try
|
||||
{
|
||||
@@ -268,9 +254,7 @@ void AbstractCodec::postProcessApplicationMessage()
|
||||
{
|
||||
// set position as whole message was read
|
||||
//(in case code haven't done so)
|
||||
std::size_t newPosition =
|
||||
alignedValue(
|
||||
_storedPosition + _storedPayloadSize, PVA_ALIGNMENT);
|
||||
std::size_t newPosition = _storedPosition + _storedPayloadSize;
|
||||
|
||||
// aligned buffer size ensures that there is enough space
|
||||
//in buffer,
|
||||
@@ -285,17 +269,12 @@ void AbstractCodec::postProcessApplicationMessage()
|
||||
// we only handle unused alignment bytes
|
||||
int bytesNotRead =
|
||||
newPosition - _socketBuffer.getPosition();
|
||||
assert(bytesNotRead>=0);
|
||||
|
||||
if (bytesNotRead < PVA_ALIGNMENT)
|
||||
if (bytesNotRead==0)
|
||||
{
|
||||
// make alignment bytes as real payload to enable SPLIT
|
||||
// no end-of-socket or segmented scenario can happen
|
||||
// due to aligned buffer size
|
||||
_storedPayloadSize += bytesNotRead;
|
||||
// reveal currently existing padding
|
||||
_socketBuffer.setLimit(_storedLimit);
|
||||
ensureData(bytesNotRead);
|
||||
_storedPayloadSize -= bytesNotRead;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -368,7 +347,7 @@ bool AbstractCodec::readToBuffer(
|
||||
}
|
||||
|
||||
// assumption: remainingBytes < MAX_ENSURE_DATA_BUFFER_SIZE &&
|
||||
// requiredBytes < (socketBuffer.capacity() - PVA_ALIGNMENT)
|
||||
// requiredBytes < (socketBuffer.capacity() - 1)
|
||||
|
||||
//
|
||||
// copy unread part to the beginning of the buffer
|
||||
@@ -377,8 +356,7 @@ bool AbstractCodec::readToBuffer(
|
||||
//
|
||||
|
||||
// a new start position, we are careful to preserve alignment
|
||||
_startPosition =
|
||||
MAX_ENSURE_SIZE + _socketBuffer.getPosition() % PVA_ALIGNMENT;
|
||||
_startPosition = MAX_ENSURE_SIZE;
|
||||
|
||||
std::size_t endPosition = _startPosition + remainingBytes;
|
||||
|
||||
@@ -491,19 +469,6 @@ void AbstractCodec::ensureData(std::size_t size) {
|
||||
//and readToBuffer needs to know real limit)
|
||||
_socketBuffer.setLimit(_storedLimit);
|
||||
|
||||
// remember alignment offset of end of the message (to be restored)
|
||||
std::size_t storedAlignmentOffset =
|
||||
_socketBuffer.getPosition() % PVA_ALIGNMENT;
|
||||
|
||||
// skip post-message alignment bytes
|
||||
if (storedAlignmentOffset > 0)
|
||||
{
|
||||
std::size_t toSkip = PVA_ALIGNMENT - storedAlignmentOffset;
|
||||
readToBuffer(toSkip, true);
|
||||
std::size_t currentPos = _socketBuffer.getPosition();
|
||||
_socketBuffer.setPosition(currentPos + toSkip);
|
||||
}
|
||||
|
||||
// we expect segmented message, we expect header
|
||||
// that (and maybe some control packets) needs to be "removed"
|
||||
// so that we get combined payload
|
||||
@@ -513,14 +478,12 @@ void AbstractCodec::ensureData(std::size_t size) {
|
||||
_readMode = storedMode;
|
||||
|
||||
// make sure we have all the data (maybe we run into SPLIT)
|
||||
readToBuffer(size - remainingBytes + storedAlignmentOffset, true);
|
||||
readToBuffer(size - remainingBytes, true);
|
||||
|
||||
// skip storedAlignmentOffset bytes (sender should padded start of
|
||||
//segmented message)
|
||||
// SPLIT cannot mess with this, since start of the message,
|
||||
//i.e. current position, is always aligned
|
||||
_socketBuffer.setPosition(
|
||||
_socketBuffer.getPosition() + storedAlignmentOffset);
|
||||
_socketBuffer.getPosition());
|
||||
|
||||
// copy before position (i.e. start of the payload)
|
||||
for (int32_t i = remainingBytes - 1,
|
||||
@@ -530,7 +493,7 @@ void AbstractCodec::ensureData(std::size_t size) {
|
||||
_startPosition = _socketBuffer.getPosition() - remainingBytes;
|
||||
_socketBuffer.setPosition(_startPosition);
|
||||
|
||||
_storedPayloadSize += remainingBytes - storedAlignmentOffset;
|
||||
_storedPayloadSize += remainingBytes;
|
||||
_storedPosition = _startPosition;
|
||||
_storedLimit = _socketBuffer.getLimit();
|
||||
_socketBuffer.setLimit(
|
||||
@@ -604,12 +567,6 @@ void AbstractCodec::alignBuffer(std::size_t alignment) {
|
||||
if (pos == newpos)
|
||||
return;
|
||||
|
||||
/*
|
||||
// there is always enough of space
|
||||
// since sendBuffer capacity % PVA_ALIGNMENT == 0
|
||||
_sendBuffer.setPosition(newpos);
|
||||
*/
|
||||
|
||||
// for safety reasons we really pad (override previous message data)
|
||||
std::size_t padCount = newpos - pos;
|
||||
_sendBuffer.put(PADDING_BYTES, 0, padCount);
|
||||
@@ -665,9 +622,6 @@ void AbstractCodec::endMessage(bool hasMoreSegments) {
|
||||
{
|
||||
std::size_t lastPayloadBytePosition = _sendBuffer.getPosition();
|
||||
|
||||
// align
|
||||
alignBuffer(PVA_ALIGNMENT);
|
||||
|
||||
// set paylaod size (non-aligned)
|
||||
std::size_t payloadSize =
|
||||
lastPayloadBytePosition -
|
||||
@@ -689,7 +643,7 @@ void AbstractCodec::endMessage(bool hasMoreSegments) {
|
||||
_lastSegmentedMessageCommand =
|
||||
_sendBuffer.getByte(flagsPosition + 1);
|
||||
}
|
||||
_nextMessagePayloadOffset = lastPayloadBytePosition % PVA_ALIGNMENT;
|
||||
_nextMessagePayloadOffset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -212,20 +212,12 @@ public:
|
||||
|
||||
|
||||
void processControlMessage() {
|
||||
// alignment check
|
||||
if (_socketBuffer.getPosition() % PVA_ALIGNMENT != 0)
|
||||
throw std::logic_error("message not aligned");
|
||||
|
||||
_receivedControlMessages.push_back(
|
||||
PVAMessage(_version, _flags, _command, _payloadSize));
|
||||
}
|
||||
|
||||
|
||||
void processApplicationMessage() {
|
||||
// alignment check
|
||||
if (_socketBuffer.getPosition() % PVA_ALIGNMENT != 0)
|
||||
throw std::logic_error("message not aligned");
|
||||
|
||||
PVAMessage caMessage(_version, _flags,
|
||||
_command, _payloadSize);
|
||||
|
||||
@@ -472,7 +464,6 @@ public:
|
||||
testHeaderSplitRead();
|
||||
testNonEmptyPayload();
|
||||
testNormalAlignment();
|
||||
testSplitAlignment();
|
||||
testSegmentedMessage();
|
||||
//testSegmentedInvalidInBetweenFlagsMessage();
|
||||
testSegmentedMessageAlignment();
|
||||
@@ -776,9 +767,8 @@ private:
|
||||
codec._readBuffer->put(PVA_VERSION);
|
||||
codec._readBuffer->put((int8_t)0x80);
|
||||
codec._readBuffer->put((int8_t)0x23);
|
||||
codec._readBuffer->putInt(PVA_ALIGNMENT);
|
||||
for (int i = 0; i < PVA_ALIGNMENT; i++)
|
||||
codec._readBuffer->put((int8_t)i);
|
||||
codec._readBuffer->putInt(1); // size
|
||||
codec._readBuffer->put((int8_t)0);
|
||||
codec._readBuffer->flip();
|
||||
|
||||
codec.processRead();
|
||||
@@ -804,8 +794,8 @@ private:
|
||||
header._payload->flip();
|
||||
|
||||
testOk(
|
||||
(std::size_t)PVA_ALIGNMENT == header._payload->getLimit(),
|
||||
"%s: PVA_ALIGNMENT == header._payload->getLimit()",
|
||||
1 == header._payload->getLimit(),
|
||||
"%s: 1 == header._payload->getLimit()",
|
||||
CURRENT_FUNCTION);
|
||||
|
||||
}
|
||||
@@ -823,14 +813,13 @@ private:
|
||||
codec._readBuffer->put(PVA_VERSION);
|
||||
codec._readBuffer->put((int8_t)0x80);
|
||||
codec._readBuffer->put((int8_t)0x23);
|
||||
int32_t payloadSize1 = PVA_ALIGNMENT+1;
|
||||
const int32_t payloadSize1 = 2;
|
||||
codec._readBuffer->putInt(payloadSize1);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize1; i++)
|
||||
codec._readBuffer->put((int8_t)i);
|
||||
// align
|
||||
std::size_t aligned =
|
||||
AbstractCodec::alignedValue(payloadSize1, PVA_ALIGNMENT);
|
||||
std::size_t aligned = payloadSize1;
|
||||
|
||||
for (std::size_t i = payloadSize1; i < aligned; i++)
|
||||
codec._readBuffer->put((int8_t)0xFF);
|
||||
@@ -841,15 +830,14 @@ private:
|
||||
codec._readBuffer->put((int8_t)0x80);
|
||||
codec._readBuffer->put((int8_t)0x45);
|
||||
|
||||
int32_t payloadSize2 = 2*PVA_ALIGNMENT-1;
|
||||
const int32_t payloadSize2 = 1;
|
||||
codec._readBuffer->putInt(payloadSize2);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize2; i++) {
|
||||
codec._readBuffer->put((int8_t)i);
|
||||
}
|
||||
|
||||
aligned =
|
||||
AbstractCodec::alignedValue(payloadSize2, PVA_ALIGNMENT);
|
||||
aligned = payloadSize2;
|
||||
|
||||
for (std::size_t i = payloadSize2; i < aligned; i++) {
|
||||
codec._readBuffer->put((int8_t)0xFF);
|
||||
@@ -937,9 +925,7 @@ private:
|
||||
}
|
||||
|
||||
// align
|
||||
std::size_t aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
_payloadSize1, PVA_ALIGNMENT);
|
||||
std::size_t aligned = _payloadSize1;
|
||||
|
||||
for (std::size_t i = _payloadSize1; i < aligned; i++)
|
||||
_codec._readBuffer->put((int8_t)0xFF);
|
||||
@@ -961,9 +947,7 @@ private:
|
||||
{
|
||||
_codec._readBuffer->clear();
|
||||
|
||||
std::size_t aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
_payloadSize2, PVA_ALIGNMENT);
|
||||
std::size_t aligned = _payloadSize2;
|
||||
|
||||
for (std::size_t i = _payloadSize2; i < aligned; i++) {
|
||||
_codec._readBuffer->put((int8_t)0xFF);
|
||||
@@ -983,97 +967,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
void testSplitAlignment()
|
||||
{
|
||||
|
||||
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
|
||||
TestCodec codec(DEFAULT_BUFFER_SIZE,DEFAULT_BUFFER_SIZE);
|
||||
|
||||
// "<=" used instead of "==" to suppress compiler warning
|
||||
if (PVA_ALIGNMENT <= 1)
|
||||
return;
|
||||
|
||||
codec._readPayload = true;
|
||||
|
||||
codec._readBuffer->put(PVA_MAGIC);
|
||||
codec._readBuffer->put(PVA_VERSION);
|
||||
codec._readBuffer->put((int8_t)0x80);
|
||||
codec._readBuffer->put((int8_t)0x23);
|
||||
|
||||
int32_t payloadSize1 = PVA_ALIGNMENT+1;
|
||||
codec._readBuffer->putInt(payloadSize1);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize1-2; i++) {
|
||||
codec._readBuffer->put((int8_t)i);
|
||||
}
|
||||
|
||||
int32_t payloadSize2 = 2*PVA_ALIGNMENT-1;
|
||||
|
||||
std::auto_ptr<ReadPollOneCallback>
|
||||
readPollOneCallback(
|
||||
new ReadPollOneCallbackForTestSplitAlignment
|
||||
(codec, payloadSize1, payloadSize2));
|
||||
|
||||
codec._readPollOneCallback = readPollOneCallback;
|
||||
|
||||
codec._readBuffer->flip();
|
||||
codec.processRead();
|
||||
|
||||
|
||||
testOk(codec._invalidDataStreamCount == 0,
|
||||
"%s: codec._invalidDataStreamCount == 0",
|
||||
CURRENT_FUNCTION);
|
||||
testOk(codec._closedCount == 0,
|
||||
"%s: codec._closedCount == 0", CURRENT_FUNCTION);
|
||||
testOk(codec._receivedControlMessages.size() == 0,
|
||||
"%s: codec._receivedControlMessages.size() == 0 ",
|
||||
CURRENT_FUNCTION);
|
||||
testOk(codec._receivedAppMessages.size() == 2,
|
||||
"%s: codec._receivedAppMessages.size() == 2",
|
||||
CURRENT_FUNCTION);
|
||||
testOk(codec._readPollOneCount == 2,
|
||||
"%s: codec._readPollOneCount == 2", CURRENT_FUNCTION);
|
||||
|
||||
PVAMessage msg = codec._receivedAppMessages[0];
|
||||
|
||||
testOk(msg._payloadSize == payloadSize1,
|
||||
"%s: msg._payloadSize == payloadSize1", CURRENT_FUNCTION);
|
||||
testOk(msg._payload.get() != 0,
|
||||
"%s: msg._payload.get() != 0", CURRENT_FUNCTION);
|
||||
|
||||
msg._payload->flip();
|
||||
|
||||
testOk(payloadSize1 = msg._payload->getLimit(),
|
||||
"%s: payloadSize1 = msg._payload->getLimit()",
|
||||
CURRENT_FUNCTION);
|
||||
|
||||
for (int32_t i = 0; i < msg._payloadSize; i++) {
|
||||
testOk((int8_t)i == msg._payload->getByte(),
|
||||
"%s: (int8_t)i == msg._payload->getByte()",
|
||||
CURRENT_FUNCTION);
|
||||
}
|
||||
|
||||
msg = codec._receivedAppMessages[1];
|
||||
|
||||
testOk(msg._payloadSize == payloadSize2,
|
||||
"%s: msg._payloadSize == payloadSize2", CURRENT_FUNCTION);
|
||||
testOk(msg._payload.get() != 0,
|
||||
"%s: msg._payload.get() != 0", CURRENT_FUNCTION);
|
||||
|
||||
msg._payload->flip();
|
||||
|
||||
testOk((std::size_t)payloadSize2 == msg._payload->getLimit(),
|
||||
"%s: payloadSize2 == msg._payload->getLimit()",
|
||||
CURRENT_FUNCTION);
|
||||
|
||||
for (int32_t i = 0; i < msg._payloadSize; i++) {
|
||||
testOk((int8_t)i == msg._payload->getByte(),
|
||||
"%s: (int8_t)i == msg._payload->getByte()",
|
||||
CURRENT_FUNCTION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testSegmentedMessage()
|
||||
{
|
||||
|
||||
@@ -1089,7 +982,7 @@ private:
|
||||
codec._readBuffer->put((int8_t)0x90);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize1 = PVA_ALIGNMENT;
|
||||
int32_t payloadSize1 = 1;
|
||||
codec._readBuffer->putInt(payloadSize1);
|
||||
|
||||
int32_t c = 0;
|
||||
@@ -1102,7 +995,7 @@ private:
|
||||
codec._readBuffer->put((int8_t)0xB0);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize2 = 2*PVA_ALIGNMENT;
|
||||
int32_t payloadSize2 = 2;
|
||||
codec._readBuffer->putInt(payloadSize2);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize2; i++)
|
||||
@@ -1121,7 +1014,7 @@ private:
|
||||
codec._readBuffer->put((int8_t)0xB0);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize3 = PVA_ALIGNMENT;
|
||||
int32_t payloadSize3 = 1;
|
||||
codec._readBuffer->putInt(payloadSize3);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize3; i++)
|
||||
@@ -1133,7 +1026,7 @@ private:
|
||||
codec._readBuffer->put((int8_t)0xA0);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize4 = 2*PVA_ALIGNMENT;
|
||||
int32_t payloadSize4 = 2;
|
||||
codec._readBuffer->putInt(payloadSize4);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize4; i++)
|
||||
@@ -1209,7 +1102,7 @@ private:
|
||||
codec._readBuffer->put((int8_t)0x90);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize1 = PVA_ALIGNMENT;
|
||||
int32_t payloadSize1 = 1;
|
||||
codec._readBuffer->putInt(payloadSize1);
|
||||
|
||||
int32_t c = 0;
|
||||
@@ -1223,7 +1116,7 @@ private:
|
||||
codec._readBuffer->put((int8_t)0x90);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize2 = 2*PVA_ALIGNMENT;
|
||||
int32_t payloadSize2 = 2;
|
||||
codec._readBuffer->putInt(payloadSize2);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize2; i++)
|
||||
@@ -1242,7 +1135,7 @@ private:
|
||||
codec._readBuffer->put((int8_t)0xB0);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize3 = PVA_ALIGNMENT;
|
||||
int32_t payloadSize3 = 1;
|
||||
codec._readBuffer->putInt(payloadSize3);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize3; i++)
|
||||
@@ -1254,7 +1147,7 @@ private:
|
||||
codec._readBuffer->put((int8_t)0xA0);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize4 = 2*PVA_ALIGNMENT;
|
||||
int32_t payloadSize4 = 2;
|
||||
codec._readBuffer->putInt(payloadSize4);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize4; i++)
|
||||
@@ -1303,15 +1196,14 @@ private:
|
||||
codec._readBuffer->put((int8_t)0x90);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize1 = PVA_ALIGNMENT+1;
|
||||
int32_t payloadSize1 = 1+1;
|
||||
codec._readBuffer->putInt(payloadSize1);
|
||||
|
||||
int32_t c = 0;
|
||||
for (int32_t i = 0; i < payloadSize1; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
std::size_t aligned =
|
||||
AbstractCodec::alignedValue(payloadSize1, PVA_ALIGNMENT);
|
||||
std::size_t aligned = payloadSize1;
|
||||
for (std::size_t i = payloadSize1; i < aligned; i++)
|
||||
codec._readBuffer->put((int8_t)0xFF);
|
||||
|
||||
@@ -1322,22 +1214,15 @@ private:
|
||||
codec._readBuffer->put((int8_t)0xB0);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize2 = 2*PVA_ALIGNMENT-1;
|
||||
int32_t payloadSize2Real =
|
||||
payloadSize2 + payloadSize1 % PVA_ALIGNMENT;
|
||||
int32_t payloadSize2 = 1;
|
||||
int32_t payloadSize2Real = payloadSize2;
|
||||
|
||||
codec._readBuffer->putInt(payloadSize2Real);
|
||||
|
||||
// pre-message padding
|
||||
for (int32_t i = 0; i < payloadSize1 % PVA_ALIGNMENT; i++)
|
||||
codec._readBuffer->put((int8_t)0xEE);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize2; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
payloadSize2Real, PVA_ALIGNMENT);
|
||||
aligned = payloadSize2Real;
|
||||
|
||||
for (std::size_t i = payloadSize2Real; i < aligned; i++)
|
||||
codec._readBuffer->put((int8_t)0xFF);
|
||||
@@ -1348,22 +1233,14 @@ private:
|
||||
codec._readBuffer->put((int8_t)0xB0);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize3 = PVA_ALIGNMENT+2;
|
||||
int32_t payloadSize3Real =
|
||||
payloadSize3 + payloadSize2Real % PVA_ALIGNMENT;
|
||||
int32_t payloadSize3 = 3;
|
||||
int32_t payloadSize3Real = payloadSize3;
|
||||
codec._readBuffer->putInt(payloadSize3Real);
|
||||
|
||||
// pre-message padding required
|
||||
for (int32_t i = 0;
|
||||
i < payloadSize2Real % PVA_ALIGNMENT; i++)
|
||||
codec._readBuffer->put((int8_t)0xEE);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize3; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
payloadSize3Real, PVA_ALIGNMENT);
|
||||
aligned = payloadSize3Real;
|
||||
|
||||
for (std::size_t i = payloadSize3Real; i < aligned; i++)
|
||||
codec._readBuffer->put((int8_t)0xFF);
|
||||
@@ -1374,23 +1251,15 @@ private:
|
||||
codec._readBuffer->put((int8_t)0xA0);
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize4 = 2*PVA_ALIGNMENT+3;
|
||||
int32_t payloadSize4Real =
|
||||
payloadSize4 + payloadSize3Real % PVA_ALIGNMENT;
|
||||
int32_t payloadSize4 = 2+3;
|
||||
int32_t payloadSize4Real = payloadSize4;
|
||||
|
||||
codec._readBuffer->putInt(payloadSize4Real);
|
||||
|
||||
// pre-message padding required
|
||||
for (int32_t i = 0;
|
||||
i < payloadSize3Real % PVA_ALIGNMENT; i++)
|
||||
codec._readBuffer->put((int8_t)0xEE);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize4; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
payloadSize4Real, PVA_ALIGNMENT);
|
||||
aligned = payloadSize4Real;
|
||||
|
||||
for (std::size_t i = payloadSize4Real; i < aligned; i++)
|
||||
codec._readBuffer->put((int8_t)0xFF);
|
||||
@@ -1468,16 +1337,16 @@ private:
|
||||
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
|
||||
|
||||
for (int32_t firstMessagePayloadSize = 1; // cannot be zero
|
||||
firstMessagePayloadSize <= 3*PVA_ALIGNMENT;
|
||||
firstMessagePayloadSize <= 3;
|
||||
firstMessagePayloadSize++)
|
||||
{
|
||||
for (int32_t secondMessagePayloadSize = 0;
|
||||
secondMessagePayloadSize <= 2*PVA_ALIGNMENT;
|
||||
secondMessagePayloadSize <= 2;
|
||||
secondMessagePayloadSize++)
|
||||
{
|
||||
// cannot be zero
|
||||
for (int32_t thirdMessagePayloadSize = 1;
|
||||
thirdMessagePayloadSize <= 2*PVA_ALIGNMENT;
|
||||
thirdMessagePayloadSize <= 2;
|
||||
thirdMessagePayloadSize++)
|
||||
{
|
||||
std::size_t splitAt = 1;
|
||||
@@ -1501,9 +1370,7 @@ private:
|
||||
for (int32_t i = 0; i < payloadSize1; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
std::size_t aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
payloadSize1, PVA_ALIGNMENT);
|
||||
std::size_t aligned = payloadSize1;
|
||||
|
||||
for (std::size_t i = payloadSize1; i < aligned; i++)
|
||||
codec._readBuffer->put((int8_t)0xFF);
|
||||
@@ -1515,22 +1382,14 @@ private:
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize2 = secondMessagePayloadSize;
|
||||
int payloadSize2Real =
|
||||
payloadSize2 + payloadSize1 % PVA_ALIGNMENT;
|
||||
int payloadSize2Real = payloadSize2;
|
||||
|
||||
codec._readBuffer->putInt(payloadSize2Real);
|
||||
|
||||
// pre-message padding
|
||||
for (int32_t i = 0;
|
||||
i < payloadSize1 % PVA_ALIGNMENT; i++)
|
||||
codec._readBuffer->put((int8_t)0xEE);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize2; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
payloadSize2Real, PVA_ALIGNMENT);
|
||||
aligned = payloadSize2Real;
|
||||
|
||||
for (std::size_t i = payloadSize2Real;
|
||||
i < aligned; i++)
|
||||
@@ -1543,22 +1402,14 @@ private:
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize3 = thirdMessagePayloadSize;
|
||||
int32_t payloadSize3Real =
|
||||
payloadSize3 + payloadSize2Real % PVA_ALIGNMENT;
|
||||
int32_t payloadSize3Real = payloadSize3;
|
||||
|
||||
codec._readBuffer->putInt(payloadSize3Real);
|
||||
|
||||
// pre-message padding required
|
||||
for (int32_t i = 0;
|
||||
i < payloadSize2Real % PVA_ALIGNMENT; i++)
|
||||
codec._readBuffer->put((int8_t)0xEE);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize3; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
payloadSize3Real, PVA_ALIGNMENT);
|
||||
aligned = payloadSize3Real;
|
||||
|
||||
for (std::size_t i = payloadSize3Real;
|
||||
i < aligned; i++)
|
||||
@@ -1742,9 +1593,8 @@ private:
|
||||
codec._readPayload = true;
|
||||
codec.startMessage((int8_t)0x23, 0);
|
||||
|
||||
codec.ensureBuffer((std::size_t)PVA_ALIGNMENT);
|
||||
for (int32_t i = 0; i < PVA_ALIGNMENT; i++)
|
||||
codec.getSendBuffer()->put((int8_t)i);
|
||||
codec.ensureBuffer(1);
|
||||
codec.getSendBuffer()->put((int8_t)0);
|
||||
|
||||
codec.endMessage();
|
||||
|
||||
@@ -1772,8 +1622,7 @@ private:
|
||||
|
||||
header._payload->flip();
|
||||
|
||||
testOk((std::size_t)PVA_ALIGNMENT ==
|
||||
header._payload->getLimit(),
|
||||
testOk(1u == header._payload->getLimit(),
|
||||
"%s: PVA_ALIGNMENT == header._payload->getLimit()",
|
||||
CURRENT_FUNCTION);
|
||||
}
|
||||
@@ -1787,7 +1636,7 @@ private:
|
||||
codec._readPayload = true;
|
||||
|
||||
codec.startMessage((int8_t)0x23, 0);
|
||||
int32_t payloadSize1 = PVA_ALIGNMENT+1;
|
||||
int32_t payloadSize1 = 1+1;
|
||||
codec.ensureBuffer(payloadSize1);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize1; i++)
|
||||
@@ -1796,7 +1645,7 @@ private:
|
||||
codec.endMessage();
|
||||
|
||||
codec.startMessage((int8_t)0x45, 0);
|
||||
int32_t payloadSize2 = 2*PVA_ALIGNMENT-1;
|
||||
int32_t payloadSize2 = 1;
|
||||
codec.ensureBuffer(payloadSize2);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize2; i++)
|
||||
@@ -1872,25 +1721,25 @@ private:
|
||||
|
||||
int32_t c = 0;
|
||||
|
||||
int32_t payloadSize1 = PVA_ALIGNMENT;
|
||||
int32_t payloadSize1 = 1;
|
||||
for (int32_t i = 0; i < payloadSize1; i++)
|
||||
codec.getSendBuffer()->put((int8_t)(c++));
|
||||
|
||||
codec.flush(false);
|
||||
|
||||
int32_t payloadSize2 = 2*PVA_ALIGNMENT;
|
||||
int32_t payloadSize2 = 2;
|
||||
for (int32_t i = 0; i < payloadSize2; i++)
|
||||
codec.getSendBuffer()->put((int8_t)(c++));
|
||||
|
||||
codec.flush(false);
|
||||
|
||||
int32_t payloadSize3 = PVA_ALIGNMENT;
|
||||
int32_t payloadSize3 = 1;
|
||||
for (int32_t i = 0; i < payloadSize3; i++)
|
||||
codec.getSendBuffer()->put((int8_t)(c++));
|
||||
|
||||
codec.flush(false);
|
||||
|
||||
int32_t payloadSize4 = 2*PVA_ALIGNMENT;
|
||||
int32_t payloadSize4 = 2;
|
||||
for (int32_t i = 0; i < payloadSize4; i++)
|
||||
codec.getSendBuffer()->put((int8_t)(c++));
|
||||
|
||||
@@ -1943,21 +1792,21 @@ private:
|
||||
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
|
||||
|
||||
for (int32_t firstMessagePayloadSize = 1; // cannot be zero
|
||||
firstMessagePayloadSize <= 3*PVA_ALIGNMENT;
|
||||
firstMessagePayloadSize <= 3;
|
||||
firstMessagePayloadSize++)
|
||||
{
|
||||
for (int32_t secondMessagePayloadSize = 0;
|
||||
secondMessagePayloadSize <= 2*PVA_ALIGNMENT;
|
||||
secondMessagePayloadSize <= 2;
|
||||
secondMessagePayloadSize++)
|
||||
{
|
||||
// cannot be zero
|
||||
for (int32_t thirdMessagePayloadSize = 1;
|
||||
thirdMessagePayloadSize <= 2*PVA_ALIGNMENT;
|
||||
thirdMessagePayloadSize <= 2;
|
||||
thirdMessagePayloadSize++)
|
||||
{
|
||||
// cannot be zero
|
||||
for (int32_t fourthMessagePayloadSize = 1;
|
||||
fourthMessagePayloadSize <= 2*PVA_ALIGNMENT;
|
||||
fourthMessagePayloadSize <= 2;
|
||||
fourthMessagePayloadSize++)
|
||||
{
|
||||
TestCodec codec(DEFAULT_BUFFER_SIZE,
|
||||
@@ -2105,16 +1954,16 @@ private:
|
||||
|
||||
|
||||
for (int32_t firstMessagePayloadSize = 1; // cannot be zero
|
||||
firstMessagePayloadSize <= 3*PVA_ALIGNMENT;
|
||||
firstMessagePayloadSize <= 3;
|
||||
firstMessagePayloadSize++)
|
||||
{
|
||||
for (int32_t secondMessagePayloadSize = 0;
|
||||
secondMessagePayloadSize <= 2*PVA_ALIGNMENT;
|
||||
secondMessagePayloadSize <= 2;
|
||||
secondMessagePayloadSize++)
|
||||
{
|
||||
// cannot be zero
|
||||
for (int32_t thirdMessagePayloadSize = 1;
|
||||
thirdMessagePayloadSize <= 2*PVA_ALIGNMENT;
|
||||
thirdMessagePayloadSize <= 2;
|
||||
thirdMessagePayloadSize++)
|
||||
{
|
||||
std::size_t splitAt = 1;
|
||||
@@ -2139,9 +1988,7 @@ private:
|
||||
for (int32_t i = 0; i < payloadSize1; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
std::size_t aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
payloadSize1, PVA_ALIGNMENT);
|
||||
std::size_t aligned = payloadSize1;
|
||||
|
||||
for (std::size_t i = payloadSize1; i < aligned; i++)
|
||||
codec._readBuffer->put((int8_t)0xFF);
|
||||
@@ -2153,22 +2000,14 @@ private:
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize2 = secondMessagePayloadSize;
|
||||
int32_t payloadSize2Real =
|
||||
payloadSize2 + payloadSize1 % PVA_ALIGNMENT;
|
||||
int32_t payloadSize2Real = payloadSize2;
|
||||
|
||||
codec._readBuffer->putInt(payloadSize2Real);
|
||||
|
||||
// pre-message padding
|
||||
for (int32_t i = 0;
|
||||
i < payloadSize1 % PVA_ALIGNMENT; i++)
|
||||
codec._readBuffer->put((int8_t)0xEE);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize2; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
payloadSize2Real, PVA_ALIGNMENT);
|
||||
aligned = payloadSize2Real;
|
||||
|
||||
for (std::size_t i = payloadSize2Real;
|
||||
i < aligned; i++)
|
||||
@@ -2181,22 +2020,14 @@ private:
|
||||
codec._readBuffer->put((int8_t)0x01);
|
||||
|
||||
int32_t payloadSize3 = thirdMessagePayloadSize;
|
||||
int32_t payloadSize3Real =
|
||||
payloadSize3 + payloadSize2Real % PVA_ALIGNMENT;
|
||||
int32_t payloadSize3Real = payloadSize3;
|
||||
|
||||
codec._readBuffer->putInt(payloadSize3Real);
|
||||
|
||||
// pre-message padding required
|
||||
for (int32_t i = 0;
|
||||
i < payloadSize2Real % PVA_ALIGNMENT; i++)
|
||||
codec._readBuffer->put((int8_t)0xEE);
|
||||
|
||||
for (int32_t i = 0; i < payloadSize3; i++)
|
||||
codec._readBuffer->put((int8_t)(c++));
|
||||
|
||||
aligned =
|
||||
AbstractCodec::alignedValue(
|
||||
payloadSize3Real, PVA_ALIGNMENT);
|
||||
aligned = payloadSize3Real;
|
||||
|
||||
for (std::size_t i = payloadSize3Real;
|
||||
i < aligned; i++)
|
||||
@@ -2915,35 +2746,6 @@ private:
|
||||
{
|
||||
testDiag("BEGIN TEST %s:", CURRENT_FUNCTION);
|
||||
|
||||
if (PVA_ALIGNMENT > 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
// non aligned
|
||||
TestCodec codec(2*AbstractCodec::MAX_ENSURE_SIZE+1,
|
||||
DEFAULT_BUFFER_SIZE);
|
||||
|
||||
testFail("%s: non-aligned buffer size accepted",
|
||||
CURRENT_FUNCTION);
|
||||
|
||||
} catch (std::exception &) {
|
||||
// OK
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// non aligned
|
||||
TestCodec codec(DEFAULT_BUFFER_SIZE,
|
||||
2*AbstractCodec::MAX_ENSURE_SIZE+1);
|
||||
|
||||
testFail("%s: non-aligned buffer size accepted",
|
||||
CURRENT_FUNCTION);
|
||||
|
||||
} catch (std::exception &) {
|
||||
// OK
|
||||
}
|
||||
}
|
||||
|
||||
TestCodec codec(DEFAULT_BUFFER_SIZE,
|
||||
DEFAULT_BUFFER_SIZE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user