This is the mail archive of the sid@sources.redhat.com mailing list for the SID project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Generic gloss read patch


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

PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]