Browse Source

JackRequest: Add start marker and verify it on read

Change-Id: Ib3f3e9faf4ec7d6e210ed7d50a74d8921410dfbb
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
pull/548/head
Timo Wischer Adam Miartus 7 years ago
parent
commit
3ed6db72bc
1 changed files with 20 additions and 1 deletions
  1. +20
    -1
      common/JackRequest.h

+ 20
- 1
common/JackRequest.h View File

@@ -93,9 +93,27 @@ struct JackRequest
kPropertyChangeNotify = 40, kPropertyChangeNotify = 40,
}; };


static const int StartMarker = 'R' | ('e' << 8) | ('q' << 16) | ('S' << 24);

static int ReadType(detail::JackChannelTransactionInterface* trans, RequestType& type) static int ReadType(detail::JackChannelTransactionInterface* trans, RequestType& type)
{ {
type = (RequestType)0; type = (RequestType)0;

do {
PRE_PACKED_STRUCTURE
union {
int i;
uint8_t b[sizeof(i)];
} POST_PACKED_STRUCTURE start;

CheckRes(trans->Read(&start.i, sizeof(StartMarker)));
if (start.i != StartMarker) {
jack_error("Request start marker not found. Ignoring %02x %02x %02x %02x ",
start.b[0], start.b[1], start.b[2], start.b[3]);
continue;
}
} while (false);

CheckRes(trans->Read(&type, sizeof(RequestType))); CheckRes(trans->Read(&type, sizeof(RequestType)));
return 0; return 0;
} }
@@ -112,6 +130,7 @@ template<class DATA>
struct JackRequestMessage struct JackRequestMessage
{ {
protected: protected:
const int fStart = JackRequest::StartMarker;
const JackRequest::RequestType fType; const JackRequest::RequestType fType;
const int fSize; const int fSize;
public: public:
@@ -120,7 +139,7 @@ public:
protected: protected:
template<typename... Args> template<typename... Args>
JackRequestMessage(Args&... args) : fType(DATA::Type()), JackRequestMessage(Args&... args) : fType(DATA::Type()),
fSize(sizeof(JackRequestMessage<DATA>) - sizeof(fType) - sizeof(fSize)),
fSize(sizeof(JackRequestMessage<DATA>) - sizeof(fStart) - sizeof(fType) - sizeof(fSize)),
d(args...) d(args...)
{} {}




Loading…
Cancel
Save