Network/UdpSocket: Add broadcasting option
Former-commit-id: bde428efc5e9c77cf3e64ec04d58d72613f1d8de
This commit is contained in:
parent
81221fbf0b
commit
f28e1a7d9b
|
|
@ -26,10 +26,14 @@ namespace Nz
|
||||||
|
|
||||||
inline bool Create(NetProtocol protocol);
|
inline bool Create(NetProtocol protocol);
|
||||||
|
|
||||||
|
void EnableBroadcasting(bool broadcasting);
|
||||||
|
|
||||||
inline IpAddress GetBoundAddress() const;
|
inline IpAddress GetBoundAddress() const;
|
||||||
inline UInt16 GetBoundPort() const;
|
inline UInt16 GetBoundPort() const;
|
||||||
inline SocketState GetState() const;
|
inline SocketState GetState() const;
|
||||||
|
|
||||||
|
inline bool IsBroadcastingEnabled() const;
|
||||||
|
|
||||||
unsigned int QueryMaxDatagramSize();
|
unsigned int QueryMaxDatagramSize();
|
||||||
|
|
||||||
bool Receive(void* buffer, std::size_t size, IpAddress* from, std::size_t* received);
|
bool Receive(void* buffer, std::size_t size, IpAddress* from, std::size_t* received);
|
||||||
|
|
@ -42,6 +46,7 @@ namespace Nz
|
||||||
|
|
||||||
IpAddress m_boundAddress;
|
IpAddress m_boundAddress;
|
||||||
SocketState m_state;
|
SocketState m_state;
|
||||||
|
bool m_isBroadCastingEnabled;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,11 @@ namespace Nz
|
||||||
{
|
{
|
||||||
return m_state;
|
return m_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool UdpSocket::IsBroadcastingEnabled() const
|
||||||
|
{
|
||||||
|
return m_isBroadCastingEnabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Network/DebugOff.hpp>
|
#include <Nazara/Network/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,17 @@ namespace Nz
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UdpSocket::EnableBroadcasting(bool broadcasting)
|
||||||
|
{
|
||||||
|
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle");
|
||||||
|
|
||||||
|
if (m_isBroadCastingEnabled != broadcasting)
|
||||||
|
{
|
||||||
|
SocketImpl::SetBroadcasting(m_handle, broadcasting, &m_lastError);
|
||||||
|
m_isBroadCastingEnabled = broadcasting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int UdpSocket::QueryMaxDatagramSize()
|
unsigned int UdpSocket::QueryMaxDatagramSize()
|
||||||
{
|
{
|
||||||
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket hasn't been created");
|
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket hasn't been created");
|
||||||
|
|
@ -73,6 +84,7 @@ namespace Nz
|
||||||
void UdpSocket::OnOpened()
|
void UdpSocket::OnOpened()
|
||||||
{
|
{
|
||||||
m_boundAddress = IpAddress::Invalid;
|
m_boundAddress = IpAddress::Invalid;
|
||||||
|
m_isBroadCastingEnabled = false;
|
||||||
|
|
||||||
UpdateState(SocketState_NotConnected);
|
UpdateState(SocketState_NotConnected);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -509,6 +509,25 @@ namespace Nz
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SocketImpl::SetBroadcasting(SocketHandle handle, bool broadcasting, SocketError* error)
|
||||||
|
{
|
||||||
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
|
||||||
|
BOOL option = broadcasting;
|
||||||
|
if (setsockopt(handle, SOL_SOCKET, SO_BROADCAST, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
|
||||||
|
|
||||||
|
return false; //< Error
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
*error = SocketError_NoError;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool SocketImpl::SetKeepAlive(SocketHandle handle, bool enabled, UInt64 msTime, UInt64 msInterval, SocketError* error)
|
bool SocketImpl::SetKeepAlive(SocketHandle handle, bool enabled, UInt64 msTime, UInt64 msInterval, SocketError* error)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ namespace Nz
|
||||||
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
||||||
|
|
||||||
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
||||||
|
static bool SetBroadcasting(SocketHandle handle, bool broadcasting, SocketError* error = nullptr);
|
||||||
static bool SetKeepAlive(SocketHandle handle, bool enabled, UInt64 msTime, UInt64 msInterval, SocketError* error = nullptr);
|
static bool SetKeepAlive(SocketHandle handle, bool enabled, UInt64 msTime, UInt64 msInterval, SocketError* error = nullptr);
|
||||||
static bool SetNoDelay(SocketHandle handle, bool nodelay, SocketError* error = nullptr);
|
static bool SetNoDelay(SocketHandle handle, bool nodelay, SocketError* error = nullptr);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue