[posix] return INVALID_STATE on EINVAL (#4959)

After adding and removing addresses, sendmsg call will return EINVAL for
a short period of time. Return INVALID_STATE to inform callers to try
again later.
This commit is contained in:
Jiacheng Guo
2020-05-14 09:01:34 -07:00
committed by GitHub
parent 092eb186e1
commit 3e1bf97188
+9 -1
View File
@@ -89,6 +89,7 @@ static otError transmitPacket(int aFd, uint8_t *aPayload, uint16_t aLength, cons
struct msghdr msg;
struct cmsghdr *cmsg;
ssize_t rval;
otError error = OT_ERROR_NONE;
memset(&peerAddr, 0, sizeof(peerAddr));
peerAddr.sin6_port = htons(aMessageInfo.mPeerPort);
@@ -157,7 +158,14 @@ static otError transmitPacket(int aFd, uint8_t *aPayload, uint16_t aLength, cons
VerifyOrExit(rval > 0, perror("sendmsg"));
exit:
return rval > 0 ? OT_ERROR_NONE : OT_ERROR_FAILED;
// EINVAL happens when we shift from child to router and the
// interface address changes. Ask callers to try again later.
if (rval == -1)
{
error = (errno == EINVAL) ? OT_ERROR_INVALID_STATE : OT_ERROR_FAILED;
}
return error;
}
static otError receivePacket(int aFd, uint8_t *aPayload, uint16_t &aLength, otMessageInfo &aMessageInfo)