Refactor UDP Socket to allow for Mocks
- Change platform/api/udp_socket to an abstract class
- Change platform/posix/udp_socket to an implementation of the abstract class
- Add platform/test/fake_udp_socket for testing
This fake_udp_socket class is needed for my upcoming Networking Pt 2 change
This change includes udp_socket changes from Networking Changes Pt 1 ongoing CL
to make merging the two easier, since this part of that CL seems to have
reached consensus.
Change-Id: Ia18671756d7457594b4fdceffef6c33e5fd4771a
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/1680971
Commit-Queue: Ryan Keane <rwkeane@google.com>
Reviewed-by: mark a. foltz <mfoltz@chromium.org>
Reviewed-by: Max Yakimakha <yakimakha@chromium.org>
Reviewed-by: Yuri Wiitala <miu@chromium.org>
diff --git a/platform/api/udp_socket.cc b/platform/api/udp_socket.cc
new file mode 100644
index 0000000..1bd96fd
--- /dev/null
+++ b/platform/api/udp_socket.cc
@@ -0,0 +1,23 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file
+
+#include "platform/api/udp_socket.h"
+
+namespace openscreen {
+namespace platform {
+
+UdpSocket::UdpSocket() {
+ deletion_callback_ = [](UdpSocket* socket) {};
+}
+
+UdpSocket::~UdpSocket() {
+ deletion_callback_(this);
+}
+
+void UdpSocket::SetDeletionCallback(std::function<void(UdpSocket*)> callback) {
+ deletion_callback_ = callback;
+}
+
+} // namespace platform
+} // namespace openscreen