![]() |
![]() |
![]() |
Open a name for a server connection
#include <sys/dispatch.h> int name_open( const char * name, int flags );
libc
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.
A nonnegative integer representing the lowest numbered unused file descriptor. Otherwise, -1 is returned (errno is set).
![]() |
In QNX 6, the returned file descriptor is the same as the connection ID (or coid) used by the QNX-specific functions. |
#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; }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
ConnectAttach(), name_attach(), name_detach(), name_close(), open()
![]() |
![]() |
![]() |