1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:47:34 +00:00

Kernel: Snooze the NetworkTask until there are incoming packets to process.

This is accomplished using a new Alarm class and a BlockedSnoozing state.
Basically, you call Process::snooze_until(some_alarm) and then the scheduler
won't wake up the process until some_alarm.is_ringing() returns true.
This commit is contained in:
Andreas Kling 2019-03-20 17:09:46 +01:00
parent 93aa4d581d
commit bc1da7f1fd
6 changed files with 51 additions and 6 deletions

View file

@ -7,6 +7,18 @@
#include <Kernel/IPv4.h>
#include <Kernel/ARP.h>
#include <Kernel/ICMP.h>
#include <Kernel/Alarm.h>
class NetworkAdapter;
class PacketQueueAlarm final : public Alarm {
public:
PacketQueueAlarm(NetworkAdapter& adapter) : m_adapter(adapter) { }
virtual ~PacketQueueAlarm() override { }
virtual bool is_ringing() const override;
private:
NetworkAdapter& m_adapter;
};
class NetworkAdapter {
public:
@ -24,6 +36,10 @@ public:
ByteBuffer dequeue_packet();
Alarm& packet_queue_alarm() { return m_packet_queue_alarm; }
bool has_queued_packets() const { return !m_packet_queue.is_empty(); }
protected:
NetworkAdapter();
void set_mac_address(const MACAddress& mac_address) { m_mac_address = mac_address; }
@ -33,5 +49,6 @@ protected:
private:
MACAddress m_mac_address;
IPv4Address m_ipv4_address;
PacketQueueAlarm m_packet_queue_alarm;
SinglyLinkedList<ByteBuffer> m_packet_queue;
};