[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
client-server-IPC
From: |
Frank Saar |
Subject: |
client-server-IPC |
Date: |
Mon, 2 Dec 2002 18:22:33 -0800 |
Hello,
I am trying to get used to the hurdish way of programming. So I started
programming some samples that should help me understanding the hurdish way
of thinking. But I encountered some problems.
I wanted to write a simple client/server program (similar to the one found
in the programmers guide to the mach user environment) and I implemented it
the following way:
<-------------------mig definition------------------------------->
subsystem test 500;
routine get_random(
server: mach_port_t;
out num: int);
<---------------------------------------client-------------------->
int main() {
int r=3;
error_t err;
mach_port_t server;
server=file_name_lookup("/servers/testserver",0,0);
if (server==MACH_PORT_NULL) {
error(1,errno,"Couldnt open server port\n");
}
err=get_random(server,&r);
if (err<0) {
error(1,errno,"get_random failed %d\n",err);
}
mach_port_deallocate(mach_task_self(),server);
return (0);
}
<---------------------------------------server-------------------->
kern_return_t get_random ( mach_port_t server, int *num )
{
db=*num;
printf("in get_random:%d\n",db);
return KERN_SUCCESS;
}
int main (int argc, char **argv)
{
error_t err;
mach_port_t bootstrap;
struct port_bucket *test_bucket;
struct port_class *test_portclass;
struct port_info *pi;
test_bucket = ports_create_bucket ();
test_portclass = ports_create_class (0, 0);
err = ports_create_port (test_portclass, test_bucket,
sizeof(*pi),&pi );
if (err<0) {
error (1, 0, "Couldnt create port:%d\n",err);
}
ports_manage_port_operations_multithread (pi->bucket, test_server,
0,0,0);
return 0;
}
--------------------------------------------------------------------------
But when I copy the server to /servers/testserver and run the client I get
get_random_failed -303 as error. As I understand it the filesystem makes a
server available to its clients. So the client should get the server port
via file_name_lookup. Since the server already exists and I dont want to
write or read from it I pass 0x00 as 2nd and 3rd parameter to
file_name_lookup. Since the client doesnt exit in the following 'if' I think
that I received a valid handle. Then the client is called and should pass
the request over to the server. But nothing happens.
I mean its quite clear that the server must be running. So I started it
before the client as a background process. So where´s problem ? In my
opinion the client wasnt able to contact the server. But why ? The client
got a valid port handle. I also thought that perhaps the port handle
received via file_name_lookup wasnt the right porthandle and added a
err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_SEND,&port);
in the client code and called the getrandom() with port instead of server
but this didnt help.
Whats wrong ? Isnt the way I started the server not the hurdish way or is it
the way I try to get a valid porthandle of the servers port ?
Does anyone know what went wrong ?
thanks in advance,
Frank
- client-server-IPC,
Frank Saar <=