Browse Source

JackRequest: Add end marker and verify them on read

Without this marker partly written messages cannot be detected before
processing them.

Change-Id: I38802e9df2a09d1ad0371aba80fc1523cec2ddfe
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
pull/386/head
Timo Wischer Timo Wischer 7 years ago
parent
commit
b346a8e278
1 changed files with 12 additions and 0 deletions
  1. +12
    -0
      common/JackRequest.h

+ 12
- 0
common/JackRequest.h View File

@@ -94,6 +94,7 @@ struct JackRequest
};

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

static int ReadType(detail::JackChannelTransactionInterface* trans, RequestType& type)
{
@@ -136,6 +137,8 @@ protected:
public:
DATA d;
protected:
const int fEnd = JackRequest::EndMarker;

template<typename... Args>
JackRequestMessage(Args&... args) : fType(DATA::Type()),
fSize(sizeof(JackRequestMessage<DATA>) - sizeof(fStart) - sizeof(fType) - sizeof(fSize)),
@@ -151,7 +154,16 @@ protected:
return -1;
}

/* Size also contains fEnd */
CheckRes(trans->Read(&d, fSize));
if (fEnd != JackRequest::EndMarker) {
jack_error("Request end marker not found (exp %08x act %08x). Request of type %d will be ignored!",
JackRequest::EndMarker, fEnd, fType);

/* no need to sync here. Will be done by JackRequest::ReadType() */
return -1;
}

return 0;
}



Loading…
Cancel
Save