Hello,
I don't know wether I suffer from a bug or ignorance.
Here is a striped dow version of my code which still hit my problem.
What do I expect it do do?
It shold start a thread as some kind of privat server. But this thread
is unable to do a msg_reply to the main thread.
As you can easy figure all goes well until I send the message OPCODE.
This gets received but the thread will hang in the msg_reply.
Why?
/*
* main.c
* Main handling loop and startup
*/
#include <sys/namer.h>
#include <hash.h>
#include <stdio.h>
#include <sys/fs.h>
#include <fcntl.h>
#include <std.h>
#include <syslog.h>
#define OPCODE 500
static port_t theRootport; /* Port we receive contacts through */
static port_name theWorkPort;
static long theWorkThread;
/*
* new_client
* try to add a new client as supplied
*/
static void
new_client(struct msg *m)
{
msg_accept(m->m_sender);
}
/*
* dup_client
*/
static void
dup_client(struct msg *m)
{
m->m_arg = m->m_arg1 = m->m_buflen = m->m_nseg = 0;
msg_reply(m->m_sender, m);
}
/*
* dead_client()
* Someone has gone away. Free their info.
*/
static void
dead_client(struct msg *m)
{
}
/*
* serve()
* Endless loop to receive and serve requests
*/
static void
serve()
{
int x;
struct msg msg;
loop:
/*
* Receive a message, log an error and then keep going
*/
x = msg_receive(theRootport, &msg);
if (x < 0) {
syslog(LOG_ERR, "msg_receive");
goto loop;
}
/*
* Categorize by basic message operation
*/
/*
* Catch odd cases
*/
printf("\nreceived msg %d from %d",msg.m_op,msg.m_sender);
switch(msg.m_op) {
case M_CONNECT: /* New client accept instead of reply */
new_client(&msg);
break;
case M_DISCONNECT: /* Client done, don't reply*/
dead_client(&msg);
break;
case M_DUP:
dup_client(&msg);
break;
case OPCODE:
msg.m_arg=msg.m_arg1=msg.m_nseg=0;
msg_reply(msg.m_sender,&msg);
printf("replied");
break;
default: /* regular functions */
msg_err(msg.m_sender, EINVAL );
break;
}
goto loop;
}
/*
* work_init()
*
*/
int work_init()
{
/*
* Last check is that we can register with the given name.
*/
theRootport = msg_port((port_name)0, &theWorkPort);
theWorkThread=tfork(serve);
return 0;
}
/*
*
*/
int work_op(port_t p)
{
struct msg m;
m.m_op=OPCODE;
m.m_arg=m.m_arg1=m.m_nseg=0;
m.m_buf=0;
return msg_send(p,&m);
}
port_t work_new()
{
return msg_connect(theWorkPort, ACC_WRITE );
}
void work_die()
{
notify(0, theWorkThread, EKILL);
}
main()
{
struct time t;
port_t c1;
work_init();
c1=work_new();
printf("\ntry the work");
work_op(c1);
printf("\ngot a reply");
sleep(20);
work_die();
exit(0);
}
Thanx for any help
/Joerg
-----------------------------------------------------------------------------
Joerg Wittenberger | email: joerg.wittenberger@inf.tu-dresden.de
Rietzstr. 32b |
01139 Dresden |
Germany | PGP: D4 B2 DA AE C3 02 50 9C 45 3E AD 99 C1 1A 8E F8
WWW: <a href=http://www.inf.tu-dresden.de:~jw6/top.html> (click here) </a>
Received on Sat Jan 7 13:12:12 1995
This archive was generated by hypermail 2.1.8 : Thu Sep 22 2005 - 15:12:11 PDT