QNET global name problem

Hi,

I have Neutrino installed on a couple of stations running QNET.

I wrote an application which uses “name_attach” to attach a global name.
When the program
runs, I can see the attached name in “/dev/name/global” on the station where
the program
is running.

If I go to another station on the network, I assume that I should also see
that name in the directory
of that station like I did under QNX 4.25, but nothing appears. What am I
doing wrong.

I am using Path B of Neutrino and the tiny tcpip.

Thanks, Jacques

“Jacques Gagne” <gagneja@collegesherbrooke.qc.ca> wrote:

Hi,

I have Neutrino installed on a couple of stations running QNET.

I wrote an application which uses “name_attach” to attach a global name.
When the program
runs, I can see the attached name in “/dev/name/global” on the station where
the program
is running.

If I go to another station on the network, I assume that I should also see
that name in the directory
of that station like I did under QNX 4.25, but nothing appears. What am I
doing wrong.

You’re not doing anything wrong, network distributed global names are not
yet implemented.

-David

QNX Training Services
dagibbs@qnx.com

David Gibbs <dagibbs@qnx.com> wrote:

“Jacques Gagne” <> gagneja@collegesherbrooke.qc.ca> > wrote:
Hi,

I have Neutrino installed on a couple of stations running QNET.

I wrote an application which uses “name_attach” to attach a global name.
When the program
runs, I can see the attached name in “/dev/name/global” on the station where
the program
is running.

If I go to another station on the network, I assume that I should also see
that name in the directory
of that station like I did under QNX 4.25, but nothing appears. What am I
doing wrong.

You’re not doing anything wrong, network distributed global names are not
yet implemented.

Since I’ve been asked for this question several times, and giving the fact
that the implementation won’t get out soon, I attach a function so you can
use to work arround the problem.

-xtang

#include <sys/dispatch.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <share.h>

int my_name_open(const char *name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, 0)) != -1 || (flags & NAME_FLAG_ATTACH_GLOBAL) == 0) {
return fd;
}

if ((dir = opendir("/net")) == NULL) {
errno = ENOENT;
return -1;
}

while (dent = readdir(dir)) {
newname = alloca(strlen("/net/") + strlen(dent->d_name) +
strlen("/dev/name/global/") + strlen(name) + 1);
if (!newname) {
errno = ENOMEM;
return -1;
}
sprintf(newname, “/net/%s/dev/name/global/%s”, dent->d_name, name);
fd = _connect(_NTO_SIDE_CHANNEL, newname, 0, O_RDWR, SH_DENYNO,
_IO_CONNECT_OPEN, 1, _IO_FLAG_RD | _IO_FLAG_WR,
_FTYPE_NAME, 0, 0, 0, 0, 0, 0);
if (fd != -1) {
closedir(dir);
return fd;
}
}

closedir(dir);
errno = ENOENT;
return -1;
}

Xiaodan Tang <xtang@qnx.com> wrote:

Since I’ve been asked for this question several times, and giving the fact
that the implementation won’t get out soon, I attach a function so you can
use to work arround the problem.

-xtang

#include <sys/dispatch.h
#include <dirent.h
#include <errno.h
#include <fcntl.h
#include <share.h

