diff --git a/AdsLib/AdsNotification.h b/AdsLib/AdsNotification.h index a0a2631b..3d087b7f 100644 --- a/AdsLib/AdsNotification.h +++ b/AdsLib/AdsNotification.h @@ -23,28 +23,29 @@ struct Notification { : connection({__port, __amsAddr}), callback(__func), buffer(sizeof(AdsNotificationHeader) + length), - hUser(__hUser) + hUser(__hUser), + size(length) { auto header = reinterpret_cast(buffer.data()); header->hNotification = 0; header->cbSampleSize = length; } - void Notify(uint64_t timestamp, RingBuffer& ring) + void Notify(RingBuffer& ring, const uint64_t timestamp, const uint32_t sampleSize) { auto header = reinterpret_cast(buffer.data()); uint8_t* data = reinterpret_cast(header + 1); - for (size_t i = 0; i < header->cbSampleSize; ++i) { + header->cbSampleSize = sampleSize; + header->nTimeStamp = timestamp; + for (size_t i = 0; i < sampleSize; ++i) { data[i] = ring.ReadFromLittleEndian(); } - header->nTimeStamp = timestamp; callback(&connection.second, header, hUser); } uint32_t Size() const { - auto header = reinterpret_cast(buffer.data()); - return header->cbSampleSize; + return size; } void hNotify(uint32_t value) @@ -57,4 +58,5 @@ struct Notification { const PAdsNotificationFuncEx callback; std::vector buffer; const uint32_t hUser; + const uint32_t size; }; diff --git a/AdsLib/standalone/NotificationDispatcher.cpp b/AdsLib/standalone/NotificationDispatcher.cpp index bbad71cf..2acaafd5 100644 --- a/AdsLib/standalone/NotificationDispatcher.cpp +++ b/AdsLib/standalone/NotificationDispatcher.cpp @@ -72,11 +72,11 @@ void NotificationDispatcher::Run() fullLength -= sizeof(hNotify) + sizeof(size); const auto notification = Find(hNotify); if (notification) { - if (size != notification->Size()) { - LOG_WARN("Notification sample size: " << size << " doesn't match: " << notification->Size()); + if (size > notification->Size()) { + LOG_WARN("Notification sample size: " << size << " to large: " << notification->Size()); goto cleanup; } - notification->Notify(timestamp, ring); + notification->Notify(ring, timestamp, size); } else { ring.Read(size); }