public inbox for sid@sourceware.org
 help / color / mirror / Atom feed
From: "J. Johnston" <jjohnstn@cygnus.com>
To: sid@sources.redhat.com
Subject: Re: Generic gloss read patch
Date: Wed, 17 Jan 2001 11:47:00 -0000	[thread overview]
Message-ID: <3A65F6CE.4C568BC8@cygnus.com> (raw)

Ok,

  Instead of making the gloss32::read wait until len characters are available, I have
changed the patch as Frank suggested: it will read all available characters from the rx buffer
at once up to the length requested.  I changed the end of the loop to exit if we have read
from the rx buffer so we won't end up looping endlessly and lose the input thus far.

  The other part of the problem stemmed from the fact that the stdio component was only
reading one character each time it was polled which meant there was only one character
in the buffer when we came in to do a read.  This code has been changed to
try to read a maximum of 1000 bytes.

  With the change the test sequence below behaves as expected under sid gloss:

 write (1, "\nEnter 10 characters\n", 21);
 write (1, "0123456789\n", 11);
 read (0, buffer, 10);
 write (1, buffer, 10);
 write (1, "\n", 1);

I have attached the new patch.  The following are the ChangeLog entries.  Ok to commit?

sid/component/consoles/ChangeLog

2001-01-17  Jeff Johnston  <jjohnstn@redhat.com>

        * stdio.cxx (read): Change to read a reasonable size of data each
	time stdin gets polled.


sid/component/gloss/ChangeLog

2001-01-17  Jeff Johnston  <jjohnstn@redhat.com>

        * gloss.cxx (read): Change use_rx_p code to extract as much
        as possible from the rx buffer (up to the len requested)
        and to exit at the end of the main loop if any characters
        are successfully read.


-- Jeff J.
Index: consoles/stdio.cxx
===================================================================
RCS file: /cvs/src/src/sid/component/consoles/stdio.cxx,v
retrieving revision 1.1
diff -u -r1.1 stdio.cxx
--- stdio.cxx	2000/12/07 19:30:50	1.1
+++ stdio.cxx	2001/01/17 19:45:17
@@ -32,17 +32,20 @@
 void
 stdioConsole::read(host_int_4)
 {
-  unsigned char c;
+  unsigned char buf[1000];
+  int len;
   host_int_4 value;
 
   // Switch to non-blocking input.
   long flags = fcntl(0, F_GETFL);
   fcntl(0, F_SETFL, flags | O_NONBLOCK);
 
-  if (::read(0, &c, 1) > 0)
+  if ((len = ::read(0, buf, 1000)) > 0)
     {
-      value = c;
-      stdin_pin.drive(value);
+      for (int i = 0; i < len; ++i)
+	{
+	  stdin_pin.drive(buf[i]);
+	}
     }
 
   // Restore flags.
Index: gloss/gloss.cxx
===================================================================
RCS file: /cvs/src/src/sid/component/gloss/gloss.cxx,v
retrieving revision 1.3
diff -u -r1.3 gloss.cxx
--- gloss.cxx	2001/01/08 04:30:42	1.3
+++ gloss.cxx	2001/01/17 19:45:18
@@ -1038,8 +1038,13 @@
 
 	  if (rx_buffer.size() > 0)
 	    {
-	      c = rx_buffer.front();
-	      rx_buffer.erase(rx_buffer.begin());
+	      count_read = min (len, rx_buffer.size());
+	      for (int i = 0; i < count_read; ++i)
+		{
+		  c = rx_buffer.front();
+		  rx_buffer.erase (rx_buffer.begin());
+		  strbuf += c;
+		}
 	    }
 	  else
 	    {
@@ -1047,8 +1052,6 @@
 	      errcode = EAGAIN;
 	      return false;
 	    }
-	  count_read = 1;
-	  strbuf = c;
 	}
       else
 	{
@@ -1095,6 +1098,11 @@
       addr = addr + count_read;
       total_read += count_read;
       len -= count_read;
+
+      // if we have read from the rx_buffer, then we have either emptied it
+      // or read the required number of characters so we should exit the loop
+      if (use_rx_p && count_read > 0)
+	break;
     }
 
   len_read = total_read;

             reply	other threads:[~2001-01-17 11:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-17 11:47 J. Johnston [this message]
2001-01-17 12:02 ` Ben Elliston
2001-01-17 13:06   ` J. Johnston
  -- strict thread matches above, loose matches on Subject: below --
2001-01-16 15:34 J. Johnston
2001-01-16 16:30 ` Frank Ch. Eigler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3A65F6CE.4C568BC8@cygnus.com \
    --to=jjohnstn@cygnus.com \
    --cc=sid@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).