• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using dead notification with mach ports
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using dead notification with mach ports


  • Subject: Re: Using dead notification with mach ports
  • From: Jim Magee <email@hidden>
  • Date: Sat, 11 Sep 2004 10:01:51 -0400

On Sep 11, 2004, at 9:36 AM, Jim Magee wrote:
On Sep 11, 2004, at 4:55 AM, Stiphane LETZ wrote:
4) client get this new private port from the server (same method as 2
)

This is where you went astray. The clients wouldn't look the new message queue up in some global namespace, but instead it would be returned to them (privately) as part of the reply to this "connection request" RPC.

So now the server does the following fo each new client in the "connection request" RPC.

mach_port_t task = mach_task_self();
mach_port_t old_port;

mach_port_allocate(task,MACH_PORT_RIGHT_RECEIVE,&clientPort)

mach_port_insert_right (task,clientPort,clientPort,MACH_MSG_TYPE_MAKE_SEND)

mach_port_move_member(task,clientPort,serverPort)

mach_port_request_notification(task, clientPort,
MACH_NOTIFY_NO_SENDERS,
1, serverPort,
MACH_MSG_TYPE_MAKE_SEND_ONCE,&old_port);

where serverPort will be used by the server in the mach_msg_server.

Then clientPort has to be sent back to the client, how is this done?
Only by sending the clientPort back? Or the client needs to get a copy
of send right to that clientPort Mach message queue alloccated by the
server?

I'm quite confused...

Sorry, I sent that early by mistake....

Anyway, one of the 2 or 3 primary advantages of Mach IPC over other forms is the flexibility in passing other port rights in messages. Since it appears you are using MIG, you simply have to declare an "out" parameter (or two, if you count sending the semaphore as well) of type mach_port_t. That will arrange to have send rights transfered to the client (copied, to be explicit). But for the no-senders notification to fire, the server can't hold its own send right to that port (and you have given the server a send right with the mach_port_insert_right() call above). Instead, it must "move" the send right it created to the client. You can do this in one of two ways:

You can declare the "out" parameter as type "mach_port_move_send_t" in the MIG definition
or
You could declare it of type "mach_port_make_send_t" and skip the call to mach_port_insert_right() altogether


Here's an example MIG definition that assumes the latter approach:

routine StephaneConnectToServer
(
	serverPort	: mach_port_t;
	connectFlags	: integer_t;
out	semaphorePort: semaphore_t;
out	connectionPort: mach_port_make_send_t
);

Hope that helps,
--Jim
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.


References: 
 >Using dead notification with mach ports (From: Stéphane Letz <email@hidden>)
 >Re: Using dead notification with mach ports (From: Jim Magee <email@hidden>)
 >Re: Using dead notification with mach ports (From: Stéphane Letz <email@hidden>)
 >Re: Using dead notification with mach ports (From: Jim Magee <email@hidden>)
 >Re: Using dead notification with mach ports (From: Stéphane LETZ <email@hidden>)
 >Re: Using dead notification with mach ports (From: Jim Magee <email@hidden>)

  • Prev by Date: Re: Using dead notification with mach ports
  • Next by Date: using stat
  • Previous by thread: Re: Using dead notification with mach ports
  • Next by thread: Calling shm_open from a CFM app.
  • Index(es):
    • Date
    • Thread