Clean up callback_list, remove sentinel/active/tail, callbacks return bool for removal, register before send

This commit is contained in:
Ian Gulliver
2026-04-11 15:01:37 +09:00
parent 938b4b8a4c
commit 1c8c645878
5 changed files with 66 additions and 72 deletions

View File

@@ -72,7 +72,7 @@ static void process_frame(std::span<const uint8_t> frame, span_writer& tx) {
if (!mac_match(eth_hdr.dst)) return;
frame_callbacks.for_each([&](frame_cb_list::node* n) {
if (n->value().fn(frame))
if (n->value(frame))
frame_callbacks.remove(n);
});
@@ -123,7 +123,9 @@ void net_set_handler(net_handler handler) {
}
frame_cb_handle net_add_frame_callback(net_frame_callback cb) {
return frame_callbacks.insert({std::move(cb)});
auto h = frame_callbacks.insert(std::move(cb));
if (!h) dlog("frame callback alloc failed");
return h;
}
void net_remove_frame_callback(frame_cb_handle h) {
@@ -135,7 +137,7 @@ void net_poll(std::span<uint8_t> tx) {
w6300::irq_pending = false;
w6300::clear_interrupt(w6300::ik_int_all);
static uint8_t rx_buf[1518];
int budget = 2;
int budget = 10;
while (budget-- > 0 && w6300::get_socket_recv_buf(raw_socket) > 0) {
auto result = w6300::recv(raw_socket, std::span{rx_buf});
if (!result) break;