Start of trail stream_send_byte navigation bar

Table of Contents

stream_send

Writes data to the stream buffer.

Description

This function writes data to the stream buffer. It attempts to store buffer_size bytes 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.

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 bytes 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 bytes sent successfully, which will be between 1 and the buffer_size (unless buffer_size is zero). If no bytes 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 calling stream_send or stream_flush at the same time. However, stream_send or stream_flush may be called by another thread at the same time as stream_receive.

The semantics of this function are comparable to the BSD send() socket function.

Prototype

t_int
stream_send(t_stream stream, const void * buffer, t_int buffer_size);

    

Parameters

t_stream stream

A client stream established using stream_connect or stream_accept.

const void * buffer

A buffer of at least buffer_size bytes containing the data to be sent.

t_int buffer_size

The number of bytes to send from the buffer.

Return value

The number of bytes sent, which may be less than buffer_size bytes for non-blocking streams. If an error occurs then a negative error code is returned. A value of zero is only returned if the buffer_size is zero.

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