6#include <asio/posix/stream_descriptor.hpp>
17 const int selectableFd =
18 pcap_get_selectable_fd(
capture);
26 const int duplicatedFd = ::dup(selectableFd);
30 throw SocketError(
"Failed to duplicate libpcap selectable descriptor: " + std::string(std::strerror(errno)));
33 asio::error_code
error;
39 ::close(duplicatedFd);
41 throw SocketError(
"Failed to assign libpcap descriptor to Asio: " +
error.message());
51 operation->pollTimer.expires_after(std::chrono::milliseconds(1));
53 operation->pollTimer.async_wait([
this, operation](
const asio::error_code&
error)
55 HandlePacketReady(operation,
error);
61 packetWait.async_wait(asio::posix::stream_descriptor::wait_read, [
this, operation](
const asio::error_code&
error)
63 HandlePacketReady(operation,
error);
71 operation->pollTimer.cancel(
error);
75 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.