summaryrefslogtreecommitdiff
path: root/Kernel/NetworkAdapter.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-20 17:09:46 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-20 17:09:46 +0100
commitbc1da7f1fd2e366d290db4b33f07b9806d2a6932 (patch)
tree8b72a3606893dd69113fd47fe97c47c2abdd1907 /Kernel/NetworkAdapter.h
parent93aa4d581d98155e7f49880ba600bb32acd2659f (diff)
downloadserenity-bc1da7f1fd2e366d290db4b33f07b9806d2a6932.zip
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.
Diffstat (limited to 'Kernel/NetworkAdapter.h')
-rw-r--r--Kernel/NetworkAdapter.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/Kernel/NetworkAdapter.h b/Kernel/NetworkAdapter.h
index 512c80dfa4..a040aaced2 100644
--- a/Kernel/NetworkAdapter.h
+++ b/Kernel/NetworkAdapter.h
@@ -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;
};