--- Begin Message ---
- From: Gary Thomas <gary at mlbassoc dot com>
- To: eCos patches <ecos-patches at sources dot redhat dot com>
- Date: 09 Mar 2003 09:02:40 -0700
- Subject: I/O errors - confusion
I was looking into a problem (dealing with abnormal exits
from I/O functions) and I'm a bit confused.
In particular, in io/fileio/current/src/devfs.cxx, there
is a test
if (-EAGAIN == err)
Looking at the underlying cyg_io_XX functions, I don't think
that they will ever return a negative value.
Also, that particular piece of code seems wrong to me. My
experience is that if I have a device in a non-blocking mode
and there is no data (to be read), the value of read() is
an error = EWOULDBLOCK. The code currently returns no error,
but also no data. A generic piece of "read this" code will
thus not be able to tell the difference between actually
reaching the end of data (like on a file) vs. not having
any data at the moment (which it may be prepared to handle
in some other fashion). I think this routine should behave
like this patch:
Index: io/fileio/current/src/devfs.cxx
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/io/fileio/current/src/devfs.cxx,v
retrieving revision 1.5
diff -u -5 -p -r1.5 devfs.cxx
--- io/fileio/current/src/devfs.cxx 23 May 2002 23:06:07 -0000 1.5
+++ io/fileio/current/src/devfs.cxx 9 Mar 2003 15:52:41 -0000
@@ -352,12 +352,18 @@ static int dev_fo_read (struct CYG_
iov->iov_base,
&len);
if( -EAGAIN == err ) // must be in non-blocking mode
{
- uio->uio_resid -= len;
- return ENOERR;
+ if (len != iov->iov_len) {
+ // Something was read
+ uio->uio_resid -= len;
+ return ENOERR;
+ } else {
+ // No data, and non-blocking - tell user
+ return EWOULDBLOCK;
+ }
}
if( err < 0 ) break;
uio->uio_resid -= len;
}
although, I'm still confused about the -EAGAIN test.
Comments?
--
------------------------------------------------------------
Gary Thomas |
MLB Associates | Consulting for the
+1 (970) 229-1963 | Embedded world
http://www.mlbassoc.com/ |
email: <gary at mlbassoc dot com> |
gpg: http://www.chez-thomas.org/gary/gpg_key.asc
------------------------------------------------------------
--- End Message ---