• 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
Using dead notification with mach ports
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using dead notification with mach ports


  • Subject: Using dead notification with mach ports
  • From: Stéphane Letz <email@hidden>
  • Date: Fri, 10 Sep 2004 12:40:50 +0200

Hi

I'm developing  a server/client system and would like  to use the
MACH_NOTIFY_DEAD_NAME system so that the server can know when clients
disappear abnormally (crash...)

On the server side :

Registration of the server port:

......
......
	mach_port_t task = mach_task_self();

	if (task_get_bootstrap_port(task, &fBootPort) != KERN_SUCCESS) {
		printf("AllocatePort: Can't find bootstrap mach port");
		return false;
	}

	if (mach_port_allocate(task, MACH_PORT_RIGHT_RECEIVE, &fServerPort) !=
KERN_SUCCESS) {
		printf("AllocatePort: can't allocate mach port");
		return false;
	}

	if (mach_port_insert_right(task, fServerPort, fServerPort,
MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS) {
		printf("AllocatePort: error inserting mach rights");
		return false;
	}

	if (bootstrap_register(fBootPort, "server", fServerPort) !=
KERN_SUCCESS) {
		printf("Allocate: can't check in mach port");
		return false;
	}
......
......

Then in a thread to get messages coming from clients:

boolean_t server_demux(mach_msg_header_t *Request,mach_msg_header_t
*Reply)
{
	printf("received message on port %x\n", Request->msgh_local_port);
	.....
	.....
	return TRUE;
}

kern_return_t res = mach_msg_server(server_demux,1024,fServerPort,0);


On the client side :

Connection to the server port:

......
......

	mach_port_t task = mach_task_self();

	if (task_get_bootstrap_port(task, &fBootPort) != KERN_SUCCESS) {
		printf("ConnectPort: can't find bootstrap port");
         return false;
      }

	if (bootstrap_look_up(fBootPort,  "server", &fServerPort) !=
KERN_SUCCESS) {
		printf("ConnectPort: can't find mach server port");
		return false;
	}
......
......

This works correctly to use MIG generated RPC between the clients and
the server.

Then I'm trying to add a dead notification to notify the server when
clients disappear :

On the client side :

	mach_port_t server_port;
	mach_port_t old_port;

	if (task_for_pid(mach_task_self(),getpid(),&server_port) !=
KERN_SUCCESS) {
		printf("NotifyDead: can't find mach task_for_pid");
		return false;
	}

	kern_return_t result;
	if ((result =
mach_port_request_notification(mach_task_self(),server_port,
												MACH_NOTIFY_DEAD_NAME,
												0,fServerPort,MACH_MSG_TYPE_MAKE_SEND_ONCE,
												&old_port)) != KERN_SUCCESS) {

		printf("NotifyDead %s\n",mach_error_string(result));
		return false;
	}


But I always get a "NotifyDead  (ipc/send) invalid port right" error
message.


Any idea of what is wrong? Is is the right way to do? Any link to
code/examples that implements this correctly?

Thanks

Stephane Letz
_______________________________________________
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.


  • Follow-Ups:
    • Re: Using dead notification with mach ports
      • From: Jim Magee <email@hidden>
  • Prev by Date: API to open the firewall?
  • Next by Date: Re: API to open the firewall?
  • Previous by thread: Re: API to open the firewall?
  • Next by thread: Re: Using dead notification with mach ports
  • Index(es):
    • Date
    • Thread