* process.c (read_process_output): Do adaptive read buffering even if carryover.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 4 Apr 2011 09:04:33 +0000 (02:04 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 4 Apr 2011 09:04:33 +0000 (02:04 -0700)
src/ChangeLog
src/process.c

index c4c7e4e..6c28e61 100644 (file)
@@ -4,6 +4,7 @@
        (exec_sentinel): Remove vars that were set but not used.
        (create_pty): Remove unnecessary "volatile"s.
        (Fnetwork_interface_info): Avoid possibility of int overflow.
+       (read_process_output): Do adaptive read buffering even if carryover.
 
        * bytecode.c (exec_byte_code): Rename local to avoid shadowing.
 
index 50a068b..33f41c4 100644 (file)
@@ -5162,15 +5162,22 @@ read_process_output (Lisp_Object proc, register int channel)
     }
   else
 #endif
-  if (proc_buffered_char[channel] < 0)
     {
+      int buffered = 0 <= proc_buffered_char[channel];
+      if (buffered)
+       {
+         chars[carryover] = proc_buffered_char[channel];
+         proc_buffered_char[channel] = -1;
+       }
 #ifdef HAVE_GNUTLS
       if (XPROCESS (proc)->gnutls_p)
        nbytes = emacs_gnutls_read (channel, XPROCESS (proc),
-                                    chars + carryover, readmax);
+                                   chars + carryover + buffered,
+                                   readmax - buffered);
       else
 #endif
-       nbytes = emacs_read (channel, chars + carryover, readmax);
+       nbytes = emacs_read (channel, chars + carryover + buffered,
+                            readmax - buffered);
 #ifdef ADAPTIVE_READ_BUFFERING
       if (nbytes > 0 && p->adaptive_read_buffering)
        {
@@ -5184,7 +5191,7 @@ read_process_output (Lisp_Object proc, register int channel)
                  delay += READ_OUTPUT_DELAY_INCREMENT * 2;
                }
            }
-         else if (delay > 0 && (nbytes == readmax))
+         else if (delay > 0 && nbytes == readmax - buffered)
            {
              delay -= READ_OUTPUT_DELAY_INCREMENT;
              if (delay == 0)
@@ -5198,22 +5205,13 @@ read_process_output (Lisp_Object proc, register int channel)
            }
        }
 #endif
-    }
-  else
-    {
-      chars[carryover] = proc_buffered_char[channel];
-      proc_buffered_char[channel] = -1;
-#ifdef HAVE_GNUTLS
-      if (XPROCESS (proc)->gnutls_p)
-       nbytes = emacs_gnutls_read (channel, XPROCESS (proc),
-                                    chars + carryover + 1, readmax - 1);
-      else
-#endif
-       nbytes = emacs_read (channel, chars + carryover + 1,  readmax - 1);
-      if (nbytes < 0)
-       nbytes = 1;
-      else
-       nbytes = nbytes + 1;
+      if (buffered)
+       {
+         if (nbytes < 0)
+           nbytes = 1;
+         else
+           nbytes = nbytes + 1;
+       }
     }
 
   p->decoding_carryover = 0;