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]

Generic gloss read patch


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.  
This causes the read to be reissued with the original buffer and len specified.  Unfortunately,
gloss32::read has already eaten some characters from the rx buffer which are lost forever.
In the end, the application just hangs waiting for the read to be satisfied.

The fix changes the code so that the rx buffer read is not performed unless
the desired number of characters are already there in which case, it reads them all at once.

I have attached a patch for sid/component/gloss/gloss.cxx.  Ok to commit?

-- Jeff J.
Index: gloss.cxx
===================================================================
RCS file: /cvs/src/src/sid/component/gloss/gloss.cxx,v
retrieving revision 1.3
diff -c -p -r1.3 gloss.cxx
*** gloss.cxx	2001/01/08 04:30:42	1.3
--- gloss.cxx	2001/01/16 23:19:57
*************** gloss32::read (int fd, address32 addr, s
*** 1036,1045 ****
  	{
  	  char c;
  
! 	  if (rx_buffer.size() > 0)
  	    {
! 	      c = rx_buffer.front();
! 	      rx_buffer.erase(rx_buffer.begin());
  	    }
  	  else
  	    {
--- 1036,1054 ----
  	{
  	  char c;
  
! 	  // 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)
  	    {
! 	      count_read = 0;
! 	      for (int i = 0; i < len; ++i)
! 		{
! 		  c = rx_buffer.front();
! 		  rx_buffer.erase(rx_buffer.begin());
! 		  ++count_read;
! 		  strbuf += c;
! 		}
  	    }
  	  else
  	    {
*************** gloss32::read (int fd, address32 addr, s
*** 1047,1054 ****
  	      errcode = EAGAIN;
  	      return false;
  	    }
- 	  count_read = 1;
- 	  strbuf = c;
  	}
        else
  	{
--- 1056,1061 ----

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