From 3e1bf971884b9fc5b51f660847a040907d683b90 Mon Sep 17 00:00:00 2001 From: Jiacheng Guo Date: Fri, 15 May 2020 00:01:34 +0800 Subject: [PATCH] [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. --- src/posix/platform/udp.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/posix/platform/udp.cpp b/src/posix/platform/udp.cpp index 9e78c9c54..4c62a5de5 100644 --- a/src/posix/platform/udp.cpp +++ b/src/posix/platform/udp.cpp @@ -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)