better error handling for mq_receive()

This commit is contained in:
Robin Müller 2021-05-31 12:22:33 +02:00
parent 567699954c
commit e961f3f038
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
1 changed files with 300 additions and 283 deletions

View File

@ -12,8 +12,7 @@
MessageQueue::MessageQueue(uint32_t messageDepth, size_t maxMessageSize):
id(MessageQueueIF::NO_QUEUE),lastPartner(MessageQueueIF::NO_QUEUE),
defaultDestination(MessageQueueIF::NO_QUEUE),
maxMessageSize(maxMessageSize) {
defaultDestination(MessageQueueIF::NO_QUEUE), maxMessageSize(maxMessageSize) {
//debug << "MessageQueue::MessageQueue: Creating a queue" << std::endl;
mq_attr attributes;
this->id = 0;
@ -91,15 +90,14 @@ ReturnValue_t MessageQueue::handleError(mq_attr* attributes,
sif::error << "This error can be fixed by setting the maximum "
"allowed message size higher!" << std::endl;
#endif
}
break;
}
case(EEXIST): {
// An error occured during open
// We need to distinguish if it is caused by an already created queue
//There's another queue with the same name
//We unlink the other queue
// There's another queue with the same name
// We unlink the other queue
int status = mq_unlink(name);
if (status != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -204,14 +202,15 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
//O_NONBLOCK or MQ_NONBLOCK was set and there are no messages
//currently on the specified queue.
return MessageQueueIF::EMPTY;
case EBADF:
case EBADF: {
//mqdes doesn't represent a valid queue open for reading.
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receive: configuration error "
<< strerror(errno) << std::endl;
#endif
/*NO BREAK*/
case EINVAL:
return HasReturnvaluesIF::RETURN_FAILED;
}
case EINVAL: {
/*
* This value indicates one of the following:
* - The pointer to the buffer for storing the received message,
@ -222,11 +221,12 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
* been set in the queue's mq_flags.
*/
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receive: configuration error "
sif::error << "MessageQueue::receive: EINVAL error "
<< strerror(errno) << std::endl;
#endif
/*NO BREAK*/
case EMSGSIZE:
return HasReturnvaluesIF::RETURN_FAILED;
}
case EMSGSIZE: {
/*
* This value indicates one of the following:
* - the QNX extended option MQ_READBUF_DYNAMIC hasn't been set,
@ -237,12 +237,29 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
* been received.
*/
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receive: configuration error "
sif::error << "MessageQueue::receive: EMSGSIZE error "
<< strerror(errno) << std::endl;
#endif
/*NO BREAK*/
case EINTR:
return HasReturnvaluesIF::RETURN_FAILED;
}
case EINTR: {
//The operation was interrupted by a signal.
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receiveMessage: EINTR error " << strerror(errno) <<
std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
case ETIMEDOUT: {
//The operation was interrupted by a signal.
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::receiveMessage: ETIMEDOUT error " << strerror(errno) <<
std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
default:
return HasReturnvaluesIF::RETURN_FAILED;