stream_peek_begin stream_peek_byte_array navigation bar

stream_peek_byte

Peeks ahead in the input stream to read a byte from the stream.

Description

This function peeks ahead in the input stream to read a byte from the stream.

The stream_peek_begin function must be called to initialize the peek state. No data peeked will be removed from the input stream until stream_peek_end is called. If stream_peek_end is not called before the next stream_peek_begin then the peeked data is read again.

See the stream_peek_begin function for more information and an example.

If stream_listen or stream_connect was called with the non-blocking flag set to false (0), then this function blocks until all the data is peeked. Blocking may occur because data may be read from the underlying communication channel. However, the contents of the stream buffer are never overwritten until stream_peek_end is called to indicate that the peeked data may be removed from the input stream.

If stream_listen or stream_connect was called with the non-blocking flag set to true (1), then this function does not block. If no byte is available then it returns -QERR_WOULD_BLOCK. In this case, the stream_poll function may be used with the STREAM_POLL_RECEIVE flag to determine when data becomes available. Otherwise it returns 1.

If the connection has been closed gracefully then it returns 0. If an error occurs, then it returns a negative error code.

This function does not support two threads peeking data at the same time. However, data may be sent or the stream flushed by another thread at the same time as data is being peeked.

The BSD socket API has no equivalent to this function.

Prototype

t_int
stream_peek_byte(t_stream stream, t_stream_peek_state * state, t_byte * value);
    

Parameters

t_stream stream

A client stream established using stream_connect or stream_accept.

t_stream_peek_state * state

The "peek state" initialized using stream_peek_begin.

t_byte * value

A pointer to a t_byte variable in which the peeked data will be stored.

Return value

Returns 1 if the data is successfully peeked from the stream. If the connection has been closed gracefully then 0 is returned. If an error occurs then a negative error code is returned.

Error codes

This function does not return any error code.

Requirements

Include Files

Libraries

quanser_stream.h

quanser_communications.lib;quanser_runtime.lib;quanser_common.lib

See Also

 

navigation bar