About rereading a message

Hi,
I’m writing a multi-threaded resource manager and, I’m asking a question
about rereading a message.

In an io_msg() function like the following one, I’m not sure I can call
resmgr_msgread() at the beginning of the function instead of calling it
inside the default case where I’m sure I received a message.
Same for the call to MsgInfo().


int io_msg(resmgr_context_t *ctp, io_msg_t *msg, RESMGR_OCB_T *ocb)
{
header_t header;

MsgInfo(ctp->rcvid, &msg_info); // necessary to know who eventually
wants to lock a record

/* go get the message again to get the textlen information */
resmgr_msgread(ctp, &header, sizeof(header), 0);

switch (ctp->rcvid) {
case -1 : /* receive error /
return_value = EFAULT;
break;
case 0 : /
we’ve got a pulse */
break;

default: /* we’ve received a message */

// process it
break;
}
}

Thanks,
Alain.

Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:

Hi,
I’m writing a multi-threaded resource manager and, I’m asking a question
about rereading a message.

In an io_msg() function like the following one, I’m not sure I can call
resmgr_msgread() at the beginning of the function instead of calling it
inside the default case where I’m sure I received a message.
Same for the call to MsgInfo().

I’m not sure what your question is here (and how it relates to
multi-threading) … but let me guess, if I’m wrong then you can
post a follow up with a question =;-)

The client is blocked on the resource manger, so you can call
MsgInfo as many times as you want. Now if it was a pulse that
was received then you wouldn’t be in this handler in the first
place (pulses don’t come into the io_msg handler and neither
do invalid rcvid’s (ie -1)). The same is true of resmgr_msgread().

You are also guaranteed to have at least the first 16 bytes of
the message read so you can switch on the “type” of message before
you do the read.

Thomas

int io_msg(resmgr_context_t *ctp, io_msg_t *msg, RESMGR_OCB_T *ocb)
{
header_t header;

MsgInfo(ctp->rcvid, &msg_info); // necessary to know who eventually
wants to lock a record

/* go get the message again to get the textlen information */
resmgr_msgread(ctp, &header, sizeof(header), 0);

switch (ctp->rcvid) {
case -1 : /* receive error /
return_value = EFAULT;
break;
case 0 : /
we’ve got a pulse */
break;

default: /* we’ve received a message */

// process it
break;
}
}

Thanks,
Alain.