bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch: Serial Port "overflow" Method Improved


From: Conrad T. Pino
Subject: Patch: Serial Port "overflow" Method Improved
Date: Fri, 9 Sep 2005 13:03:06 -0700

I've concluded the "overflow" method should iterate the write
buffer process until the entire buffer is written or a write
fails.  A write failure carefully preserves unwritten data so
the next call to "overflow" can resume the write operation.

This patch modifies the following files:

        src/serial.cpp

This patch is committed on "dev-bcb6-arm" branch between revision
tags "dev-bcb6-arm-0051" and "dev-bcb6-arm-0052".

Index: src/serial.cpp
===================================================================
RCS file: /cvsroot/gnutelephony/testing/commoncpp2/src/serial.cpp,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.1.1.1.2.2
diff -u -p -r1.1.1.1.2.1 -r1.1.1.1.2.2
--- src/serial.cpp      7 Sep 2005 19:01:20 -0000       1.1.1.1.2.1
+++ src/serial.cpp      9 Sep 2005 18:46:36 -0000       1.1.1.1.2.2
@@ -1180,7 +1180,6 @@ void TTYStream::flushOutput(void)
 
 void TTYStream::waitOutput(void)
 {
-//     while(overflow(EOF) == EOF);
        overflow(EOF);
 
        Serial::waitOutput();
@@ -1272,7 +1271,7 @@ int TTYStream::sync(void)
 int TTYStream::overflow(int c)
 {
        unsigned char ch;
-       ssize_t rlen, req;
+       ssize_t plen, poff, wlen;
 
        if(!pbase())
        {
@@ -1280,10 +1279,10 @@ int TTYStream::overflow(int c)
                        return 0;
 
                ch = (unsigned char)(c);
-               rlen = aWrite((char *)&ch, 1);
-               if(rlen < 1)
+               wlen = aWrite((char *)&ch, 1);
+               if(wlen < 1)
                {
-                       if(rlen < 0)
+                       if(wlen < 0)
                        {
                                setstate(failbit);
                                error(errOutput);
@@ -1294,26 +1293,31 @@ int TTYStream::overflow(int c)
                return c;
        }
 
-       req = (ssize_t)(pptr() - pbase());
-       if(req)
+       for(plen = (ssize_t)(pptr() - pbase()), poff = 0; plen > 0;)
        {
-               rlen = aWrite((char *)pbase(), req);
-               if(rlen < 1)
+               wlen = aWrite((char *)pbase() + poff, plen);
+               if(wlen < 1)
                {
-                       if(rlen < 0)
+                       if(wlen < 0)
                        {
                                setstate(failbit);
                                error(errOutput);
                        }
+
+                       // poff written, plen unwritten
+                       if(poff > 0 && plen > 0)
+                       {
+                               memmove(pbuf, pbuf + poff, plen);
+                               setp(pbuf + plen, pbuf + bufsize);
+                       }
+
                        return EOF;
                }
-               req -= rlen;
+               plen -= wlen;
+               poff += wlen;
        }
 
-       if(req)
-//             memmove(pptr(), pptr() + rlen, req);
-               memmove(pbuf, pbuf + rlen, req);
-       setp(pbuf + req, pbuf + bufsize);
+       setp(pbuf, pbuf + bufsize);
 
        if(c == EOF)
                return 0;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]