I’d like to know if both of the io_read handler work identically:
io_read(){
buffer = malloc();
…
if (nbytes) {
…
IO_SET_READ_NBYTES(ctp, nbytes);
resmgr_msgwrite(ctp, buffer, nbytes, 0);
free(buffer);
}else{
IO_SET_READ_NBYTES(ctp, 0);
}
return(EOK);
}
or:
io_read(){
buffer = malloc();
…
if (nbytes) {
…
_IO_SET_READ_NBYTES(ctp, nbytes);
SETIOV (ctp->iov, buffer + ocb->offset, nbytes);
nparts = 1;
}else{
free(buffer);
_IO_SET_READ_NBYTES(ctp, 0);
nparts = 0;
}
return(_RESMGR_NPARTS(nparts));
}
Other questions:
Can we respond indifferently:
return(status);
and
return(_RESMGR_ERRNO(status));
What about when status = EOK ?
Thanks,
Alain.
Alain Bonnefoy (alain.bonnefoy@icbt.com) wrote:
: I’d like to know if both of the io_read handler work identically:
Obviously not
: io_read(){
: buffer = malloc();
: …
: if (nbytes) {
: …
: IO_SET_READ_NBYTES(ctp, nbytes);
: resmgr_msgwrite(ctp, buffer, nbytes, 0);
: free(buffer);
: }else{
: IO_SET_READ_NBYTES(ctp, 0);
: }
: return(EOK);
: }
: or:
: io_read(){
: buffer = malloc();
: …
: if (nbytes) {
: …
: _IO_SET_READ_NBYTES(ctp, nbytes);
: SETIOV (ctp->iov, buffer + ocb->offset, nbytes);
: nparts = 1;
: }else{
: free(buffer);
: _IO_SET_READ_NBYTES(ctp, 0);
: nparts = 0;
: }
: return(_RESMGR_NPARTS(nparts));
: }
The first one frees the data buffer if nbytes is set, the second one
frees the data buffer it nbytes is zero.
The first one returns data starting at buffer, the second one returns
data starting at buffer + ocb → offset.
: Other questions:
: Can we respond indifferently:
: return(status);
: and
: return(_RESMGR_ERRNO(status));
Yes.
: What about when status = EOK ?
return (0) is the same as return (_RESMGR_ERRNO (0))
Cheers,
-RK
–
Robert Krten, PARSE Software Devices; email my initials at parse dot com
Consulting, Systems Architecture / Design, Drivers, Training, QNX 4 & Neutrino
Check out our new QNX 4 and Neutrino (QRTP) books at http://www.parse.com/
Wanted PDP-8/9/10/11/12 Systems/documentation/spare parts! Will trade books!
Robert Krten a écrit :
Alain Bonnefoy (> alain.bonnefoy@icbt.com> ) wrote:
: I’d like to know if both of the io_read handler work identically:
Obviously not >
: io_read(){
: buffer = malloc();
: …
: if (nbytes) {
: …
: IO_SET_READ_NBYTES(ctp, nbytes);
: resmgr_msgwrite(ctp, buffer, nbytes, 0);
: free(buffer);
: }else{
: IO_SET_READ_NBYTES(ctp, 0);
: }
: return(EOK);
: }
: or:
: io_read(){
: buffer = malloc();
: …
: if (nbytes) {
: …
: _IO_SET_READ_NBYTES(ctp, nbytes);
: SETIOV (ctp->iov, buffer + ocb->offset, nbytes);
: nparts = 1;
: }else{
: free(buffer);
: _IO_SET_READ_NBYTES(ctp, 0);
: nparts = 0;
: }
: return(_RESMGR_NPARTS(nparts));
: }
The first one frees the data buffer if nbytes is set, the second one
frees the data buffer it nbytes is zero.
The first one returns data starting at buffer, the second one returns
data starting at buffer + ocb → offset.
Oups! Sorry Robert, I didn’t take care of these mistakes!
Forget the offset, that’s not the problem here and I assumed that i was able to
reply the datas in one shot so, my question was more about the way to free my
buffer.
Thanks,
Alain.
Alain Bonnefoy (alain.bonnefoy@icbt.com) wrote:
: Robert Krten a écrit :
: > Alain Bonnefoy (alain.bonnefoy@icbt.com) wrote:
: > : I’d like to know if both of the io_read handler work identically:
: >
: > Obviously not
: >
: > : io_read(){
: > : buffer = malloc();
: > : …
: > : if (nbytes) {
: > : …
: > : IO_SET_READ_NBYTES(ctp, nbytes);
: > : resmgr_msgwrite(ctp, buffer, nbytes, 0);
: > : free(buffer);
: > : }else{
: > : IO_SET_READ_NBYTES(ctp, 0);
: > : }
: > : return(EOK);
: > : }
: >
: > : or:
: >
: > : io_read(){
: > : buffer = malloc();
: > : …
: > : if (nbytes) {
: > : …
: > : _IO_SET_READ_NBYTES(ctp, nbytes);
: > : SETIOV (ctp->iov, buffer + ocb->offset, nbytes);
: > : nparts = 1;
: > : }else{
: > : free(buffer);
: > : _IO_SET_READ_NBYTES(ctp, 0);
: > : nparts = 0;
: > : }
: > : return(_RESMGR_NPARTS(nparts));
: > : }
: >
: > The first one frees the data buffer if nbytes is set, the second one
: > frees the data buffer it nbytes is zero.
: > The first one returns data starting at buffer, the second one returns
: > data starting at buffer + ocb → offset.
: Oups! Sorry Robert, I didn’t take care of these mistakes!
: Forget the offset, that’s not the problem here and I assumed that i was able to
: reply the datas in one shot so, my question was more about the way to free my
: buffer.
You can’t free() the buffer and then transfer it. While this “might” appear to
work, it’s just luck – some other thread may re-use the free’d buffer.
Cheers,
-RK
–
Robert Krten, PARSE Software Devices; email my initials at parse dot com
Consulting, Systems Architecture / Design, Drivers, Training, QNX 4 & Neutrino
Check out our new QNX 4 and Neutrino (QRTP) books at http://www.parse.com/
Wanted PDP-8/9/10/11/12 Systems/documentation/spare parts! Will trade books!