This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: tty_write yields written bytes count
- From: Robin Farine <robin dot farine at acn-group dot ch>
- To: Jonathan Larmour <jlarmour at redhat dot com>
- Cc: eCos users <ecos-discuss at sources dot redhat dot com>
- Date: 28 Feb 2002 09:03:01 +0100
- Subject: Re: [ECOS] tty_write yields written bytes count
- References: <1014650109.8931.114.camel@halftrack> <3C7D60C0.CAB937E5@redhat.com>
On Wed, 2002-02-27 at 23:42, Jonathan Larmour wrote:
[snip]
>
> I certainly agree with your analysis, but I think there is a simpler
> solution. Haven't tried it admittedly, but tell me what you think!
>
[snip]
Yes, your solution is a lot more elegant but I don't think it works
correctly (I haven't tried it either :). The problem comes with the
error case. The underlying device will set 'size' to the number of bytes
it could send before the error. Fine. But tty_write() doesn't know at
that time how many lf -> crlf or other translations it did before and
thus it cannot adjust 'bytes_successfull' correctly. That's why I
thought the easier way was to flush the buffer each time a translation
occurs.
Robin
> Jifl
>
> Index: tty.c
> ===================================================================
> RCS file: /home/cvs/ecc/ecc/io/serial/current/src/common/tty.c,v
> retrieving revision 1.14
> diff -u -5 -p -r1.14 tty.c
> --- tty.c 2000/11/06 19:40:01 1.14
> +++ tty.c 2002/02/27 22:41:21
> @@ -156,19 +156,18 @@ static Cyg_ErrNo
> tty_write(cyg_io_handle_t handle, const void *_buf, cyg_uint32 *len)
> {
> cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)handle;
> struct tty_private_info *priv = (struct tty_private_info *)t->priv;
> cyg_io_handle_t chan = (cyg_io_handle_t)priv->dev_handle;
> - cyg_int32 size, bytes_successful, actually_written;
> + cyg_int32 size, bytes_successful;
> cyg_uint8 xbuf[BUFSIZE];
> cyg_uint8 c;
> cyg_uint8 *buf = (cyg_uint8 *)_buf;
> Cyg_ErrNo res = -EBADF;
> // assert(chan)
> size = 0;
> bytes_successful = 0;
> - actually_written = 0;
> while (bytes_successful++ < *len) {
> c = *buf++;
> if ((c == '\n') &&
> (priv->dev_info.tty_out_flags & CYG_TTY_OUT_FLAGS_CRLF)) {
> xbuf[size++] = '\r';
> @@ -177,18 +176,17 @@ tty_write(cyg_io_handle_t handle, const
> // Always leave room for possible CR/LF expansion
> if ((size >= (BUFSIZE-1)) ||
> (bytes_successful == *len)) {
> res = cyg_io_write(chan, xbuf, &size);
> if (res != ENOERR) {
> - *len = actually_written;
> + *len = bytes_successful-size;
> return res;
> }
> - actually_written += size;
> size = 0;
> }
> }
> - *len = actually_written;
> + *len = bytes_successful;
> return res;
> }
>
> static Cyg_ErrNo
> tty_read(cyg_io_handle_t handle, void *_buf, cyg_uint32 *len)
>
>
> Jifl
> --
> Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
> Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
>
> --
> Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
> and search the list archive: http://sources.redhat.com/ml/ecos-discuss
>
>
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss