nl::Inet::UDPEndPoint

#include <src/inet/UDPEndPoint.h>

此类的对象表示 UDP 传输端点。

摘要

在系统进行相应配置时,Nest Inet 层封装了与 UDP 传输端点(Linux 和 BSD 派生系统上的 SOCK_DGRAM 套接字)或 LwIP UDP 协议控制块交互的方法。

继承

继承自: nl::Inet::IPEndPointBasis

公共函数

Bind(IPAddressType addrType, IPAddress addr, uint16_t port, InterfaceId intfId)
将端点绑定到接口 IP 地址。
BindInterface(IPAddressType addrType, InterfaceId intf)
将端点绑定到网络接口。
Close(void)
void
关闭端点。
Free(void)
void
关闭端点并回收其内存。
GetBoundInterface(void)
InterfaceId
获取此端点上的绑定接口。
GetBoundPort(void)
uint16_t
Listen(void)
准备端点以接收 UDP 消息。
SendMsg(const IPPacketInfo *pktInfo, Weave::System::PacketBuffer *msg, uint16_t sendFlags)
将 UDP 消息发送到指定目的地。
SendTo(IPAddress addr, uint16_t port, Weave::System::PacketBuffer *msg, uint16_t sendFlags)
SendTo(addr, port, INET_NULL_INTERFACEID, msg, sendFlags) 的同义词。
SendTo(IPAddress addr, uint16_t port, InterfaceId intfId, Weave::System::PacketBuffer *msg, uint16_t sendFlags)
向指定的目标地址发送 UDP 消息。

公共函数

Bind

INET_ERROR Bind(
  IPAddressType addrType,
  IPAddress addr,
  uint16_t port,
  InterfaceId intfId
)

将端点绑定到接口 IP 地址。

将端点绑定到指定的网络接口 IP 地址。

具体说明
参数
[in] addrType
IP 地址的协议版本
[in] addr
IP 地址(必须是接口地址)
[in] port
UDP 端口
[in] intfId
可选的网络接口指示符
返回值
INET_NO_ERROR
成功:端点绑定到地址
INET_ERROR_INCORRECT_STATE
端点之前已经绑定过
INET_NO_MEMORY
端点内存不足
INET_ERROR_UNKNOWN_INTERFACE
在某些平台上,没有选择性指定的接口。
INET_ERROR_WRONG_PROTOCOL_TYPE
addrType”与“IPVer”不匹配。
INET_ERROR_WRONG_ADDRESS_TYPE
addrTypekIPAddressType_Any,或者 addr 的类型不等于 addrType
other
其他系统或平台错误

在 LwIP 上,不得在已获取 LwIP 堆栈锁的情况下调用此方法。

BindInterface

INET_ERROR BindInterface(
  IPAddressType addrType,
  InterfaceId intf
)

将端点绑定到网络接口。

将端点绑定到指定的网络接口 IP 地址。

具体说明
参数
[in] addrType
IP 地址的协议版本。
[in] intf
网络接口指示符。
返回值
INET_NO_ERROR
成功:端点绑定到地址
INET_NO_MEMORY
端点内存不足
INET_ERROR_NOT_IMPLEMENTED
系统实施尚未完成。
INET_ERROR_UNKNOWN_INTERFACE
在某些平台上,该接口不存在。
other
其他系统或平台错误

在 LwIP 上,不得在已获取 LwIP 堆栈锁的情况下调用此方法。

关闭

void Close(
  void
)

关闭端点。

如果为 mState != kState_Closed,则关闭该端点,并将其从可接收通信事件的一组端点中移除。

在 LwIP 系统上,不得在已获取 LwIP 堆栈锁的情况下调用此方法。

免费

void Free(
  void
)

关闭端点并回收其内存。

调用 Close 方法,然后调用 InetLayerBasis::Release 方法以将对象返回到其内存池。

在 LwIP 系统上,不得在已获取 LwIP 堆栈锁的情况下调用此方法。

GetBoundInterface

InterfaceId GetBoundInterface(
  void
)

获取此端点上的绑定接口。

