|
28 | 28 | extern "C" { |
29 | 29 | #include <solo5.h> |
30 | 30 | } |
31 | | - |
| 31 | +static const uint32_t NUM_BUFFERS = 1024; |
32 | 32 | using namespace net; |
33 | 33 |
|
34 | 34 | const char* Solo5Net::driver_name() const { return "Solo5Net"; } |
35 | 35 |
|
36 | 36 | Solo5Net::Solo5Net() |
37 | 37 | : Link(Link_protocol{{this, &Solo5Net::transmit}, mac()}, |
38 | | - 2048u, sizeof(net::Packet) + MTU()), |
| 38 | + NUM_BUFFERS, 2048u), // don't change this |
39 | 39 | packets_rx_{Statman::get().create(Stat::UINT64, device_name() + ".packets_rx").get_uint64()}, |
40 | 40 | packets_tx_{Statman::get().create(Stat::UINT64, device_name() + ".packets_tx").get_uint64()} |
41 | 41 | { |
@@ -70,32 +70,29 @@ void Solo5Net::transmit(net::Packet_ptr pckt) |
70 | 70 | } |
71 | 71 | } |
72 | 72 |
|
73 | | -std::unique_ptr<Packet> |
74 | | -Solo5Net::create_packet(int link_offset) |
| 73 | +net::Packet_ptr Solo5Net::create_packet(int link_offset) |
75 | 74 | { |
76 | 75 | auto buffer = bufstore().get_buffer(); |
77 | 76 | auto* pckt = (net::Packet*) buffer.addr; |
78 | 77 |
|
79 | 78 | new (pckt) net::Packet(link_offset, 0, packet_len(), buffer.bufstore); |
80 | 79 | return net::Packet_ptr(pckt); |
81 | 80 | } |
82 | | - |
83 | | -std::unique_ptr<Packet> |
84 | | -Solo5Net::recv_packet() |
| 81 | +net::Packet_ptr Solo5Net::recv_packet() |
85 | 82 | { |
86 | 83 | auto buffer = bufstore().get_buffer(); |
87 | 84 | auto* pckt = (net::Packet*) buffer.addr; |
88 | | - new (pckt) net::Packet(0, MTU(), packet_len(), &bufstore()); |
89 | | - uint8_t *buf = pckt->buf(); |
| 85 | + new (pckt) net::Packet(0, MTU(), packet_len(), buffer.bufstore); |
90 | 86 | // Populate the packet buffer with new packet, if any |
91 | 87 | int size = MTU(); |
92 | | - if (solo5_net_read_sync(buf, &size) == 0) { |
| 88 | + if (solo5_net_read_sync(pckt->buf(), &size) == 0) { |
93 | 89 | // Adjust packet size to match received data |
94 | 90 | if (size) { |
95 | 91 | pckt->set_data_end(size); |
96 | 92 | return net::Packet_ptr(pckt); |
97 | 93 | } |
98 | 94 | } |
| 95 | + bufstore().release(buffer.addr); |
99 | 96 | return nullptr; |
100 | 97 | } |
101 | 98 |
|
|
0 commit comments