stream_peek_single_array stream_peek_double_array navigation bar

Table of Contents

stream_peek_double

Peeks ahead in the input stream to read a double-precision (64-bit) floating-point number from the stream.

Description

This function peeks ahead in the input stream to read a double-precision (64-bit) floating-point number from the stream. If the stream has been configured to swap bytes using stream_set_swap_bytes or stream_set_byte_order then this function will swap the order of the bytes that it peeks before storing them in the given buffer.

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 fewer bytes are available then the size of a double-precision floating-point number 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 only if there are fewer bytes left to peek than the size of a double-precision floating-point number. Otherwise it returns the number of double-precision floating-point numbers peeked before the connection closed. Once there are fewer bytes left to peek than the size of a double-precision floating-point number then it will return 0 to indicate the connection has been closed. Use stream_peek to peek any remaining bytes if required. 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_double(t_stream stream, t_stream_peek_state * state, t_double * 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_double * value

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

Return value

Returns 1 if the data is successfully peeked from the stream. If fewer bytes than the size of a double-precision floating-point number are available and 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