#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/openscreen_platform/udp_socket.h"
#include <utility>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "components/openscreen_platform/network_context.h"
#include "components/openscreen_platform/network_util.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/base/address_family.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "third_party/openscreen/src/platform/base/udp_packet.h"
namespace openscreen {
ErrorOr<std::unique_ptr<UdpSocket>> UdpSocket::Create(
TaskRunner& task_runner,
Client* client,
const IPEndpoint& local_endpoint) { … }
}
namespace openscreen_platform {
namespace {
ByteView;
Error;
IPAddress;
IPEndpoint;
UdpPacket;
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = …;
}
UdpSocket::UdpSocket(
Client* client,
const IPEndpoint& local_endpoint,
mojo::Remote<network::mojom::UDPSocket> udp_socket,
mojo::PendingReceiver<network::mojom::UDPSocketListener> pending_listener)
: … { … }
UdpSocket::~UdpSocket() = default;
bool UdpSocket::IsIPv4() const { … }
bool UdpSocket::IsIPv6() const { … }
IPEndpoint UdpSocket::GetLocalEndpoint() const { … }
void UdpSocket::Bind() { … }
void UdpSocket::SetMulticastOutboundInterface(
openscreen::NetworkInterfaceIndex ifindex) { … }
void UdpSocket::JoinMulticastGroup(const IPAddress& address,
openscreen::NetworkInterfaceIndex ifindex) { … }
void UdpSocket::SendMessage(ByteView data, const IPEndpoint& dest) { … }
void UdpSocket::SetDscp(openscreen::UdpSocket::DscpMode state) { … }
void UdpSocket::OnReceived(
int32_t net_result,
const std::optional<net::IPEndPoint>& source_endpoint,
std::optional<base::span<const uint8_t>> data) { … }
void UdpSocket::BindCallback(int32_t result,
const std::optional<net::IPEndPoint>& address) { … }
void UdpSocket::JoinGroupCallback(int32_t result) { … }
void UdpSocket::SendCallback(int32_t result) { … }
}