nl::Inet::UDPEndPoint

#include <src/inet/UDPEndPoint.h>

這個類別的物件代表 UDP 傳輸端點。

摘要

Nest Inet Layer 會封裝與 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 堆疊鎖定,就不得呼叫此方法。

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
其他系統或平台錯誤