UDP
此模块包含控制 UDP 通信的函数。
摘要
枚举 |
|
---|---|
otNetifIdentifier{
|
枚举 此枚举定义了 OpenThread 网络接口标识符。 |
类型定义符 |
|
---|---|
otNetifIdentifier
|
typedefenum otNetifIdentifier
此枚举定义了 OpenThread 网络接口标识符。 |
otUdpHandler)(void *aContext, const otMessage *aMessage, const otMessageInfo *aMessageInfo)
|
typedefbool(*
此回调允许 OpenThread 为特定 UDP 消息提供特定的处理程序。 |
otUdpReceive)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
|
typedefvoid(*
借助此回调,OpenThread 可以通知应用已收到的 UDP 消息。 |
otUdpReceiver
|
typedefstruct otUdpReceiver
此结构表示 UDP 接收器。 |
otUdpSocket
|
typedefstruct otUdpSocket
此结构表示 UDP 套接字。 |
函数 |
|
---|---|
otUdpAddReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver)
|
此函数会添加 UDP 接收器。
|
otUdpBind(otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName, otNetifIdentifier aNetif)
|
绑定 UDP/IPv6 套接字。
|
otUdpClose(otInstance *aInstance, otUdpSocket *aSocket)
|
关闭 UDP/IPv6 套接字。
|
otUdpConnect(otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName)
|
连接 UDP/IPv6 套接字。
|
otUdpGetSockets(otInstance *aInstance)
|
此函数可获取链接的 UDP 套接字列表的标头。
|
otUdpIsOpen(otInstance *aInstance, const otUdpSocket *aSocket)
|
bool
检查 UDP 套接字是否已打开。
|
otUdpNewMessage(otInstance *aInstance, const otMessageSettings *aSettings)
|
分配一个用于发送 UDP 消息的新消息缓冲区。
|
otUdpOpen(otInstance *aInstance, otUdpSocket *aSocket, otUdpReceive aCallback, void *aContext)
|
打开 UDP/IPv6 套接字。
|
otUdpRemoveReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver)
|
此函数会移除 UDP 接收器。
|
otUdpSend(otInstance *aInstance, otUdpSocket *aSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo)
|
发送 UDP/IPv6 消息。
|
otUdpSendDatagram(otInstance *aInstance, otMessage *aMessage, otMessageInfo *aMessageInfo)
|
此函数会发送不带套接字的 UDP 消息。
|
结构体 |
|
---|---|
otUdpReceiver |
此结构表示 UDP 接收器。 |
otUdpSocket |
此结构表示 UDP 套接字。 |
枚举
otNetifIdentifier
otNetifIdentifier
此枚举定义了 OpenThread 网络接口标识符。
属性 | |
---|---|
OT_NETIF_BACKBONE
|
Backbone 接口。 |
OT_NETIF_THREAD
|
线程接口。 |
OT_NETIF_UNSPECIFIED
|
未指定的网络接口。 |
类型定义符
otUdpHandler
bool(* otUdpHandler)(void *aContext, const otMessage *aMessage, const otMessageInfo *aMessageInfo)
此回调允许 OpenThread 为特定 UDP 消息提供特定的处理程序。
详情 | |||||
---|---|---|---|---|---|
返回值 |
|
otUdpReceive
void(* otUdpReceive)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
借助此回调,OpenThread 可以通知应用已收到的 UDP 消息。
函数
otUdpAddReceiver
otError otUdpAddReceiver( otInstance *aInstance, otUdpReceiver *aUdpReceiver )
此函数会添加 UDP 接收器。
详情 | |||||
---|---|---|---|---|---|
参数 |
|
||||
返回值 |
|
otUdpBind
otError otUdpBind( otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName, otNetifIdentifier aNetif )
绑定 UDP/IPv6 套接字。
详情 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otUdpClose
otError otUdpClose( otInstance *aInstance, otUdpSocket *aSocket )
关闭 UDP/IPv6 套接字。
详情 | |||||
---|---|---|---|---|---|
参数 |
|
||||
返回值 |
|
otUdpConnect
otError otUdpConnect( otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName )
连接 UDP/IPv6 套接字。
详情 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
otUdpGetSocket
otUdpSocket * otUdpGetSockets( otInstance *aInstance )
此函数可获取链接的 UDP 套接字列表的标头。
详情 | |||
---|---|---|---|
参数 |
|
||
返回值 |
指向“UDP 套接字关联列表”标头位置的指针。
|
otUdpIsOpen
bool otUdpIsOpen( otInstance *aInstance, const otUdpSocket *aSocket )
检查 UDP 套接字是否已打开。
详情 | |||||
---|---|---|---|---|---|
参数 |
|
||||
返回值 |
是否打开 UDP 套接字。
|
otUdpNewMessage
otMessage * otUdpNewMessage( otInstance *aInstance, const otMessageSettings *aSettings )
分配一个用于发送 UDP 消息的新消息缓冲区。
详情 | |||||
---|---|---|---|---|---|
参数 |
|
||||
返回值 |
指向消息缓冲区的指针,如果未提供消息缓冲区或者参数无效,则为 NULL。
|
otMessageFree
otUdpOpen
otError otUdpOpen( otInstance *aInstance, otUdpSocket *aSocket, otUdpReceive aCallback, void *aContext )
打开 UDP/IPv6 套接字。
详情 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
|
otUdpRemoveReceiver
otError otUdpRemoveReceiver( otInstance *aInstance, otUdpReceiver *aUdpReceiver )
此函数会移除 UDP 接收器。
详情 | |||||
---|---|---|---|---|---|
参数 |
|
||||
返回值 |
|
otUdpSend
otError otUdpSend( otInstance *aInstance, otUdpSocket *aSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo )
发送 UDP/IPv6 消息。
如果返回值为 OT_ERROR_NONE,则 OpenThread 将获得 aMessage
的所有权,并且调用方不应再引用 aMessage
。如果返回值不是 OT_ERROR_NONE,调用方会保留 aMessage
的所有权,包括在不再需要消息缓冲区时释放 aMessage
。
详情 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
详情 | |||||||
---|---|---|---|---|---|---|---|
返回值 |
|
otUdpSendDatagram
otError otUdpSendDatagram( otInstance *aInstance, otMessage *aMessage, otMessageInfo *aMessageInfo )
此函数会发送不带套接字的 UDP 消息。
详情 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
|
资源
OpenThread API 参考主题源自源代码,可在 GitHub 上找到。 如需了解详情或为我们的文档做贡献,请参阅资源。