7#ifndef WIN32_LEAN_AND_MEAN
8#define WIN32_LEAN_AND_MEAN
13#include <asio/windows/object_handle.hpp>
22 const HANDLE captureEvent = pcap_getevent(
capture);
24 if (captureEvent ==
nullptr || captureEvent == INVALID_HANDLE_VALUE)
30 HANDLE duplicatedEvent =
nullptr;
32 if (!DuplicateHandle(GetCurrentProcess(), captureEvent, GetCurrentProcess(), &duplicatedEvent, 0, FALSE, DUPLICATE_SAME_ACCESS))
34 throw SocketError(
"Failed to duplicate libpcap packet event: error " + std::to_string(GetLastError()));
37 asio::error_code
error;
43 CloseHandle(duplicatedEvent);
45 throw SocketError(
"Failed to assign libpcap event to Asio: " +
error.message());
55 operation->pollTimer.expires_after(std::chrono::milliseconds(1));
57 operation->pollTimer.async_wait([
this, operation](
const asio::error_code&
error)
59 HandlePacketReady(operation,
error);
65 packetWait.async_wait([
this, operation](
const asio::error_code&
error)
67 HandlePacketReady(operation,
error);
75 operation->pollTimer.cancel(
error);
79 packetWait.cancel(
error);
void CancelPacketWait(const std::shared_ptr< ReceiveOperation > &operation, asio::error_code &error)
Cancel the current packet readiness operation.
bool usePolling
True when packet readiness must use timer polling.
pcap_t * capture
libpcap capture handle.
void InitializePacketWait()
Connect the packet source to the Asio readiness mechanism.
asio::posix::stream_descriptor packetWait
Asio wrapper around the duplicated libpcap selectable descriptor.
void AsyncWaitForPacket(const std::shared_ptr< ReceiveOperation > &operation)
Start waiting until a packet source becomes readable.
Private Ethernet packet backend used by AsioEthernetSocket.
Declares exceptions and error types used by the PROFINET IO controller stack.