1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 18:05:07 +00:00

Kernel: Make KBuffer a value-type wrapper around a KBufferImpl

A KBuffer always contains a valid KBufferImpl. If you need a "null"
state buffer, use Optional<KBuffer>.

This makes KBuffer very easy to work with and pass around, just like
ByteBuffer before it.
This commit is contained in:
Andreas Kling 2019-08-05 11:06:21 +02:00
parent 52cfe9ebae
commit 605975adb5
6 changed files with 50 additions and 22 deletions

View file

@ -44,11 +44,11 @@ void NetworkTask_main()
if (adapter)
adapter->set_ipv4_address(IPv4Address(192, 168, 5, 2));
auto dequeue_packet = [&]() -> RefPtr<KBuffer> {
auto dequeue_packet = [&]() -> Optional<KBuffer> {
auto packet = LoopbackAdapter::the().dequeue_packet();
if (!packet.is_null()) {
dbgprintf("Receive loopback packet (%d bytes)\n", packet->size());
return packet;
if (packet.has_value()) {
dbgprintf("Receive loopback packet (%d bytes)\n", packet.value().size());
return packet.value();
}
if (adapter && adapter->has_queued_packets())
return adapter->dequeue_packet();
@ -58,7 +58,7 @@ void NetworkTask_main()
kprintf("NetworkTask: Enter main loop.\n");
for (;;) {
auto packet_maybe_null = dequeue_packet();
if (packet_maybe_null.is_null()) {
if (!packet_maybe_null.has_value()) {
(void)current->block_until("Networking", [] {
if (LoopbackAdapter::the().has_queued_packets())
return true;
@ -70,7 +70,7 @@ void NetworkTask_main()
});
continue;
}
auto& packet = *packet_maybe_null;
auto& packet = packet_maybe_null.value();
if (packet.size() < (int)(sizeof(EthernetFrameHeader))) {
kprintf("NetworkTask: Packet is too small to be an Ethernet packet! (%d)\n", packet.size());
continue;