Skip to content

Commit

Permalink
[C/C++] Ensure media driver is ready before requesting termination.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Apr 12, 2022
1 parent efbb23b commit c0807c9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
9 changes: 9 additions & 0 deletions aeron-client/src/main/c/aeron_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,15 @@ int aeron_context_request_driver_termination(const char *directory, const uint8_

aeron_cnc_metadata_t *metadata = (aeron_cnc_metadata_t *)cnc_mmap.addr;
int32_t cnc_version = aeron_cnc_version_volatile(metadata);

if (cnc_version <= 0)
{
AERON_SET_ERR(EINVAL, "Aeron CnC not initialised");

result = -1;
goto cleanup;
}

if (aeron_semantic_version_major(cnc_version) != aeron_semantic_version_major(AERON_CNC_VERSION))
{
AERON_SET_ERR(
Expand Down
44 changes: 24 additions & 20 deletions aeron-client/src/main/cpp/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,32 @@ bool Context::requestDriverTermination(
if (fileLength > static_cast<std::size_t>(minLength))
{
const std::int32_t cncVersion = CncFileDescriptor::cncVersionVolatile(cncFile);
if (semanticVersionMajor(cncVersion) != semanticVersionMajor(CncFileDescriptor::CNC_VERSION))
{
throw AeronException(
"Aeron CnC version does not match:"
" app=" + semanticVersionToString(CncFileDescriptor::CNC_VERSION) +
" file=" + semanticVersionToString(cncVersion),
SOURCEINFO);
}

if (!CncFileDescriptor::isCncFileLengthSufficient(cncFile))

if (cncVersion > 0)
{
throw AeronException(
"Aeron CnC file length not sufficient: length=" + std::to_string(fileLength), SOURCEINFO);
if (semanticVersionMajor(cncVersion) != semanticVersionMajor(CncFileDescriptor::CNC_VERSION))
{
throw AeronException(
"Aeron CnC version does not match:"
" app=" + semanticVersionToString(CncFileDescriptor::CNC_VERSION) +
" file=" + semanticVersionToString(cncVersion),
SOURCEINFO);
}

if (!CncFileDescriptor::isCncFileLengthSufficient(cncFile))
{
throw AeronException(
"Aeron CnC file length not sufficient: length=" + std::to_string(fileLength), SOURCEINFO);
}

AtomicBuffer toDriverBuffer(CncFileDescriptor::createToDriverBuffer(cncFile));
ManyToOneRingBuffer ringBuffer(toDriverBuffer);
DriverProxy driverProxy(ringBuffer);

driverProxy.terminateDriver(tokenBuffer, tokenLength);

return true;
}

AtomicBuffer toDriverBuffer(CncFileDescriptor::createToDriverBuffer(cncFile));
ManyToOneRingBuffer ringBuffer(toDriverBuffer);
DriverProxy driverProxy(ringBuffer);

driverProxy.terminateDriver(tokenBuffer, tokenLength);

return true;
}
}

Expand Down

0 comments on commit c0807c9

Please sign in to comment.