Proxy problems

I try to implement a message queue
where the sender informs the recipient
if new data with Trigger.

But after a few successful Trigger calls, subsequent
fails when the receiver enters Receive().

sender code snippet:

static pid_t proxy = -1;

if (-1 == proxy) {

pid_t pid;

/* Attach a proxy to receiver */
if (-1 == (pid = Send_ss_getpid(RECIEVER)))
return -1;
printf("%d: pid of RECEIVER: %d\n", getpid(), pid);

if (-1 == (proxy = qnx_proxy_attach(pid, 0, 0, -1)))
return errno;
printf("%d: pid of proxy: %d\n", getpid(), proxy);
}

if (-1 == Trigger(proxy)) {
printf("%d: Trigger(%d) failed: %s\n", getpid(), proxy,
strerror(errno));
return errno;
}
else
printf("%d: Trigger(%d) succeceded\n", getpid(), proxy);

return 0;

when run, it produces the following trace:

2510: pid of RECEIVER: 2520
2510: pid of proxy: 2536
2510: Trigger(2536) succeceded
2510: Trigger(2536) succeceded
2510: Trigger(2536) succeceded
2510: Trigger(2536) succeceded
2510: Trigger(2536) succeceded
2520: enter Receive()
2510: Trigger(2536) failed: No such process
2510: Trigger(2536) failed: No such process
2510: Trigger(2536) failed: No such process
2510: Trigger(2536) failed: No such process
2510: Trigger(2536) failed: No such process
2510: Trigger(2536) failed: No such process


Grateful for any help/insight.

thanks in advance


Per Åkesson
Carmenta AB
SWEDEN

Per Akesson <Per.Akesson@carmenta.se> wrote:

I try to implement a message queue
where the sender informs the recipient
if new data with Trigger.

But after a few successful Trigger calls, subsequent
fails when the receiver enters Receive().

In general, the no such process means that the
proxy no longer exists.

The proxy will be removed/destroyed when either
the owning process terminates (crashes/exits) or
when the owning process explicitly removes the
proxy by calling qnx_proxy_detach().

Try doing a “sin pr” at the command line to check
the existence of a proxy with that proxy id.

Try doing a “sin” at the command line to verify
the existence of the owning process.


if (-1 == (proxy = qnx_proxy_attach(pid, 0, 0, -1)))

In general, the attaching of a proxy to any other process
is not a recommended thing. Architecturally, you are
allocating a resource in one process that will be owned
and only de-allocatable in a different process.

The proper way to do this, is for the process that will
be receiving the proxy notifications to call qnx_proxy_attach()
with a pid of 0, and then to include that proxy id in the
“registration” message when it makes itself known to the
queueing server.

e.g.

proxy = qnx_proxy_attach( 0, 0, 0, -1 );
msg.type = REGISTER_FOR_QUEUE;
msg.proxy = proxy;
queue_pid = qnx_name_locate( “queue_name”, …);
Send( queue_pid, &msg, …);
while(1)
(
pid = Receive(…);
if (pid == proxy )
{
/* get message from queue */
msg.type = GET_MSG_FROM_QUEUE;
Send( queue_pid, &msg, … );

}

}

A couple of the reasons for this include:

– if you attach a proxy to someone else, and then crash before
triggering it, then the owning process doesn’t know the proxy id,
and can never find it out, so the resource is permanently consumed

– if two different processes attach a proxy to the same someone else,
and trigger them, it is very difficult for the receiving process to
know which proxy comes from which other process

-David

Please follow-up to newsgroup, rather than personal email.
David Gibbs
QNX Training Services
dagibbs@qnx.com

David Gibbs wrote:

The proper way to do this, is for the process that will
be receiving the proxy notifications to call qnx_proxy_attach()
with a pid of 0, and then to include that proxy id in the
“registration” message when it makes itself known to the
queueing server.

Thanks, I changed my code according to your
suggestions, and now it works perfect.

thanks again

\

Per Åkesson
Carmenta AB
SWEDEN