I have been studying Hurd and GNU Mach for a while now; and am trying to
figure out how things work. The way IPC is handled under Mach/GNUMach is
rather new to me; and I've read three or four different descriptions
of it; now I've decided to try for myself to get a real understanding.
My references include the Hurd manual, and the Mach documentation from
CMU's page (kernel interface guide and kernel principles; both of which
are showered with code examples ;). I navigate the source while I can, but
I'm still getting use to the structure of things Mach. Following this
is my attempt to lose my message passing virginity; but as you can see,
I didn't get all the way. Any help, redirection towards references, etc,
would be helpful. Thanks!
Things I suspect:
I can't receive the message the way I'm doing it , since I haven't
created a receive right.
What I'm doing is silly because I'm not even in different threads.
(I'm trying to keep things simple).
Things I want to know:
How do I get a port name; say, from another task?
Let's say I want to do producer, consumer...
Task Farmer... Task Cow... Port Barn...
How does Task Cow figure out where Port Barn is?
Is low level message passing irrelevant to Hurd? I've grepped
the source and don't find many references to the msg_send etc
commands.
port_name_array_t ... is it missing? I couldn't find it. Is that
a Hurd thing or a Mach 4.0 thing?
#include <stdio.h>
#include <mach.h>
#include <mach/port.h>
#include <mach/message.h>
int main() {
mach_port_t foo;
boolean_t owner;
mach_msg_option_t option;
mach_msg_timeout_t timeout;
char* msg = "Moo";
struct message {
mach_msg_header_t header;
unsigned int
msgt_name : 8,
msgt_size : 8,
msgt_number : 12,
msgt_inline : 1;
char* inline_data;
unsigned int
msgt_lf : 1,
msgt_deal : 1;
};
struct message my_message;
struct message the_message;
mach_port_allocate( mach_task_self(),
MACH_PORT_RIGHT_SEND, foo );
my_message.inline_data = malloc( 64 );
strcpy( my_message.inline_data, "A Simple Message" );
my_message.header.msgh_size = sizeof( struct message );
my_message.header.msgh_local_port = foo;
my_message.msgt_name = MACH_MSG_TYPE_STRING;
my_message.msgt_inline = 1;
my_message.msgt_lf = 0;
my_message.msgt_deal = 0;
mach_msg_send( (mach_msg_header_t*) &my_message,
MACH_MSG_OPTION_NONE, 0 );
perror("Send Result: ");
the_message.header.msgh_remote_port = &foo;
the_message.inline_data = malloc( 64 );
mach_msg_receive( (mach_msg_header_t*) & the_message,
MACH_MSG_OPTION_NONE, 0 );
perror("Receive result: ");
printf("%s\n", the_message.inline_data );
mach_port_deallocate( mach_task_self(),
foo ) ;
return 0;
}
--
S. A. Hutchins
[EMAIL PROTECTED]
http://www.csis.gvsu.edu/~hutchisa/