[Previous] [Contents] [Index] [Next]

Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

nbaconnect()

Initiate a connection on a socket (nonblocking)

Synopsis:

#include <sys/socket.h>

int nbaconnect( int s, 
                const struct sockaddr * name,
                size_t namelen );

Arguments:

s
The descriptor of the socket on which to initiate the connection.
name
The name of the socket to connect to for a SOCK_STREAM connection.
namelen
The length of the name, in bytes.

Library:

libsocket

Use the -l socket option to qcc to link against this library.

Description:

The nbaconnect() function is called in place of connect(), to prevent a nonblocking connect() from blocking during an autoconnect (see /etc/autoconnect).

When the autoconnect behavior is used, connect() may block your application while waiting for the autoconnect to complete; nbaconnect() allows your application to continue executing during the autoconnect.

The nbaconnect() function takes the same arguments as connect(), but it differs in the return value when an autoconnect is required. If an autoconnect is required, a file descriptor (fd) is returned. The fd is used in the call to nbaconnect_result() to get the errno related to the autoconnect and the connect attempt.


Note: Since nbaconnect_result() is a blocking call, it's recommended that you call select() first to determine if there's data available on the pipe.

When the data's available, call nbaconnect_result() to get the status of the nbaconnect() attempt.

If an autoconnect isn't required, nbaconnect() returns -1 and exhibits the same behavior as connect() on nonblocking sockets (e.g. if -1 is returned and errno is set to EINPROGRESS, it's possible to do a select() for completion by selecting the socket for writing).

Returns:

A file descriptor that you can pass to nbaconnect_result() to get the result of the nbaconnect() attempt, or -1 if an error occurred (errno is set).

Errors:

Any value from the Errors section in connect(), as well as:

EINVAL
The socket file descriptor being passed isn't nonblocking.

Classification:

QNX Neutrino

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

Caveats:

The pipe manager must be available.

See also:

accept(), bind(), connect(), errno, fcntl(), getsockname(), nbaconnect_result(), open(), pipe(), read(), select(), socket(), write()

/etc/autoconnect, pipe in the Utilities Reference.


[Previous] [Contents] [Index] [Next]