stream_listen stream_poll navigation bar

Table of Contents

stream_accept

Accepts a connection to a listening communication stream by a client.

Description

This function accepts a connection to a listening communication stream by a client. The client connects using stream_connect.

If stream_listen was called with non_blocking set to false (0) then this call will block until a client connects. The client stream returned will also be a blocking stream.

If stream_listen was called with non_blocking set to true (1) then this call will not block. If there is no pending client connection then it will return -QERR_WOULD_BLOCK. The stream_poll function may be used with the STREAM_POLL_ACCEPT flag to determine when a client connection is pending. In this case, the client stream returned will also be a non-blocking stream.

On POSIX systems this function should be interruptible by a signal so that arrival of a signal will cause a -QERR_INTERRUPTED error to be returned.

Prototype

t_error
stream_accept(t_stream server_stream, t_int send_buffer_size, t_int receive_buffer_size, t_stream * client_stream);
    

Parameters

t_stream server_stream

A listening stream established using stream_listen.

t_int send_buffer_size

The size of the buffer to use for sending data over the stream, in bytes.

t_int receive_buffer_size

The size of the buffer to use for receiving data over the stream, in bytes.

t_stream * client_stream

A pointer to a t_stream variable in which the client stream handle will be stored.

Return value

Returns 0 on success. If an error occurs then a negative error code is returned.

Error codes

QERR_WOULD_BLOCK

The connection is in non-blocking mode and there are no pending client connections.

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 = false;
const t_int send_buffer_size = 8000;
const t_int receive_buffer_size = 8000;

t_stream server;
t_stream client;

result = stream_listen(uri, nonblocking, &server);
if (result == 0){
    ...
    result = stream_accept(server, send_buffer_size, receive_buffer_size, &client);
    if (result == 0){
        ...
    }
}
    

See Also

 

navigation bar