diff --git a/examples/platforms/posix/radio.c b/examples/platforms/posix/radio.c index 31e20a3ac..b6b4d3f2d 100644 --- a/examples/platforms/posix/radio.c +++ b/examples/platforms/posix/radio.c @@ -28,6 +28,8 @@ #include "platform-posix.h" +#include + #include #include #include @@ -815,15 +817,22 @@ void platformRadioProcess(otInstance *aInstance, const fd_set *aReadFdSet, const { ssize_t rval = recvfrom(sRxFd, (char *)&sReceiveMessage, sizeof(sReceiveMessage), 0, NULL, NULL); - if (rval < 0) + if (rval > 0) + { + sReceiveFrame.mLength = (uint8_t)(rval - 1); + + radioReceive(aInstance); + } + else if (rval == 0) + { + // socket is closed, which should not happen + assert(false); + } + else if (errno != EINTR && errno != EAGAIN) { perror("recvfrom(sRxFd)"); exit(EXIT_FAILURE); } - - sReceiveFrame.mLength = (uint8_t)(rval - 1); - - radioReceive(aInstance); } #endif