Skip to content

Commit

Permalink
re-factored buffer overflow-fix to handle other than 4 frames per ZMQ…
Browse files Browse the repository at this point in the history
…-msg
  • Loading branch information
Landberg committed Nov 7, 2016
1 parent 53e1317 commit bf87db1
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/InputZeroMQReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,35 +221,35 @@ void InputZeroMQWorker::RecvProcess(struct InputZeroMQThreadData* workerdata)

queue_size = workerdata->in_messages->size();

/* Drop three more incoming ETI frames before
* we start accepting them again, to guarantee
* that we keep transmission frame vs. ETI frame
* phase.
*/
// /* Drop three more incoming ETI frames before
// * we start accepting them again, to guarantee
// * that we keep transmission frame vs. ETI frame
// * phase.
// */
//m_to_drop = 3;
if(workerdata->restart_queue_depth != 0)

// Make sure we drop a multiple of 8 frames.
// There are 4 in each ZMQ-msg, with NUM_FRAMES_PER_ZMQ_MESSAGE = 4 as default.
// We drop the current msg with 4 frames and need to drop another to keep phase.
// Plus the amount we need to reach wanted start depth.
m_to_drop = (8 / NUM_FRAMES_PER_ZMQ_MESSAGE) - 1; // To keep frame phase for all modes.

// Add amount of frames to reach wanted depth in a multiple of 8.
if(workerdata->restart_queue_depth != 0) // We have a restart_queue_depth value defined.
{
etiLog.level(warn) << "resetting ZeroMQ buffer to: " << workerdata->restart_queue_depth;
m_to_drop = (workerdata->max_queued_frames - workerdata->restart_queue_depth) / 4;
m_to_drop += ((workerdata->max_queued_frames - workerdata->restart_queue_depth) / 8) * (8 / NUM_FRAMES_PER_ZMQ_MESSAGE);
}
else
else // We use half the max_queued_frames as default restart value when restart_queue_depth isn't defined.
{
etiLog.level(warn) << "resetting ZeroMQ buffer to: " << workerdata->max_queued_frames / 2;
m_to_drop = workerdata->max_queued_frames / 4;
m_to_drop += ((workerdata->max_queued_frames / 2) / 8) * (8 / NUM_FRAMES_PER_ZMQ_MESSAGE);
}
if(m_to_drop != 0)

if(m_to_drop % (8 / NUM_FRAMES_PER_ZMQ_MESSAGE) == 0)
{
/* Make sure we drop a multiple of 8 frames.
* There are 4 in each ZMQ-msg, and we drop the
* current msg with 4 frames.
*/
if(m_to_drop % 2 == 0)
--m_to_drop;
if(m_to_drop < 0)
{
--m_to_drop;
if(m_to_drop < 0)
{
m_to_drop = 0;
}
m_to_drop = 0;
}
}
}
Expand Down

0 comments on commit bf87db1

Please sign in to comment.