具体说明
返回值
InterfaceId 绑定的接口 ID。

GetBoundPort

uint16_t GetBoundPort(
  void
)

聆听

INET_ERROR Listen(
  void
)

准备端点以接收 UDP 消息。

如果 State 已设置为 kState_Listening,则不执行任何操作;否则,mState 会设置为 kState_Listening,并且端点可以根据平台的语义准备好接收 UDP 消息。

具体说明
返回值
INET_NO_ERROR
成功:端点可以接收消息了。
INET_ERROR_INCORRECT_STATE
端点已经在监听。

在 LwIP 上,不得在已获取 LwIP 堆栈锁的情况下调用此方法

SendMsg

INET_ERROR SendMsg(
  const IPPacketInfo *pktInfo,
  Weave::System::PacketBuffer *msg,
  uint16_t sendFlags
)

将 UDP 消息发送到指定目的地。

 Send the UDP message in \c msg to the destination address and port given in
 \c pktInfo.  If \c pktInfo contains an interface id, the message will be sent
 over the specified interface.  If \c pktInfo contains a source address, the
 given address will be used as the source of the UDP message.

 Where (sendFlags & kSendFlag_RetainBuffer) != 0, calls
 Weave::System::PacketBuffer::Free on behalf of the caller, otherwise this
 method deep-copies \c msg into a fresh object, and queues that for
 transmission, leaving the original \c msg available after return.

具体说明
参数
[in] pktInfo
UDP 消息的来源和目的地信息
[in] msg
包含 UDP 消息的数据包缓冲区
[in] sendFlags
可选的传输选项标志
返回值
INET_NO_ERROR
如果成功:msg 已加入传输队列。
INET_ERROR_NOT_SUPPORTED
系统不支持请求的操作。
INET_ERROR_WRONG_ADDRESS_TYPE
目标地址和绑定的接口地址的协议版本或地址类型不匹配。
INET_ERROR_MESSAGE_TOO_LONG
msg 不包含完整的 UDP 消息。
INET_ERROR_OUTBOUND_MESSAGE_TRUNCATED
在某些平台上,只有 msg 中被截断的部分已加入传输队列。
other
其他系统或平台错误

SendTo

INET_ERROR SendTo(
  IPAddress addr,
  uint16_t port,
  Weave::System::PacketBuffer *msg,
  uint16_t sendFlags
)

SendTo(addr, port, INET_NULL_INTERFACEID, msg, sendFlags) 的同义词。

SendTo

INET_ERROR SendTo(
  IPAddress addr,
  uint16_t port,
  InterfaceId intfId,
  Weave::System::PacketBuffer *msg,
  uint16_t sendFlags
)

向指定的目标地址发送 UDP 消息。

 If possible, then this method sends the UDP message \c msg to the
 destination \c addr (with \c intfId used as the scope
 identifier for IPv6 link-local destinations) and \c port with the
 transmit option flags encoded in \c sendFlags.

 Where (sendFlags & kSendFlag_RetainBuffer) != 0, calls
 Weave::System::PacketBuffer::Free on behalf of the caller, otherwise this
 method deep-copies \c msg into a fresh object, and queues that for
 transmission, leaving the original \c msg available after return.

具体说明
参数
[in] addr
目标 IP 地址
[in] port
目标 UDP 端口
[in] intfId
可选的网络接口指示符
[in] msg
包含 UDP 消息的数据包缓冲区
[in] sendFlags
可选的传输选项标志
返回值
INET_NO_ERROR
如果成功:msg 已加入传输队列。
INET_ERROR_NOT_SUPPORTED
系统不支持请求的操作。
INET_ERROR_WRONG_ADDRESS_TYPE
目标地址和绑定的接口地址的协议版本或地址类型不匹配。
INET_ERROR_MESSAGE_TOO_LONG
msg 不包含完整的 UDP 消息。
INET_ERROR_OUTBOUND_MESSAGE_TRUNCATED
在某些平台上,只有 msg 中被截断的部分已加入传输队列。
other
其他系统或平台错误