IPC - name_close() issue - Resending Previous Message

I am using MsgSend/MsgReceive/MsgReply to communicate between two process along with name_attach/name_open/name_close. Mainly this is working however when I make the call to name_close() it resends the message it has just sent with MsgSend(). I receive no error from any of the APIs. Can someone advise what is going wrong?

Server Code

[code] if ((attach = name_attach(NULL, ATTACH_POINT, 0)) == NULL) {
fprintf(stderr, “%s: (server) couldn’t create a channel: %s\n”, progname, strerror(errno));
exit(EXIT_FAILURE);
}

while(1){
    rcvid = MsgReceive(attach->chid, &msg, sizeof(msg), NULL);
    fprintf(stderr, "%s: (server) msg = '%d'\n", progname, msg.command);
    switch (msg.command)
    {
    case CASE1:
        do stuff
        break;           
    }
    MsgReply(rcvid, 0, &reply, sizeof(reply));
}  [/code]

Client code

[code]

if ((fd = name_open(ATTACH_POINT, 0)) == -1) {
return EXIT_FAILURE;
}

msg.command = command;

ret = MsgSend(fd, &msg, sizeof(msg), &reply, sizeof(reply));
if (ret != -1) {
    fprintf(stderr, "%d - MsgSend got reply: %d\n", command, reply.result);
} else {
    fprintf(stderr, "%d - MsgSend failed, errno is %d, '%s'\n", command, errno, strerror(errno));
}

if (name_close(fd) == -1){
    fprintf(stderr, " %d - name_close failed, errno is %d, '%s'\n", command, errno, strerror(errno));
    return EXIT_FAILURE;

}

return EXIT_SUCCESS;[/code]

Is this real code? I’m surprise it works.

Read the name_attach documentation and all your question shall be answered.

Yes it did actually work, I’m surprised it worked now as well :unamused:.I think the fact that it did got me much further than I should of got!

All working now, the extra message will be _PULSE_CODE_DISCONNECT!

Thanks

A pulse is not a message - but pulses are received by MsgReceive(). You should always check for them!

Another “gotcha” is assigning your message numbers lower 512 (reserved for system use).