[udp] add Udp::IsBound() method (#3708)

This commit is contained in:
Jonathan Hui
2019-03-25 08:35:56 -07:00
committed by GitHub
parent 23ff1015d4
commit a9e0fe9ec6
3 changed files with 12 additions and 3 deletions
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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()));
}
+9
View File
@@ -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.
*