-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
UdpSocket.inl
78 lines (63 loc) · 1.51 KB
/
UdpSocket.inl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Network module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/Debug.hpp>
namespace Nz
{
inline UdpSocket::UdpSocket() :
AbstractSocket(SocketType_UDP)
{
}
inline UdpSocket::UdpSocket(NetProtocol protocol) :
UdpSocket()
{
Create(protocol);
}
inline UdpSocket::UdpSocket(UdpSocket&& udpSocket) :
AbstractSocket(std::move(udpSocket)),
m_boundAddress(std::move(udpSocket.m_boundAddress)),
m_state(udpSocket.m_state)
{
}
inline SocketState UdpSocket::Bind(UInt16 port)
{
IpAddress any;
switch (m_protocol)
{
case NetProtocol_Any:
case NetProtocol_Unknown:
NazaraInternalError("Invalid protocol Any at this point");
return SocketState_NotConnected;
case NetProtocol_IPv4:
any = IpAddress::AnyIpV4;
break;
case NetProtocol_IPv6:
any = IpAddress::AnyIpV6;
break;
}
any.SetPort(port);
return Bind(any);
}
bool UdpSocket::Create(NetProtocol protocol)
{
NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol");
return Open(protocol);
}
inline IpAddress UdpSocket::GetBoundAddress() const
{
return m_boundAddress;
}
inline UInt16 UdpSocket::GetBoundPort() const
{
return m_boundAddress.GetPort();
}
inline SocketState UdpSocket::GetState() const
{
return m_state;
}
inline bool UdpSocket::IsBroadcastingEnabled() const
{
return m_isBroadCastingEnabled;
}
}
#include <Nazara/Network/DebugOff.hpp>