This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug in read in a device file




I think I found a bug in read() when a device file is set to NON_BLOCK
When I use read() to get more than one data from device ,such as :
      read(devfd,buf,3);
it will read nothing for ever .

The reason is :
    in file io/fileio/src/devfs.cxx, linenumber 324

//-----------------------------------------------------------------------

static int dev_fo_read      (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG
*uio)
{
    Cyg_ErrNo err = 0;
    int i;

    // Now loop over the iovecs until they are all done, or
    // we get an error.
    for( i = 0; i < uio->uio_iovcnt; i++ )
    {
        cyg_iovec *iov = &uio->uio_iov[i];
        cyg_uint32 len = iov->iov_len;

        err = cyg_io_read( (cyg_io_handle_t)fp->f_data,
                           iov->iov_base,
                           &len);

        if( err < 0 ) break;

        uio->uio_resid -= len;
    }

    return -err;
}
//-------------------------------------------------------------------

now len=3, if just one byte in the read buffer of drivers . after called
cyg_io_read ,
,it will return one byte in iov->iov_base,and len =1(because set
NON_BLOCK),but
err < 0,
so the byte will lost .
I use function "select" and "read" to get device data , and the device speed
isn't quick
enough , when function select decide there are some data in device driver,
function "read"
will be call, but only one byte in the read buffer now .so the read function
will return
failure always .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]