[Previous] [Contents] [Next]

name_open()

Open a name for a server connection

Synopsis:

#include <sys/dispatch.h>

int name_open( const char * name, 
               int flags );

Library:

libc

Description:

The name_open() function opens name for a server connection. The flags argument, as with name_attach(), specifies whether it's a local or global connection (not supported yet). No ordering is guaranteed when accessing resources on other nodes.

Returns:

A nonnegative integer representing the lowest numbered unused file descriptor. Otherwise, -1 is returned (errno is set).


Note: In QNX 6, the returned file descriptor is the same as the connection ID (or coid) used by the QNX-specific functions.

Errors:

EACCES
Search permission is denied on a component of the name.
EBADFSYS
While attempting to open the named file, either the file itself or a component of the path prefix was found to be corrupted. A system failure -- from which no automatic recovery is possible -- occurred while the file was being written to, or while the directory was being updated. You'll need to invoke appropriate systems-administration procedures to correct this situation before proceeding.
EBUSY
The connection specified by name has already been opened and additional connections aren't permitted.
EINTR
The name_open() operation was interrupted by a signal.
EISDIR
The named path is a directory.
ELOOP
Too many levels of symbolic links or prefixes.
EMFILE
Too many file descriptors are currently in use by this process.
ENAMETOOLONG
The length of the name string exceeds PATH_MAX, or a pathname component is longer than NAME_MAX.
ENFILE
Too many files are currently open in the system.
ENOENT
The connection specified by name doesn't exist.
ENOTDIR
A component of the name prefix isn't a directory.

Examples:

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/dispatch.h>

#define ATTACH_POINT "myname"

/* We specify the header as being at least a pulse */
typedef struct _pulse msg_header_t;

/* Our real data comes after the header */
typedef struct _my_data {
                     msg_header_t hdr;
                     int data;
} my_data_t;


/*** Client Side of the code ***/
int client() {
         my_data_t value;
         int fd;

    if ((fd = name_open(ATTACH_POINT, 0)) == -1) {
    return EXIT_FAILURE;
    }

    /* We would have pre-defined data to stuff here */
    value.hdr.type = 0x00;
    value.hdr.subtype = 0x00;

    /* Do whatever work you wanted with server connection */
    for (value.data=0; value.data < 5; value.data++) {
            printf("Client sending %d \n", value.data);
            if (MsgSend(fd, &value, sizeof(value), NULL, 0) == -1) {
                    break;
            }
    }

    /* Close the connection */
    name_close(fd);
    return EXIT_SUCCESS;
}

int main(int argc, char **argv) {
    int ret;

    if (argc < 2) {
            ret = EXIT_FAILURE;
    }
    else if (strcmp(argv[1], "-c") == 0) {
            printf("Running Client ... \n");
            ret = client();      /* see name_open() */
    }
    else if (strcmp(argv[1], "-s") == 0) {
            printf("Running Server ... \n");
            ret = server();      /* see name_attach() */
    }
    else {
            printf("Usage %s [-s] | [-c] \n");
            ret = EXIT_FAILURE;
    }
    return ret;
}

Classification:

QNX 6

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

See also:

ConnectAttach(), name_attach(), name_detach(), name_close(), open()


[Previous] [Contents] [Next]