#define MS_CLASS "RTC::UdpSocket"
#include "RTC/UdpSocket.hpp"
#include "Logger.hpp"
#include "RTC/PortManager.hpp"
#include <string>
namespace RTC
{
UdpSocket::UdpSocket(Listener* listener, std::string& ip)
: ::UdpSocketHandler::UdpSocketHandler(PortManager::BindUdp(ip)), listener(listener)
{
MS_TRACE();
}
UdpSocket::UdpSocket(Listener* listener, std::string& ip, uint16_t port)
: ::UdpSocketHandler::UdpSocketHandler(PortManager::BindUdp(ip, port)), listener(listener),
fixedPort(true)
{
MS_TRACE();
}
UdpSocket::~UdpSocket()
{
MS_TRACE();
if (!fixedPort)
{
PortManager::UnbindUdp(this->localIp, this->localPort);
}
}
void UdpSocket::UserOnUdpDatagramReceived(const uint8_t* data, size_t len, const struct sockaddr* addr)
{
MS_TRACE();
if (!this->listener)
{
MS_ERROR("no listener set");
return;
}
this->listener->OnUdpSocketPacketReceived(this, data, len, addr);
}
}