Udp Socket: Wrap client_ calls to hide std::function requirement

Currently, returning responses from UdpSockets involve wrapping the response
error in a std::function<...> bound to the client's OnError/OnSendError/OnRead
functions. This change makes the client_ private and has all responses go
through methods in the UdpSocket class
This provides benefits:
  1) Callers don't need to worry about wrapping responses or pushing them to the
     task runner
  2) We ensure that std::move(...) semantics are used for response types, since
     ensuring this happens has a few unexpected and easy-to-miss edge cases

Change-Id: Iac924c1390c8a488c90382101a47c0273578337e
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/1760111
Commit-Queue: Ryan Keane <rwkeane@google.com>
Reviewed-by: mark a. foltz <mfoltz@chromium.org>
Reviewed-by: Max Yakimakha <yakimakha@chromium.org>
diff --git a/platform/api/udp_socket.h b/platform/api/udp_socket.h
index 703f6b0..64b2dbd 100644
--- a/platform/api/udp_socket.h
+++ b/platform/api/udp_socket.h
@@ -139,6 +139,17 @@
   // the duration of this socket's lifetime.
   UdpSocket(TaskRunner* task_runner, Client* client);
 
+  // Methods to take care of posting UdpSocket::Client callbacks for client_ to
+  // task_runner_.
+  void OnError(Error error);
+  void OnSendError(Error error);
+  void OnRead(ErrorOr<UdpPacket> read_data);
+
+ private:
+  // This callback allows other objects to observe the socket's destructor and
+  // act when it is called.
+  std::function<void(UdpSocket*)> deletion_callback_;
+
   // Client to use for callbacks.
   // NOTE: client_ can be nullptr if the user does not want any callbacks (for
   // example, in the send-only case).
@@ -147,11 +158,6 @@
   // Task runner to use for queuing client_ callbacks.
   TaskRunner* const task_runner_;
 
- private:
-  // This callback allows other objects to observe the socket's destructor and
-  // act when it is called.
-  std::function<void(UdpSocket*)> deletion_callback_;
-
   OSP_DISALLOW_COPY_AND_ASSIGN(UdpSocket);
 };