mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:08:12 +00:00
NetworkTask: Add a combined alarm for the all network adapters.
This way we can go back to snoozing in the receiver task and stop chewing up the CPU. :^)
This commit is contained in:
parent
bcc00857a4
commit
329cc60a92
1 changed files with 24 additions and 4 deletions
|
@ -34,6 +34,22 @@ Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
|
||||||
return *the;
|
return *the;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CombinedPacketQueueAlarm : public Alarm {
|
||||||
|
public:
|
||||||
|
CombinedPacketQueueAlarm() { }
|
||||||
|
|
||||||
|
virtual bool is_ringing() const override
|
||||||
|
{
|
||||||
|
if (LoopbackAdapter::the().has_queued_packets())
|
||||||
|
return true;
|
||||||
|
if (auto* e1000 = E1000NetworkAdapter::the()) {
|
||||||
|
if (e1000->has_queued_packets())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void NetworkTask_main()
|
void NetworkTask_main()
|
||||||
{
|
{
|
||||||
LoopbackAdapter::the();
|
LoopbackAdapter::the();
|
||||||
|
@ -44,19 +60,23 @@ void NetworkTask_main()
|
||||||
adapter.set_ipv4_address(IPv4Address(192, 168, 5, 2));
|
adapter.set_ipv4_address(IPv4Address(192, 168, 5, 2));
|
||||||
|
|
||||||
auto dequeue_packet = [&] () -> ByteBuffer {
|
auto dequeue_packet = [&] () -> ByteBuffer {
|
||||||
if (LoopbackAdapter::the().has_queued_packets())
|
auto packet = LoopbackAdapter::the().dequeue_packet();
|
||||||
return LoopbackAdapter::the().dequeue_packet();
|
if (!packet.is_null()) {
|
||||||
|
dbgprintf("Receive loopback packet (%d bytes)\n", packet.size());
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
if (adapter.has_queued_packets())
|
if (adapter.has_queued_packets())
|
||||||
return adapter.dequeue_packet();
|
return adapter.dequeue_packet();
|
||||||
return { };
|
return { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CombinedPacketQueueAlarm queue_alarm;
|
||||||
|
|
||||||
kprintf("NetworkTask: Enter main loop.\n");
|
kprintf("NetworkTask: Enter main loop.\n");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto packet = dequeue_packet();
|
auto packet = dequeue_packet();
|
||||||
if (packet.is_null()) {
|
if (packet.is_null()) {
|
||||||
// FIXME: Wake up when one of the adapters has packets.
|
current->snooze_until(queue_alarm);
|
||||||
current->sleep(1);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (packet.size() < (int)(sizeof(EthernetFrameHeader))) {
|
if (packet.size() < (int)(sizeof(EthernetFrameHeader))) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue