stream_accept stream_set_byte_order navigation bar

Table of Contents

stream_poll

Polls the stream to determine whether it is possible to send or receive or accept a connection without blocking.

Description

This function polls the stream to determine whether it is possible to send or receive or accept a connection without blocking. The flags argument determines the conditions for which to check. The return value indicates the conditions which occurred. This function returns after the given timeout with a value of 0 if none of the conditions occurs. If an error occurs, then it returns a negative error code. The function will return before the timeout if at least one of the conditions occurs prior to the timeout.

Prototype

t_int
stream_poll(t_stream stream, const t_timeout * timeout, t_uint flags);
    

Parameters

t_stream stream

A stream established using stream_listen, stream_connect or stream_accept.

const t_timeout * timeout

A relative or absolute timeout which determines the maximum time that this function will wait for one of the conditions to occur before returning. A value of NULL indicates an infinite timeout.

t_uint flags

A bit mask indicating the conditions for which to check. Valid flags are:

STREAM_POLL_RECEIVE - on a listening stream, check for connections pending from clients. On a client stream, check whether there is any data available to receive.
STREAM_POLL_SEND - not valid on a listening stream. On a client stream, check whether there is space in the stream buffer to store any data.
STREAM_POLL_FLUSH - not valid on a listening stream. On a client stream, check whether it is possible to flush any more data without blocking.
STREAM_POLL_ACCEPT - not valid on a client stream. On a listening stream, check whether there is a pending client connection.
STREAM_POLL_CONNECT - not valid on a listening stream. On a client stream, check whether the connection has completed.

Return value

A bit mask containing the conditions which were satisfied. It has the same definition as the flags argument. If none of the specified conditions occurs before the timeout, then 0 is returned. If an error occurs then a negative error code is returned.

Error codes

QERR_CANNOT_CONNECT

It was not possible to connect to the specified URI.

Requirements

Include Files

Libraries

quanser_stream.h

quanser_communications.lib;quanser_runtime.lib;quanser_common.lib

Examples

const char uri[] = "shmem://foobar:1";
const t_boolean nonblocking = true;

t_stream server;
        
result = stream_listen(uri, nonblocking, &server);
if (result == 0) {
    t_timeout timeout = { 1, 0, false };
    ...
    while (!stop) {
        ...
        result = stream_poll(server, &timeout, STREAM_POLL_ACCEPT);
        if (result < 0)
            break;
        ...
    }
}
    

See Also

 

navigation bar