[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Trying to understand Mach IPC
From: |
Manu Valderrama |
Subject: |
Trying to understand Mach IPC |
Date: |
Sun, 09 Jun 2002 22:56:35 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 |
Hello! I would need some help with Mach IPC ( without using MIG, only
the syscalls for IPC ); I was writing
some example programs with the purpose to learn about Mach IPC, and now
I'm blocked and don't know
how to continue. I hope that somewhat could help me in this mailing list.
I had used for trying to program mach IPC, the OSF manuals ( IMHO not
very good for programming learning; either they are reference manuals,
either they explain you only the ideas behind Mach; they are better suitted
for those who already know mach ), the gnumach reference manuals, and "A
programmer's guide to the mach
system calls", that treats about mach 2.5 IPC wo MIG; then I tried to
adapt what in this last text is said
to the Mach 3.0 system calls and message data structures , described in
the gnumach reference manual and
in the "Mach 3 Kernel Interfaces" of the OSF, but whithout success, :-(
Then my questions are :
(i) who do I construct a message in C language ?
I tried the following ( just a mach 3 adaption of some sample
code of "A programmer's guide.... " ) :
make a structure like that :
struct simple_message {
mach_msg_header_t head;
mach_msg_type_t type;
int inline_data;
};
struct simple_message my_message;
Then fill some fields of msg_header and msg_type :
my_message.head.msgh_size = sizeof( struct simple_message );
.....
my_message.head.msgh_remote_port = my_port; ( being
my_port a valid port with receive rigths )
....
my_message.type.msgt_name = MACH_MSG_INTEGER_32;
.....
and so on..... but I think that it is not the way.
(ii) Once I have a well formed message, who do I send this message
correctly ?
I tried in this case the following :
msg_return_code = mach_msg( &(my_message.head), MACH_SEND_MSG, my_message.head.msgh_size,
0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL );
but I suspect it didn't work!!!
I put the sample source code I was preparing as an attachment; I
will continue trying by mi own, but
some help will help me very much!
Thanks!!
/*
* Mach IPC "hello, world!"
*/
#include <mach.h>
#include <stdio.h>
int main( void )
{
mach_port_t my_port;
kern_return_t error;
mach_msg_return_t msg_return_code;
struct simple_message
{
mach_msg_header_t head;
mach_msg_type_t type;
int inline_data;
};
struct simple_message my_message;
struct simple_message rcv_message;
error = mach_port_allocate( mach_task_self(), MACH_PORT_RIGHT_RECEIVE,
&my_port );
/* ejem!, I don't make comprobations in this case */
printf( "The port %d was created\n", my_port );
/* Header of the message : */
my_message.head.msgh_size = sizeof(struct simple_message);
/* my_message.head.msgh_local_port = mach_task_self(); */
my_message.head.msgh_local_port = MACH_PORT_NULL;
my_message.head.msgh_remote_port = my_port;
/* my_message.head.msgh_id = 0x1234; */
/* Type of the message : */
my_message.type.msgt_name = MACH_MSG_TYPE_INTEGER_32;
my_message.type.msgt_size = 32;
my_message.type.msgt_inline = TRUE;
my_message.type.msgt_longform = FALSE;
/* Data of the message : */
my_message.inline_data = 1;
/* OK, time to send the message : */
msg_return_code = mach_msg( &(my_message.head), MACH_SEND_MSG,
my_message.head.msgh_size,
0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL );
if( msg_return_code != MACH_MSG_SUCCESS ){ /* Here are some errors; let's
study them later */
printf( "Error : could not send the message, %d\n", msg_return_code );
}
else{
printf( "Success : the message was queued\n" );
}
/* header of the received message : */
rcv_message.head.msgh_size = sizeof(struct simple_message);
rcv_message.head.msgh_local_port = my_port;
/* Time to receive the message : */
printf( "\nOf course, if the message was not sended, it's futile to wait
for the message\n" );
msg_return_code = mach_msg( &(rcv_message.head), MACH_RCV_MSG, 0,
rcv_message.head.msgh_size,
my_port, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL
);
printf( "I received the integer %d\n", rcv_message.inline_data );
}
- Trying to understand Mach IPC,
Manu Valderrama <=
- Re: Trying to understand Mach IPC, Manuel Menal, 2002/06/10
- Re: Trying to understand Mach IPC, Manu Valderrama, 2002/06/10
- Message not available
- Re: Trying to.... It's amazing and it works!, Manu Valderrama, 2002/06/10
- Re: Trying to.... It's amazing and it works!, Manuel Menal, 2002/06/11
- Re: Trying to.... It's amazing and it works!, Manu Valderrama, 2002/06/11
- Re: Trying to.... It's amazing and it works!, Thomas Bushnell, BSG, 2002/06/11
- Re: Trying to.... It's amazing and it works!, Manu Valderrama, 2002/06/12
- Message not available
- Re: Trying to.... It's amazing and it works!, Manu Valderrama, 2002/06/12