mirror of
https://github.com/espressif/openthread.git
synced 2026-09-06 09:10:04 +00:00
[udp] add Udp::IsBound() method (#3708)
This commit is contained in:
@@ -274,7 +274,7 @@ otError Dtls::Bind(TransportCallback aCallback, void *aContext)
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(mState == kStateOpen, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(mSocket.GetSockName().mPort == 0, error = OT_ERROR_ALREADY);
|
||||
VerifyOrExit(!mSocket.IsBound(), error = OT_ERROR_ALREADY);
|
||||
VerifyOrExit(mTransportCallback == NULL, error = OT_ERROR_ALREADY);
|
||||
|
||||
mTransportCallback = aCallback;
|
||||
|
||||
@@ -101,7 +101,7 @@ otError UdpSocket::Bind(const SockAddr &aSockAddr)
|
||||
|
||||
mSockName = aSockAddr;
|
||||
|
||||
if (mSockName.mPort == 0)
|
||||
if (!IsBound())
|
||||
{
|
||||
do
|
||||
{
|
||||
@@ -182,7 +182,7 @@ otError UdpSocket::SendTo(Message &aMessage, const MessageInfo &aMessageInfo)
|
||||
messageInfoLocal.SetSockAddr(GetSockName().GetAddress());
|
||||
}
|
||||
|
||||
if (GetSockName().mPort == 0)
|
||||
if (!IsBound())
|
||||
{
|
||||
SuccessOrExit(error = Bind(GetSockName()));
|
||||
}
|
||||
|
||||
@@ -143,6 +143,15 @@ public:
|
||||
*/
|
||||
otError Bind(const SockAddr &aSockAddr);
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the socket is bound.
|
||||
*
|
||||
* @retval TRUE if the socket is bound (i.e. source port is non-zero).
|
||||
* @retval FALSE if the socket is not bound (source port is zero).
|
||||
*
|
||||
*/
|
||||
bool IsBound(void) const { return mSockName.mPort != 0; }
|
||||
|
||||
/**
|
||||
* This method connects the UDP socket.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user