Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - MsgSendx(), MsgReply(), MsgError() and error reporting: (4 Items)
   
MsgSendx(), MsgReply(), MsgError() and error reporting  
The documentation on using MsgSendx(), MsgReceive(), MsgReply() is straight forward and understandable, when there are 
no errors.

I would like to state my understanding of the nature of the 'status' argument in MsgReply() and the reporting of errors 
and ask if my understanding is correct.

MsgSendx() defines its return argument as being -1 when there is an error and the error is in 'errno'.

MsgReply() states that 'status' arg becomes the return value of MsgSendx().
MsgError() does the same thing.

I've seen examples of the following:

if(MsgRead(...))
{
   status = errno;
   MsgReply(coid, status, ....)
}
else {...


This implies to me that the 'status' argument is ONLY to be used to send back errors when something happens between 
MsgReceive() and MsgReply() with respect to MsgRead() and other such system calls.

It is NOT to be used to reply to the client about an error at a 'higher' level of abstraction, such as command 'turn the
 motor on'. The error is the  motor stalled.

The error that the motor stalled should be in the reply message of MsgReply via string or IOV, not the 'status' argument
.

The user is not allowed to define 'errno' values (at least I have not found the _ERRNO_MAX or something similar to that 
of _IO_MAX)

Thus the user is not allowed to use 'status' to report custom errors as there is no way to distinguish between system 
'errno' errors and custom errors as there is no _ERRNO_MAX as well as it not being the intended use of 'status'.

Do I have the use of 'status' and error reporting correct?
Re: MsgSendx(), MsgReply(), MsgError() and error reporting  
On Tue, Jan 27, 2009 at 02:00:24PM -0500, Keith Smith wrote:
> The documentation on using MsgSendx(), MsgReceive(), MsgReply() is straight forward and understandable, when there are
 no errors.
> 
> I would like to state my understanding of the nature of the 'status' argument in MsgReply() and the reporting of 
errors and ask if my understanding is correct.
> 
> MsgSendx() defines its return argument as being -1 when there is an error and the error is in 'errno'.
> 
> MsgReply() states that 'status' arg becomes the return value of MsgSendx().
> MsgError() does the same thing.
> 
> I've seen examples of the following:
> 
> if(MsgRead(...))
> {
>    status = errno;
>    MsgReply(coid, status, ....)
> }
> else {...

The above is probably wrong.  MsgError() should be used to
indicate errors.  If you did something like the above when
handling a write() (for example) the client would think it
had successfully written (status = errno) bytes.

> 
> 
> This implies to me that the 'status' argument is ONLY to be used to send back errors when something happens between 
MsgReceive() and MsgReply() with respect to MsgRead() and other such system calls.


> 
> It is NOT to be used to reply to the client about an error at a 'higher' level of abstraction, such as command 'turn 
the motor on'. The error is the  motor stalled.
> 
> The error that the motor stalled should be in the reply message of MsgReply via string or IOV, not the 'status' 
argument.
> 
> The user is not allowed to define 'errno' values (at least I have not found the _ERRNO_MAX or something similar to 
that of _IO_MAX)
> 
> Thus the user is not allowed to use 'status' to report custom errors as there is no way to distinguish between system 
'errno' errors and custom errors as there is no _ERRNO_MAX as well as it not being the intended use of 'status'.
> 
> Do I have the use of 'status' and error reporting correct?

I don't think so.  MsgError() should be used to indicate errors.

-seanb
Re: MsgSendx(), MsgReply(), MsgError() and error reporting  
I'll try to restate my confusion, because I'm still confused.

Per documentation on MsgSend()
=====
MsgSend()

    Success
        The value of status from MsgReply*(). 
    -1
        An error occurred (errno is set), or the server called MsgError*() (errno is set to the error value passed to 
MsgError()). 
====

If the return argument of MsgSend is NOT -1, then this is the value of 'status' as sent by MsgReply(). So MsgReply is 
not allowed to set 'status' to -1.

If the return argument is -1, then MsgSend() has an error or MsgError() was called instead of MsgReply().

However, MsgError() is setting 'errno'. MsgError() doesn't know what additional errors MsgSend() might report on its own
. MsgSend() reports EBADF, EFAULT, EINTR, ESRCH, ESRVRFAULT,ETIMEDOUT.

MsgRead() and MsgWrite() reports EFAULT, ESRCH, ESRVRFAULT.

If one uses MsgError() to send back the error from MsgRead() or MsgWrite(), the client can't distinguish between whether
 the error occurred because of the MsgSend call or because of problems on the server side.

Thus, it appears one has to use 'status' for all system errors that occur during the processing of a client message. 
Again the errors reported can only be limited to system errors. 'Higher level' errors need to be sent in 'msg' or IOV, 
as there is no user defined 'errno's.
 
Re: MsgSendx(), MsgReply(), MsgError() and error reporting  
On Thu, Jan 29, 2009 at 12:02:22PM -0500, Keith Smith wrote:
> I'll try to restate my confusion, because I'm still confused.
> 
> Per documentation on MsgSend()
> =====
> MsgSend()
> 
>     Success
>         The value of status from MsgReply*(). 
>     -1
>         An error occurred (errno is set), or the server called MsgError*() (errno is set to the error value passed to 
MsgError()). 
> ====
> 
> If the return argument of MsgSend is NOT -1, then this is the value of 'status' as sent by MsgReply(). So MsgReply is 
not allowed to set 'status' to -1.
> 
> If the return argument is -1, then MsgSend() has an error or MsgError() was called instead of MsgReply().
> 
> However, MsgError() is setting 'errno'. MsgError() doesn't know what additional errors MsgSend() might report on its 
own. MsgSend() reports EBADF, EFAULT, EINTR, ESRCH, ESRVRFAULT,ETIMEDOUT.
> 
> MsgRead() and MsgWrite() reports EFAULT, ESRCH, ESRVRFAULT.
> 
> If one uses MsgError() to send back the error from MsgRead() or MsgWrite(), the client can't distinguish between 
whether the error occurred because of the MsgSend call or because of problems on the server side.

If it's EFAULT the problem is with the buffer supplied
by the client.  It doesn't really matter if it's touched
by the kernel in the initial MsgSend (the buffer the server
is storing the receive into is >= the size of the client's
buffer), or from a subsequent MsgRead.

If it's ESRVRFAULT the problem is with the buffer the server
is receiving into / replying from.

It doesn't really matter exactly when the buffers are touched.

> 
> Thus, it appears one has to use 'status' for all system errors that occur during the processing of a client message. 
Again the errors reported can only be limited to system errors. 'Higher level' errors need to be sent in 'msg' or IOV, 
as there is no user defined 'errno's.

You can't use the status of a reply for errors (see previous
example).  If you don't think there's enough errnos for your
particular situation you can invent some other error reporting
mechanism but you won't be able to use any of our _IO_* messages
(sys/iomsg.h> as non of our servers will know anything about it.

-seanb
>  
> 
> 
> _______________________________________________
> QNX Momentics Community Support
> http://community.qnx.com/sf/go/post21009
>