From: "Frank Ch. Eigler" <fche@redhat.com>
To: "J. Johnston" <jjohnstn@cygnus.com>
Cc: sid@sources.redhat.com
Subject: Re: Generic gloss read patch
Date: Tue, 16 Jan 2001 16:30:00 -0000 [thread overview]
Message-ID: <20010116193023.G18054@redhat.com> (raw)
In-Reply-To: <3A64DA7A.FC6F014@cygnus.com>
Hi -
jjohnstn wrote:
: I ran into a problem with gloss32::read trying to read n characters
: from stdin.
: read (0, buffer, 10);
: What happens is that the gloss32::read function reads one character at
: a time from the buffer in a loop that is checking to see if the total
: number of characters has been read. The read buffer doesn't get filled
: right away so if read empties the buffer before the len characters are
: read, it returns false and denotes the read as blocked. [...]
That's true - gloss is not right to do that. However, the UNIX read system
call is permitted to return any number of bytes > 0 and <= 10 in response to
such a call; it need not block until exactly 10 arrive.
This means that your fix is nearly right, except that it should not assert
! // check if we have enough characters to satisfy the request
! // if not, no point in reading since we will end up blocked
! // and the read will be reissued
! if (rx_buffer.size() >= len)
but rather "> 0"; and then the loop
! for (int i = 0; i < len; ++i)
should read
! for (int i = 0; i < len && rx_buffer.size() > 0; ++i)
By the way, as an alternative to the character-by-character copy loop
from rx_buffer to strbuf, consider something like
strbuf = rx_buffer.substr (0, min(len, rx_buffer.size()));
rx_buffer = rx_buffer.substr (min(len, rx_buffer.size()));
- FChE
--
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE6ZOefVZbdDOm/ZT0RAmWpAJ0b98jLi4lVHwjTLsWGbBMoVXqMigCcDWkJ
4N2qNQbWMrW8AlYVuHUb2ZA=
=R3cT
-----END PGP SIGNATURE-----
next prev parent reply other threads:[~2001-01-16 16:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-01-16 15:34 J. Johnston
2001-01-16 16:30 ` Frank Ch. Eigler [this message]
2001-01-17 11:47 J. Johnston
2001-01-17 12:02 ` Ben Elliston
2001-01-17 13:06 ` J. Johnston
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=20010116193023.G18054@redhat.com \
--to=fche@redhat.com \
--cc=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).