Generic gloss read patch
Frank Ch. Eigler
fche@redhat.com
Tue Jan 16 16:30:00 GMT 2001
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-----
More information about the Sid
mailing list