NL::内网:: UDP端点

#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 消息。

公共职能

绑定

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 堆栈锁的情况下调用此方法。

绑定接口

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 堆栈锁的情况下调用此方法。

获取绑定接口

InterfaceId GetBoundInterface(
  void
)

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

细节
退货
InterfaceId 绑定的接口 ID。

获取绑定端口

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 堆栈锁的情况下调用此方法

发送消息

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
另一个系统或平台错误

发给

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

一种用于同义词SendTo(addr, port, INET_NULL_INTERFACEID, msg, sendFlags)

发给

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
另一个系统或平台错误