6#include <condition_variable>
88 std::lock_guard<std::mutex> lock(
mutex);
102 [[nodiscard]] std::chrono::milliseconds
Timeout()
const
109 void OnSend(std::function<
void()> callback)
111 onSend = std::move(callback);
123 std::lock_guard<std::mutex> lock(
mutex);
149 return std::move(action.
data);
204 std::unique_lock lock(
mutex);
217 std::lock_guard lock(
mutex);
226 std::unique_lock lock(
mutex);
267 std::shared_ptr<LifetimeTrackingSocketState>
state)
274 if (
state->receiveActive.load(std::memory_order_acquire))
276 state->destroyedWhileReceiving.store(
277 true, std::memory_order_release);
280 state->destroyed.store(
true, std::memory_order_release);
289 state->receiveActive.store(
true, std::memory_order_release);
292 std::lock_guard lock(
state->mutex);
293 state->receiveEntered =
true;
296 state->receiveEnteredCv.notify_one();
299 std::unique_lock lock(
state->mutex);
300 state->receiveCv.wait(lock, [
this]
302 return state->releaseReceive;
306 state->receiveActive.store(
false, std::memory_order_release);
309 std::lock_guard lock(
state->mutex);
310 state->receiveExited =
true;
313 state->receiveExitedCv.notify_one();
324 std::unique_lock lock(
state->mutex);
326 state->receiveEnteredCv.wait(lock, [
this]
328 return state->receiveEntered;
334 std::unique_lock lock(
state->mutex);
336 state->receiveExitedCv.wait(lock, [
this]
338 return state->receiveExited;
345 std::lock_guard lock(
state->mutex);
346 state->releaseReceive =
true;
349 state->receiveCv.notify_one();
353 std::shared_ptr<LifetimeTrackingSocketState>
state;
Abstraction for sending and receiving raw Ethernet frames.
Abstract interface for raw Ethernet frame transport.
Bytes Recv() override
Receive one raw Ethernet frame.
std::condition_variable receiveCv
void Send(const Bytes &frame) override
Send one complete raw Ethernet frame.
void SetTimeout(std::chrono::milliseconds timeout) override
Set the receive timeout.
void WaitUntilReceiveEntered()
std::condition_variable receiveEnteredCv
Deterministic socket stub used by cyclic controller unit tests.
void QueueTimeout()
Queue a receive timeout result represented by an empty frame.
void SetRecvExceptionMessage(std::string message)
Configure the exception message used by Recv().
void SetSendThrows(bool enabled)
Configure whether Send() throws.
void SetTimeout(std::chrono::milliseconds value) override
Configure the receive timeout.
bool sendThrows
Whether Send() throws an exception.
void OnSend(std::function< void()> callback)
Register a callback invoked after every successful Send().
void SetSendExceptionMessage(std::string message)
Configure the exception message used by Send().
const Bytes & SentFrame(std::size_t index) const
Return a transmitted frame.
std::chrono::milliseconds Timeout() const
Return the most recently configured socket timeout.
Bytes Recv() override
Receive the next queued frame or timeout.
std::string sendExceptionMessage
Send exception text.
std::deque< ReceiveAction > receiveActions
Queued receive actions consumed by Recv().
std::vector< Bytes > sentFrames
Frames successfully sent through the stub.
void QueueReceive(Bytes data)
Queue a received Ethernet frame.
std::size_t SentFrameCount() const
Return the number of frames sent through the stub.
void Send(const Bytes &data) override
Send an Ethernet frame through the stub.
std::chrono::milliseconds timeout
Timeout configured through SetTimeout().
std::string recvExceptionMessage
Receive exception text.
std::function< void()> onSend
Callback invoked after a successful send.
void QueueReceiveException()
Queue a receive exception.
std::shared_ptr< LifetimeTrackingSocketState > state
void WaitUntilReceiveExited()
~LifetimeTrackingRawEthernetSocket() override
void WaitUntilReceiveEntered()
void SetTimeout(std::chrono::milliseconds) override
Set the receive timeout.
Bytes Recv() override
Receive one raw Ethernet frame.
LifetimeTrackingRawEthernetSocket(std::shared_ptr< LifetimeTrackingSocketState > state)
void Send(const Bytes &) override
Send one complete raw Ethernet frame.
std::vector< std::uint8_t > Bytes
Generic byte buffer alias used throughout the library for raw wire data.
PROFINET protocol wire-format structures and serialization helpers.
std::condition_variable receiveEnteredCv
std::condition_variable releaseReceiveCv
Bytes data
Bytes returned by Recv() when no exception is requested.
bool throwException
Whether Recv() throws instead of returning data.
std::atomic< bool > destroyed
std::atomic< bool > receiveActive
std::atomic< bool > destroyedWhileReceiving
std::condition_variable receiveExitedCv
std::condition_variable receiveCv
std::condition_variable receiveEnteredCv
Declares Linux Ethernet, addressing, timing, and utility helpers used by the PROFINET stack.