host/stream_comm.c
/** Grab one byte from the communication stream. There is no way for this
  * function to indicate a read error. This is intentional; it
  * makes program flow simpler (no need to put checks everywhere). As a
  * consequence, this function should only return if the received byte is
  * free of read errors.
  *
  * Previously, if a read or write error occurred, processPacket() would
  * return, an error message would be displayed and execution would halt.
  * There is no reason why this couldn't be done inside streamGetOneByte()
  * or streamPutOneByte(). So nothing was lost by omitting the ability to
  * indicate read or write errors.
  *
  * Perhaps the argument can be made that if this function indicated read
  * errors, the caller could attempt some sort of recovery. Perhaps
  * processPacket() could send something to request the retransmission of
  * a packet. But retransmission requests are something which can be dealt
  * with by the implementation of the stream. Thus a caller of
  * streamGetOneByte() will assume that the implementation handles things
  * like automatic repeat request, flow control and error detection and that
  * if a true "stream read error" occurs, the communication link is shot to
  * bits and nothing the caller can do will fix that.
  * \return The received byte.
  */
Grab one byte from the communication stream. There is no way for this
function to indicate a read error. This is intentional; it
makes program flow simpler (no need to put checks everywhere). As a
consequence, this function should only return if the received byte is
free of read errors.

Previously, if a read or write error occurred, processPacket() would
return, an error message would be displayed and execution would halt.
There is no reason why this couldn't be done inside streamGetOneByte()
or streamPutOneByte(). So nothing was lost by omitting the ability to
indicate read or write errors.

Perhaps the argument can be made that if this function indicated read
errors, the caller could attempt some sort of recovery. Perhaps
processPacket() could send something to request the retransmission of
a packet. But retransmission requests are something which can be dealt
with by the implementation of the stream. Thus a caller of
streamGetOneByte() will assume that the implementation handles things
like automatic repeat request, flow control and error detection and that
if a true "stream read error" occurs, the communication link is shot to
bits and nothing the caller can do will fix that.
\return The received byte.
Grab one byte from the communication stream . There is no way for this function to indicate a read error . This is intentional ; it makes program flow simpler ( no need to put checks everywhere ) . As a consequence this function should only return if the received byte is free of read errors . Previously if a read or write error occurred processPacket () would return an error message would be displayed and execution would halt . There is no reason why this couldn ' t be done inside streamGetOneByte () or streamPutOneByte () . So nothing was lost by omitting the ability to indicate read or write errors . Perhaps the argument can be made that if this function indicated read errors the caller could attempt some sort of recovery . Perhaps processPacket () could send something to request the retransmission of a packet . But retransmission requests are something which can be dealt with by the implementation of the stream . Thus a caller of streamGetOneByte () will assume that the implementation handles things like automatic repeat request flow control and error detection and that if a true " stream read error " occurs the communication link is shot to bits and nothing the caller can do will fix that . \ return The received byte .
uint8_t streamGetOneByte(void)
{
	if (is_stream_of_infinite_zeros)
		return 0;
	if (stream == NULL)
	{
		printf("ERROR: Tried to read a stream whose contents weren't set.\n");
		exit(1);
	}
	if (stream_byte_index >= stream_length)
	{
		printf("ERROR: Tried to read past the end of the stream.\n");
		exit(1);
	}
	return stream[stream_byte_index++];
}
uint8_t streamGetOneByte ( void ) { if ( is_stream_of_infinite_zeros ) return 0 ; if ( stream == NULL ) { printf ( " \n " ) ; exit ( 1 ) ; } if ( stream_byte_index >= stream_length ) { printf ( " \n " ) ; exit ( 1 ) ; } return stream [ stream_byte_index ++ ] ; }
Grab one byte from the communication stream.
Grab one byte from the communication stream .