DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dpdklibs
include
dpdklibs
sender
TxEngine.hpp
Go to the documentation of this file.
1
31
#ifndef DPDKLIBS_INCLUDE_DPDKLIBS_SENDER_TXENGINE_HPP_
32
#define DPDKLIBS_INCLUDE_DPDKLIBS_SENDER_TXENGINE_HPP_
33
34
#include <cstddef>
35
#include <cstdint>
36
#include <cstring>
37
38
namespace
dunedaq::dpdklibs::sender
{
39
40
enum class
TxOutcome
41
{
42
kSent
,
// backend took ownership of the buffer
43
kAllocFailed
,
// no buffer was available
44
kPrepareFailed
,
// append rejected: insufficient tailroom
45
kTxFailed
// backend refused the packet; buffer freed
46
};
47
48
template
<
typename
Backend>
49
class
BufGuard
50
{
51
public
:
52
BufGuard
(Backend& backend,
void
* buf)
53
:
m_backend
(backend)
54
,
m_buf
(buf)
55
{
56
}
57
~BufGuard
()
58
{
59
if
(
m_buf
!=
nullptr
) {
60
m_backend
.free(
m_buf
);
61
}
62
}
63
BufGuard
(
const
BufGuard
&) =
delete
;
64
BufGuard
&
operator=
(
const
BufGuard
&) =
delete
;
65
BufGuard
(
BufGuard
&&) =
delete
;
66
BufGuard
&
operator=
(
BufGuard
&&) =
delete
;
67
68
void
release
() {
m_buf
=
nullptr
; }
69
70
private
:
71
Backend&
m_backend
;
72
void
*
m_buf
;
73
};
74
75
// Allocate, build, and transmit one packet.
76
//
77
// - build(dst) writes exactly packet_bytes into dst.
78
// - If pre_tx_copy is non-null, the constructed bytes are copied there before
79
// the transmit attempt. The buffer is not readable after a successful
80
// transmit, so this copy is the only record of the transmitted bytes.
81
// - on_sent() runs only after a successful transmit.
82
template
<
typename
Backend,
typename
BuildFn,
typename
OnSentFn>
83
TxOutcome
84
send_packet
(Backend& backend, std::size_t packet_bytes, std::uint8_t* pre_tx_copy, BuildFn&& build, OnSentFn&& on_sent)
85
{
86
void
* buf = backend.alloc();
87
if
(buf ==
nullptr
) {
88
return
TxOutcome::kAllocFailed
;
89
}
90
BufGuard<Backend>
guard(backend, buf);
91
92
std::uint8_t* dst = backend.prepare(buf, packet_bytes);
93
if
(dst ==
nullptr
) {
94
return
TxOutcome::kPrepareFailed
;
95
}
96
97
build(dst);
98
if
(pre_tx_copy !=
nullptr
) {
99
std::memcpy(pre_tx_copy, dst, packet_bytes);
100
}
101
102
if
(!backend.transmit(buf)) {
103
return
TxOutcome::kTxFailed
;
104
}
105
106
guard.
release
();
107
on_sent();
108
return
TxOutcome::kSent
;
109
}
110
111
}
// namespace dunedaq::dpdklibs::sender
112
113
#endif
// DPDKLIBS_INCLUDE_DPDKLIBS_SENDER_TXENGINE_HPP_
dunedaq::dpdklibs::sender::BufGuard
Definition
TxEngine.hpp:50
dunedaq::dpdklibs::sender::BufGuard::release
void release()
Definition
TxEngine.hpp:68
dunedaq::dpdklibs::sender::BufGuard::BufGuard
BufGuard(Backend &backend, void *buf)
Definition
TxEngine.hpp:52
dunedaq::dpdklibs::sender::BufGuard::m_buf
void * m_buf
Definition
TxEngine.hpp:72
dunedaq::dpdklibs::sender::BufGuard::m_backend
Backend & m_backend
Definition
TxEngine.hpp:71
dunedaq::dpdklibs::sender::BufGuard::operator=
BufGuard & operator=(BufGuard &&)=delete
dunedaq::dpdklibs::sender::BufGuard::BufGuard
BufGuard(BufGuard &&)=delete
dunedaq::dpdklibs::sender::BufGuard::~BufGuard
~BufGuard()
Definition
TxEngine.hpp:57
dunedaq::dpdklibs::sender::BufGuard::operator=
BufGuard & operator=(const BufGuard &)=delete
dunedaq::dpdklibs::sender::BufGuard::BufGuard
BufGuard(const BufGuard &)=delete
dunedaq::dpdklibs::sender
Definition
CallbackGate.hpp:35
dunedaq::dpdklibs::sender::send_packet
TxOutcome send_packet(Backend &backend, std::size_t packet_bytes, std::uint8_t *pre_tx_copy, BuildFn &&build, OnSentFn &&on_sent)
Definition
TxEngine.hpp:84
dunedaq::dpdklibs::sender::TxOutcome
TxOutcome
Definition
TxEngine.hpp:41
dunedaq::dpdklibs::sender::TxOutcome::kTxFailed
@ kTxFailed
Definition
TxEngine.hpp:45
dunedaq::dpdklibs::sender::TxOutcome::kPrepareFailed
@ kPrepareFailed
Definition
TxEngine.hpp:44
dunedaq::dpdklibs::sender::TxOutcome::kAllocFailed
@ kAllocFailed
Definition
TxEngine.hpp:43
dunedaq::dpdklibs::sender::TxOutcome::kSent
@ kSent
Definition
TxEngine.hpp:42
Generated on
for DUNE-DAQ by
1.18.0