Explorar el Código

Kernel: Add on_receive callback to NetworkAdapter

Conrad Pankoff hace 5 años
padre
commit
36d349f7a7
Se han modificado 2 ficheros con 5 adiciones y 0 borrados
  1. 2 0
      Kernel/Net/NetworkAdapter.cpp
  2. 3 0
      Kernel/Net/NetworkAdapter.h

+ 2 - 0
Kernel/Net/NetworkAdapter.cpp

@@ -88,6 +88,8 @@ void NetworkAdapter::did_receive(const u8* data, int length)
     m_packets_in++;
     m_packets_in++;
     m_bytes_in += length;
     m_bytes_in += length;
     m_packet_queue.append(KBuffer::copy(data, length));
     m_packet_queue.append(KBuffer::copy(data, length));
+    if (m_on_receive)
+        m_on_receive();
 }
 }
 
 
 Optional<KBuffer> NetworkAdapter::dequeue_packet()
 Optional<KBuffer> NetworkAdapter::dequeue_packet()

+ 3 - 0
Kernel/Net/NetworkAdapter.h

@@ -45,6 +45,8 @@ public:
     u32 packets_out() const { return m_packets_out; }
     u32 packets_out() const { return m_packets_out; }
     u32 bytes_out() const { return m_bytes_out; }
     u32 bytes_out() const { return m_bytes_out; }
 
 
+    void set_on_receive(Function<void()> on_receive) { m_on_receive = move(on_receive); }
+
 protected:
 protected:
     NetworkAdapter();
     NetworkAdapter();
     void set_interface_name(const StringView& basename);
     void set_interface_name(const StringView& basename);
@@ -63,4 +65,5 @@ private:
     u32 m_bytes_in { 0 };
     u32 m_bytes_in { 0 };
     u32 m_packets_out { 0 };
     u32 m_packets_out { 0 };
     u32 m_bytes_out { 0 };
     u32 m_bytes_out { 0 };
+    Function<void()> m_on_receive;
 };
 };