Replace sorted_list/vector with callback_list doubly-linked list for timers and frame callbacks
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include "net.h"
|
||||
#include <vector>
|
||||
#include "pico/unique_id.h"
|
||||
#include "pico/time.h"
|
||||
#include "eth.h"
|
||||
@@ -18,7 +17,7 @@ static constexpr uint16_t PICOMAP_PORT = __builtin_bswap16(28781);
|
||||
static net_state state;
|
||||
static w6300::socket_id raw_socket{0};
|
||||
static net_handler msg_handler;
|
||||
static std::vector<net_frame_callback> frame_callbacks;
|
||||
static frame_cb_list frame_callbacks;
|
||||
|
||||
void net_send_raw(std::span<const uint8_t> data) {
|
||||
dlog_if_slow("net_send_raw", 1000, [&]{
|
||||
@@ -72,10 +71,10 @@ static void process_frame(std::span<const uint8_t> frame, span_writer& tx) {
|
||||
|
||||
if (!mac_match(eth_hdr.dst)) return;
|
||||
|
||||
auto cbs = std::move(frame_callbacks);
|
||||
frame_callbacks.clear();
|
||||
for (auto& cb : cbs)
|
||||
cb(frame);
|
||||
frame_callbacks.for_each([&](frame_cb_list::node* n) {
|
||||
if (n->value().fn(frame))
|
||||
frame_callbacks.remove(n);
|
||||
});
|
||||
|
||||
switch (eth_hdr.ethertype) {
|
||||
case eth::ETH_ARP:
|
||||
@@ -123,8 +122,12 @@ void net_set_handler(net_handler handler) {
|
||||
msg_handler = std::move(handler);
|
||||
}
|
||||
|
||||
void net_add_frame_callback(net_frame_callback cb) {
|
||||
frame_callbacks.push_back(std::move(cb));
|
||||
frame_cb_handle net_add_frame_callback(net_frame_callback cb) {
|
||||
return frame_callbacks.insert({std::move(cb)});
|
||||
}
|
||||
|
||||
void net_remove_frame_callback(frame_cb_handle h) {
|
||||
frame_callbacks.remove(h);
|
||||
}
|
||||
|
||||
void net_poll(std::span<uint8_t> tx) {
|
||||
|
||||
Reference in New Issue
Block a user