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]
Other format: [Raw text]

Re: tty_write yields written bytes count


Robin Farine wrote:
> 
> Hi,
> 
> I'm using the TTY driver with CR/LF translations for console IO. When I
> write a single '\n', I get the assertion failure below:
> 
> ASSERT FAIL: <4>stream.inl [ 179]
> Cyg_ErrNo Cyg_StdioStream::write_byte()
> Single byte not written, but no error returned!
> 
> The tty_write() routine translates the '\n' into '\r\n' and thus returns
> 2 which confuses the Cyg_StdioStream::write_byte() routine.
> 
> I believe that tty_write() should return the number of bytes consumed
> and successfully passed to the underlying device. The attached patch
> proposes a possible modification to tty_write() and a ChangeLog entry
> follows just in case ...

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!

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


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