Skip to content

Conversation

@Dimi1010
Copy link
Collaborator

Part of #1838

This PR updates the synchronous capture method.

@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 69.09091% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.44%. Comparing base (9e03913) to head (1376290).

Files with missing lines Patch % Lines
Pcap++/src/PcapLiveDevice.cpp 69.09% 11 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2026      +/-   ##
==========================================
- Coverage   83.46%   83.44%   -0.02%     
==========================================
  Files         311      311              
  Lines       54574    54591      +17     
  Branches    11535    11820     +285     
==========================================
+ Hits        45551    45556       +5     
+ Misses       7839     7836       -3     
- Partials     1184     1199      +15     
Flag Coverage Δ
alpine320 75.86% <50.00%> (-0.03%) ⬇️
fedora42 75.42% <50.00%> (-0.03%) ⬇️
macos-14 81.56% <62.22%> (-0.02%) ⬇️
macos-15 81.55% <62.22%> (-0.02%) ⬇️
mingw32 69.94% <40.62%> (-0.06%) ⬇️
mingw64 69.94% <50.00%> (+0.09%) ⬆️
npcap ?
rhel94 75.43% <51.42%> (-0.03%) ⬇️
ubuntu2004 59.45% <51.42%> (-0.01%) ⬇️
ubuntu2004-zstd 59.55% <51.42%> (-0.04%) ⬇️
ubuntu2204 75.39% <51.42%> (-0.03%) ⬇️
ubuntu2204-icpx 57.83% <55.55%> (-0.03%) ⬇️
ubuntu2404 75.45% <42.85%> (-0.06%) ⬇️
ubuntu2404-arm64 75.54% <50.00%> (+<0.01%) ⬆️
unittest 83.44% <69.09%> (-0.02%) ⬇️
windows-2022 85.38% <66.66%> (+0.11%) ⬆️
windows-2025 85.41% <63.41%> (+0.06%) ⬆️
winpcap 85.42% <68.29%> (-0.13%) ⬇️
xdp 52.96% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Dimi1010 Dimi1010 marked this pull request as ready for review November 19, 2025 23:57
@Dimi1010 Dimi1010 requested a review from seladb as a code owner November 19, 2025 23:57
const int64_t timeoutMs = timeout * 1000; // timeout unit is seconds, let's change it to milliseconds
// A valid timeout is only generated when timeout is positive.
// This means that the timeout timepoint should be after the start time.
const bool hasTimeout = timeout > 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd avoid this variable and use timeout > 0 to indicate timeout is used.

I'd also do:

auto timeoutTime = timeout > 0 ? startTime + std::chrono::milliseconds(static_cast<int64_t>(timeout * 1000)) : 0;


if (std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - startTime).count() >= timeoutMs)
// Check the time only if a valid timeout was specified. Otherwise it would always be true.
if (hasTimeout && currentTime >= timeoutTime)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we set timeoutTime = 0 if timeout <= 0 we probably don't need hasTimeout here

Comment on lines +340 to +359
try
{
if (context->callback(&rawPacket, context->device, context->userCookie))
{
// If the callback returns true, it means that the user wants to stop the capture
PCPP_LOG_DEBUG("Capture callback requested to stop capturing");
context->requestStop = true;
}
}
catch (const std::exception& ex)
{
PCPP_LOG_ERROR("Exception occurred while invoking packet arrival callback: " << ex.what());
context->requestStop = true; // Stop capture on exception
}
catch (...)
{
PCPP_LOG_ERROR("Unknown exception occurred while invoking packet arrival callback");
context->requestStop = true; // Stop capture on unknown exception
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we decided not to catch exceptions here, no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants