netlink: Use function views

These provide type erasure without requiring us to copy anything into
function objects.

Change-Id: I4dcddb54b1b78d36945ac4c976a1be55bed1c0f9
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/netlink.cpp b/src/netlink.cpp
index 011cf95..4ac7c8b 100644
--- a/src/netlink.cpp
+++ b/src/netlink.cpp
@@ -19,7 +19,7 @@
 namespace detail
 {
 
-void processMsg(std::string_view& msgs, bool& done, const ReceiveCallback& cb)
+void processMsg(std::string_view& msgs, bool& done, ReceiveCallback cb)
 {
     // Parse and update the message buffer
     auto hdr = stdplus::raw::copyFrom<nlmsghdr>(msgs);
@@ -73,7 +73,7 @@
     }
 }
 
-static void receive(int sock, const ReceiveCallback& cb)
+static void receive(int sock, ReceiveCallback cb)
 {
     // We need to make sure we have enough room for an entire packet otherwise
     // it gets truncated. The netlink docs guarantee packets will not exceed 8K
@@ -156,8 +156,7 @@
     return sock;
 }
 
-void performRequest(int protocol, void* data, size_t size,
-                    const ReceiveCallback& cb)
+void performRequest(int protocol, void* data, size_t size, ReceiveCallback cb)
 {
     auto sock = makeSocket(protocol);
     requestSend(sock.get(), data, size);
diff --git a/src/netlink.hpp b/src/netlink.hpp
index e1a8253..2168972 100644
--- a/src/netlink.hpp
+++ b/src/netlink.hpp
@@ -2,7 +2,7 @@
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
 
-#include <functional>
+#include <function2/function2.hpp>
 #include <string_view>
 #include <tuple>
 #include <type_traits>
@@ -16,15 +16,15 @@
 
 /* @brief Called on each nlmsg received on the socket
  */
-using ReceiveCallback = std::function<void(const nlmsghdr&, std::string_view)>;
+using ReceiveCallback =
+    fu2::function_view<void(const nlmsghdr&, std::string_view)>;
 
 namespace detail
 {
 
-void processMsg(std::string_view& msgs, bool& done, const ReceiveCallback& cb);
+void processMsg(std::string_view& msgs, bool& done, ReceiveCallback cb);
 
-void performRequest(int protocol, void* data, size_t size,
-                    const ReceiveCallback& cb);
+void performRequest(int protocol, void* data, size_t size, ReceiveCallback cb);
 
 } // namespace detail
 
@@ -47,7 +47,7 @@
  */
 template <typename T>
 void performRequest(int protocol, uint16_t type, uint16_t flags, const T& msg,
-                    const ReceiveCallback& cb)
+                    ReceiveCallback cb)
 {
     static_assert(std::is_trivially_copyable_v<T>);