stream_send_unit stream_send_unit_array navigation bar

stream_send_units

Writes an array of "units" to the stream buffer, where the size of a "unit" is determined by the unit_size parameter.

Description

This function writes an array of "units" to the stream buffer, where the size of a "unit" is determined by the unit_size parameter. It attempts to store the units in the stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed using stream_flush or there is no more room available in the stream buffer. If an error occurs, then it returns a negative error code. If the connection is closed it is considered an error condition.

Unlike the stream_send_unit_array function, this function does not require that the stream send buffer be at least num_units * unit_size bytes in length. Hence, it allows smaller stream buffers to be used.

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 within each unit when they are sent.

If stream_listen or stream_connect was called with the non-blocking flag set to false (0), then this function may block attempting to flush the stream buffer. All the data will be consumed and the total number of units sent is returned. Some of the data may remain in the stream buffer and not be sent until the next time stream_flush is called or there is no more room available in the stream buffer. If an error occurs then the error code is returned and the stream should be closed.

If stream_listen or stream_connect was called with the non-blocking flag set to true (1), then this function does not block. It returns the number of units sent successfully, which will be between 1 and num_units (unless num_units is zero). If no units could be sent without blocking, then -QERR_WOULD_BLOCK is returned. If an error occurs then the error code is returned and the stream should be closed.

This function does not support two threads sending or flushing 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 received.

The BSD socket API has no equivalent to this function.

Prototype

t_int
stream_send_units(t_stream stream, const void * units, t_int unit_size, t_int num_units);

    

Parameters

t_stream stream

A client stream established using stream_connect or stream_accept.

const void * units

The array to be sent.

t_int unit_size

The size of one element in the array.

t_int num_units

The number of elements in the array to send.

Return value

The number of units sent, which may be less than the number requested for non-blocking streams. 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