Clean-up/Bug-fix: Move all UdpSocketPosix impl out of public API.

1. Remove implementation code from the UdpSocket interface class.

2. Move any constructs related only to the standalone UdpSocketPosix
impl out of the UdpSocket class.

3. Bug fix a use-before-init bug when trying to read packets with
UdpSocketPosix. #1 implicitly fixed this bug, which was being caused by
LifetimeObserver::OnCreate() being called from the "interface" class
before the UdpSocketPosix::handle_ data member was initialized in the
UdpSocketPosix subclass.

4. Clean-up object graph permission details: Now, only
UdpSocketReaderPosix can set the global "lifetime observer" pointer; and
client code no longer needs to worry about this internal detail.

5. Isolated thread-aware code to just UdpSocketPosix::ReadMessage() and

UdpSocketPosix::Close(), with the rest of the implementation being
non-thread-safe, per OpenScreen's threading decisions. To be clear, the
entire UdpSocket API is not meant to be used by anything other than the
TaskRunner thread. Updated class-level comments to reflect this.
Change-Id: I1c7a27a8271ea856c4f247927333b1ba4f9fcabe
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/1869803
Reviewed-by: Yuri Wiitala <miu@chromium.org>
Reviewed-by: Max Yakimakha <yakimakha@chromium.org>
Commit-Queue: Yuri Wiitala <miu@chromium.org>
diff --git a/platform/api/udp_socket.cc b/platform/api/udp_socket.cc
index 3c75b18..60262ca 100644
--- a/platform/api/udp_socket.cc
+++ b/platform/api/udp_socket.cc
@@ -4,82 +4,11 @@
 
 #include "platform/api/udp_socket.h"
 
-#include "platform/api/task_runner.h"
-
 namespace openscreen {
 namespace platform {
 
-UdpSocket::UdpSocket(TaskRunner* task_runner, Client* client)
-    : client_(client), task_runner_(task_runner) {
-  OSP_CHECK(task_runner_);
-  if (lifetime_observer_.load()) {
-    lifetime_observer_.load()->OnCreate(this);
-  }
-}
-
-UdpSocket::~UdpSocket() {
-  OSP_DCHECK(is_closed_);
-}
-
-// static
-void UdpSocket::SetLifetimeObserver(LifetimeObserver* observer) {
-  lifetime_observer_.store(observer);
-}
-
-// static
-std::atomic<UdpSocket::LifetimeObserver*> UdpSocket::lifetime_observer_{
-    nullptr};
-
-void UdpSocket::OnError(Error error) {
-  CloseIfError(error);
-
-  if (!client_) {
-    return;
-  }
-
-  task_runner_->PostTask([e = std::move(error), this]() mutable {
-    // TODO(crbug.com/openscreen/71): |this| may be invalid at this point.
-    this->client_->OnError(this, std::move(e));
-  });
-}
-
-void UdpSocket::OnSendError(Error error) {
-  if (!client_) {
-    return;
-  }
-
-  task_runner_->PostTask([e = std::move(error), this]() mutable {
-    // TODO(crbug.com/openscreen/71): |this| may be invalid at this point.
-    this->client_->OnSendError(this, std::move(e));
-  });
-}
-
-void UdpSocket::OnRead(ErrorOr<UdpPacket> read_data) {
-  if (!client_) {
-    return;
-  }
-
-  task_runner_->PostTask([data = std::move(read_data), this]() mutable {
-    // TODO(crbug.com/openscreen/71): |this| may be invalid at this point.
-    this->client_->OnRead(this, std::move(data));
-  });
-}
-
-void UdpSocket::CloseIfError(const Error& error) {
-  if (error.code() != Error::Code::kNone &&
-      error.code() != Error::Code::kAgain) {
-    CloseIfOpen();
-  }
-}
-
-void UdpSocket::CloseIfOpen() {
-  if (!is_closed_.exchange(true)) {
-    if (lifetime_observer_.load()) {
-      lifetime_observer_.load()->OnDestroy(this);
-    }
-    Close();
-  }
-}
+UdpSocket::UdpSocket() = default;
+UdpSocket::~UdpSocket() = default;
 
 }  // namespace platform
 }  // namespace openscreen