bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some questions about libports and notification of ports


From: Thomas Bushnell BSG
Subject: Re: Some questions about libports and notification of ports
Date: Sun, 24 Aug 2008 17:57:16 -0700

On Sun, 2008-08-24 at 19:36 +0200, Da Zheng wrote:
> As I said above, I have to make sure all ports created for the user 
> program have been destroyed before the translator exits.

Are these ports that the translator has the receive rights to?  If so,
then when the translator exits, they will all be destroyed.  

> Assume that I create a port for the user programs and give its send 
> right to them.
> After ports_create_port() and several ports_get_right() are called, the 
> reference count of the port is 2.

Yes.

> When all user programs exit, the no-senders notification for the port is 
> generated.
> If ports_port_deref() isn't called somewhere, the reference count of the 
> port is still 2 when the no-senders notification comes, therefore, the 
> port cannot be destroyed by ports_no_senders() or 
> ports_do_mach_notify_no_senders() or something else.

Exactly.  That's because when you call ports_create_port, you create a
reference, and you must free it before that stack frame returns.

> That's why I ask you for a suggestion where I should call 
> ports_port_deref() to decrease the reference count when there is a 
> sequence of ports_get_right() calls.

I'm keep telling you.  Calling ports_get_right does not mean you need to
call ports_port_deref, and never does in normal Hurd code.  But calling
ports_create_port does create a reference, and *that* reference must
indeed be freed, by ports_port_deref, before the calling routine is
done.

Now, this has *NOTHING* to do with calling ports_destroy_right, which is
only needed in very special cases.

> It's exactly what I did after I followed your suggestion to use the 
> structure of proxy_user, proxy_device and proxy:-).
> In the clean routine of proxy_user, I also freed the memory of proxy.
> In the clean routine of proxy_device, I just set the pointer to the 
> proxy_device in the proxy structure null (device->proxy->device = NULL).

But as you point out, the Mach device still has a reference to your
port, so you do need to destroy the right.  This is really because you
are using libports to serve a port which is not following normal Hurd
protocols.  (The port a Mach device sends filtered packets on is not
following Hurd protocols.)

Once you have things in a way you think looks good, why don't you post
the relevant code here, so that more eyes can look at it?

Thomas






reply via email to

[Prev in Thread] Current Thread [Next in Thread]