Randall Hyde <email@example.com> wrote:
I’m writing a short io_read function for a resource manager.
It’s easy enough to copy the examples off the web page, but of
course once you stray from the script a bit, lots of questions form…
The on-line documentation recommends copying data to the client’s
buffer rather than simply returning a pointer. This is paramount for
my application since I’m using a circular queue as my internal data
structure and I need to release the buffer storage when I return.
Couple of questions:
- does SETIOV or _IO_SET_READ_NBYTES do the actual data copying?
After the return( _RESMGR_NPARTS(x)), there is an implied
MsgReplyv() done that does the actual copying.
- For the io_read_t data structure there is a commented out field,
Be careful – the io_read_t data type is a union, not a structure.
The documentation seems to imply that this is the “output” data
the “i” field is the input data structure. Is this correct?
Essentially yes. But, it is mostly describing the TYPE of the
return, rather than the need to use that location (especially as
it is commented out.)
If so, do
I just copy the
data to where this guy points?
Not usually. If you wanted to re-use your receive buffer for building
the reply data, then pointing to it, you could do so. (Though, this will
only usually be reasonable for small replies.)
Else, how do I do a “return by value” on this data?
You can & you can’t.
– you will have to have one copy – the data MUST be copied from the
resource manager back to the client.
Within the resource manager, you don’t need to copy:
– SETIOV takes a reference to the data wherever you have it
– return _RESMGR_NPARTS and the data will be copied to the client
– you can MsgReply() or MsgReplyv() directly yourself and return
QNX Training Services
Please followup in this newsgroup if you have further questions.