message_connect()

Updated: October 26, 2022

Create a connection to a channel

Synopsis:

#include <sys/iofunc.h>
#include <sys/dispatch.h>

int message_connect( dispatch_t * dpp,
                     int flags );

Arguments:

dpp
The dispatch handle, as returned by a successful call to dispatch_create().
flags
Currently, the following flag is defined in <sys/dispatch.h>:
  • MSG_FLAG_SIDE_CHANNEL — request the connection ID be a side-channel connection (see the ConnectAttach() section on _NTO_SIDE_CHANNEL). We recommend you set MSG_FLAG_SIDE_CHANNEL, so the ID will be greater than any valid file descriptor. Once they're created, there's no difference in the use of the messaging primitives on these IDs.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The message_connect() function creates a connection to the channel used by dispatch handle dpp. This function calls the ConnectAttach() kernel call. To detach the connection ID, you can call ConnectDetach().

Returns:

A connection ID used by the message primitives, or -1 if an error occurs (errno is set).

Errors:

EAGAIN
All kernel connection objects are in use.

The message_connect() function can set errno to any of the errors indicated by ConnectAttach().

Examples:

#include <sys/dispatch.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
        
int main( int argc, char **argv ) {
   dispatch_t    *dpp;
   int           coid;
    
   if( ( dpp = dispatch_create() ) == NULL ) {
     fprintf( stderr, 
        "%s: Unable to allocate dispatch context.\n",
        argv[0] );
     return EXIT_FAILURE;
   }
    
   …

   if( (coid = message_connect ( dpp, MSG_FLAG_SIDE_CHANNEL)) == -1 ) {
     fprintf ( stderr, "Failed to create connection \
               to channel used by dispatch.\n");
     return EXIT_FAILURE;
   }
   /* else connection to channel used by dispatch is created */
            
   …
}

For examples using the dispatch interface, see dispatch_create(), message_attach(), resmgr_attach(), and thread_pool_create().

Classification:

QNX Neutrino

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