int my_name_open(const char *name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, 0)) != -1 || (flags & NAME_FLAG_ATTACH_GLOBAL) == 0) {

sorry, this line should be like:

if ((fd = name_open(name, flags)) != -1 || (flags & NAME_FLAG_ATTACH_GLOBAL) == 0) {

-xtang

Seems like a solution I can work with!

Thanks for the hint,

Jacques Gagne

“Xiaodan Tang” <xtang@qnx.com> wrote in message
news:9f3krb$nt4$1@nntp.qnx.com

Xiaodan Tang <> xtang@qnx.com> > wrote:

Since I’ve been asked for this question several times, and giving the
fact
that the implementation won’t get out soon, I attach a function so you
can
use to work arround the problem.

-xtang

#include <sys/dispatch.h
#include <dirent.h
#include <errno.h
#include <fcntl.h
#include <share.h

int my_name_open(const char *name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, 0)) != -1 || (flags &
NAME_FLAG_ATTACH_GLOBAL) == 0) {

sorry, this line should be like:

if ((fd = name_open(name, flags)) != -1 || (flags &
NAME_FLAG_ATTACH_GLOBAL) == 0) {

-xtang

I’m learning example name_attach()/name_open() from documentation. Your
solution Mr. Tang for my_name_open() looks nice.
I have 2 hosts with QNX 6.0 Patch B. Qnet is working. I have access to each
other hosts via Qnet.
Then I start server part of example on fisrst host and
client part using your my_name_open() replacement on other. First call
_connect() returns -1 (Ok, it is localhost),
then next call (connect to remote host) return -1 again with perror “No
such process”.

Where I’m wrong ?

Thanks in advance,

Nick

Message from 30.05:

“Xiaodan Tang” <xtang@qnx.com> wrote in message
news:9f3krb$nt4$1@nntp.qnx.com

Xiaodan Tang <> xtang@qnx.com> > wrote:

Since I’ve been asked for this question several times, and giving the
fact
that the implementation won’t get out soon, I attach a function so you
can
use to work arround the problem.

int my_name_open(const char *name, int flags)

I was learning example name_attach()/name_open() from docs. Your
solution, Mr. Tang, for my_name_open() looks nice.
I have 2 hosts with QNX 6.0 Patch B. Qnet is working. I have access to each
other hosts via Qnet.
Then I start server part of example at first host and
client part using your my_name_open() function at another host. First call
_connect() returns -1 (Ok, it’s localhost),
then next call (connect to remote host) returns -1 again with perror “No
such process”.

Where I’m wrong ?

Thanks in advance,

Nick

Message from 30.05:

“Xiaodan Tang” <xtang@qnx.com> wrote in message
news:9f3krb$nt4$1@nntp.qnx.com

Xiaodan Tang <> xtang@qnx.com> > wrote:

Since I’ve been asked for this question several times, and giving the
fact
that the implementation won’t get out soon, I attach a function so you
can
use to work arround the problem.

int my_name_open(const char *name, int flags)

I was learning example name_attach()/name_open() from docs. Your
solution, Mr. Tang, for my_name_open() looks nice.
I have 2 hosts with QNX 6.0 Patch B. Qnet is working. I have access to each
other hosts via Qnet.
Then I start server part of example at first host and
client part using your my_name_open() function at another host. First call
_connect() returns -1 (Ok, it’s localhost),
then next call (connect to remote host) returns -1 again with perror “No
such process”.

Where I’m wrong ?

Thanks in advance,

Nick

Nick <nikolai_r@yahoo.com> wrote:

Message from 30.05:

“Xiaodan Tang” <> xtang@qnx.com> > wrote in message
news:9f3krb$nt4$> 1@nntp.qnx.com> …
Xiaodan Tang <> xtang@qnx.com> > wrote:

Since I’ve been asked for this question several times, and giving the
fact
that the implementation won’t get out soon, I attach a function so you
can
use to work arround the problem.

int my_name_open(const char *name, int flags)

I was learning example name_attach()/name_open() from docs. Your
solution, Mr. Tang, for my_name_open() looks nice.
I have 2 hosts with QNX 6.0 Patch B. Qnet is working. I have access to each
other hosts via Qnet.
Then I start server part of example at first host and
client part using your my_name_open() function at another host. First call
_connect() returns -1 (Ok, it’s localhost),
then next call (connect to remote host) returns -1 again with perror “No
such process”.

Where I’m wrong ?

My guess is the “name” you give in is not correct. If server name_attach(“abc”),
the client should my_name_open(“abc”,…).

If you still can’t make it work, post your sample code.

-xtang

“Xiaodan Tang” <xtang@qnx.com> wrote in message
news:9g7pnt$j7t$1@nntp.qnx.com

Nick <> nikolai_r@yahoo.com> > wrote:
Message from 30.05:

“Xiaodan Tang” <> xtang@qnx.com> > wrote in message
news:9f3krb$nt4$> 1@nntp.qnx.com> …
Xiaodan Tang <> xtang@qnx.com> > wrote:

Since I’ve been asked for this question several times, and giving the
fact
that the implementation won’t get out soon, I attach a function so
you
can
use to work arround the problem.

int my_name_open(const char *name, int flags)

I was learning example name_attach()/name_open() from docs. Your
solution, Mr. Tang, for my_name_open() looks nice.
I have 2 hosts with QNX 6.0 Patch B. Qnet is working. I have access to
each
other hosts via Qnet.
Then I start server part of example at first host and
client part using your my_name_open() function at another host. First
call
_connect() returns -1 (Ok, it’s localhost),
then next call (connect to remote host) returns -1 again with perror
“No
such process”.

Where I’m wrong ?

My guess is the “name” you give in is not correct. If server
name_attach(“abc”),
the client should my_name_open(“abc”,…).

If you still can’t make it work, post your sample code.

-xtang

Thanks in advance, Mr. Tang!
A sample code (full) is below:

--------------- ClientServer.c -----------------
#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;

/*** Server Side of the code ***/
int server() {
name_attach_t *attach;
my_data_t msg;
int rcvid;

/* Create a local name (/dev/name/local/…) */
if ((attach = name_attach(NULL, ATTACH_POINT, NAME_FLAG_ATTACH_GLOBAL))
== NULL) {
return EXIT_FAILURE;
}

/* Do your MsgReceive’s here now with the chid */
while (1) {
rcvid = MsgReceive(attach->chid, &msg, sizeof(msg), NULL);

if (rcvid == -1) { /* Error condition, exit /
/
+++ Added +++ /
printf(“Server. Error was occured!\n”);
/
------------ */
break;
}

if (rcvid == 0) {/* Pulse received /
switch (msg.hdr.code) {
case _PULSE_CODE_DISCONNECT:
/

  • A client disconnected all its connections (called
  • name_close() for each name_open() of our name) or
  • terminated
    /
    ConnectDetach(msg.hdr.scoid);
    break;
    case _PULSE_CODE_UNBLOCK:
    /
  • REPLY blocked client wants to unblock (was hit by
  • a signal or timed out). It’s up to you if you
  • reply now or later.
    /
    break;
    default:
    /
  • A pulse sent by one of your processes or a
  • _PULSE_CODE_COIDDEATH or _PULSE_CODE_THREADDEATH
  • from the kernel?
    */
    }
    continue;
    }

/* A QNX IO message received, reject */
if (msg.hdr.type >= _IO_BASE && msg.hdr.type <= _IO_MAX) {
MsgError(rcvid, ENOSYS);
continue;
}

/* A message (presumable ours) received, handle */
printf(“Server receive %d \n”, msg.data);
MsgReply(rcvid, EOK, 0, 0);

}

/* Remove the name from the space */
name_detach(attach, 0);

return EXIT_SUCCESS;
}

/* +++ Added +++ */
int my_name_open(const char *, int);

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

/* Here is difference from docs example */
if ((fd = my_name_open(ATTACH_POINT, NAME_FLAG_ATTACH_GLOBAL)) == -1) {
perror(“name_open”);
return EXIT_FAILURE;
}

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

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

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

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

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

----------------- my_name_open.c ---------------

#include <sys/dispatch.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <share.h>

int my_name_open(const char * name, int flags)
{
int fd;
DIR *dir;
struct dirent *dent;
char *newname;

if ((fd = name_open(name, flags)) != -1 || (flags &
NAME_FLAG_ATTACH_GLOBAL) == 0) {
return fd;
}

if ((dir = opendir("/net")) == NULL) {
errno = ENOENT;
return -1;
}

while (dent = readdir(dir)) {
newname = alloca(strlen("/net") +
strlen(dent->d_name) +
strlen("/dev/name/global/") +
strlen(name) + 1);
if (!newname) {
errno = ENOMEM;
return -1;
}

sprintf(newname, “/net/%s/dev/name/global/%s”, dent->d_name, name);

fd = _connect(_NTO_SIDE_CHANNEL, newname, 0, O_RDWR, SH_DENYNO,
_IO_CONNECT_OPEN, 1, _IO_FLAG_RD | _IO_FLAG_WR,
_FTYPE_NAME, 0,0,0,0,0,0);
if (fd != -1) {
closedir(dir);
return fd;
}
/* +++ Added +++ /
else
perror(“my_name”);
/
------------- */
}
closedir(dir);
errno = ENOENT;
return -1;
}


Thanks!

Nick

Nick <nikolai_r@yahoo.com> wrote:

“Xiaodan Tang” <> xtang@qnx.com> > wrote in message
news:9g7pnt$j7t$> 1@nntp.qnx.com> …
Nick <> nikolai_r@yahoo.com> > wrote:
Message from 30.05:

“Xiaodan Tang” <> xtang@qnx.com> > wrote in message
news:9f3krb$nt4$> 1@nntp.qnx.com> …
Xiaodan Tang <> xtang@qnx.com> > wrote:

Since I’ve been asked for this question several times, and giving the
fact
that the implementation won’t get out soon, I attach a function so
you
can
use to work arround the problem.

int my_name_open(const char *name, int flags)

I was learning example name_attach()/name_open() from docs. Your
solution, Mr. Tang, for my_name_open() looks nice.
I have 2 hosts with QNX 6.0 Patch B. Qnet is working. I have access to
each
other hosts via Qnet.
Then I start server part of example at first host and
client part using your my_name_open() function at another host. First
call
_connect() returns -1 (Ok, it’s localhost),
then next call (connect to remote host) returns -1 again with perror
“No
such process”.

Where I’m wrong ?

My guess is the “name” you give in is not correct. If server
name_attach(“abc”),
the client should my_name_open(“abc”,…).

If you still can’t make it work, post your sample code.

-xtang



Thanks in advance, Mr. Tang!
A sample code (full) is below:

Your program works fine for me.

There is no magic in this program, after start server,
on client do a “ls /net/server/name/global” see if you can
see the directory.

Add printf to see the “newname” value, if it matches.

Your problems may somewhere else…

-xtang

“Xiaodan Tang” <xtang@qnx.com> wrote in message
news:9gb258$kko$1@nntp.qnx.com

Nick <> nikolai_r@yahoo.com> > wrote:

“Xiaodan Tang” <> xtang@qnx.com> > wrote in message
news:9g7pnt$j7t$> 1@nntp.qnx.com> …
Nick <> nikolai_r@yahoo.com> > wrote:
Message from 30.05:

“Xiaodan Tang” <> xtang@qnx.com> > wrote in message
news:9f3krb$nt4$> 1@nntp.qnx.com> …
Xiaodan Tang <> xtang@qnx.com> > wrote:

Since I’ve been asked for this question several times, and giving
the
fact
that the implementation won’t get out soon, I attach a function so
you
can
use to work arround the problem.

int my_name_open(const char *name, int flags)

I was learning example name_attach()/name_open() from docs. Your
solution, Mr. Tang, for my_name_open() looks nice.
I have 2 hosts with QNX 6.0 Patch B. Qnet is working. I have access
to
each
other hosts via Qnet.
Then I start server part of example at first host and
client part using your my_name_open() function at another host. First
call
_connect() returns -1 (Ok, it’s localhost),
then next call (connect to remote host) returns -1 again with perror
“No
such process”.

Where I’m wrong ?

My guess is the “name” you give in is not correct. If server
name_attach(“abc”),
the client should my_name_open(“abc”,…).

If you still can’t make it work, post your sample code.

-xtang



Thanks in advance, Mr. Tang!
A sample code (full) is below:

Your program works fine for me.

There is no magic in this program, after start server,
on client do a “ls /net/server/name/global” see if you can
see the directory.

Add printf to see the “newname” value, if it matches.

Your problems may somewhere else…

-xtang

OK, Mr. Tang! It’s my mistake. Server part was working under Patch A, but

client - under Patch B.
And I got errors. In reverse order - server under Patch B, client under Pach
A it’s working fine.

Thank in advance!

Nick.