lundi 29 juin 2020

Trying to Write a Basic Test for QNX Functions MsgReceive(), MsgSend(), and MsgReply()

I am attempting to write a simple test case exercising MsgReceive(), MsgSend(), and MsgReply() but I feel like I am fundamentally misunderstanding how these functions work. Here is my attempt:

printf("Testing MsgReceive()...\n");
printf("Receives message and place it into a buffer.\n");
chid = ChannelCreate(_NTO_CHF_SENDER_LEN);
if(chid == -1){
    printf("ChannelCreate FAILED!");
}
coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0);
pid = fork();
if(pid == -1){
    return;
}
            
if(pid == 0){
    msgSend = MsgSend(coid, writemsg, 13, buffer, 13);
    if(msgSend == -1){
        printf("Child FAILED: %d\n", msgSend);
    }
}
else{
    msgRec = MsgReceive(chid, buffer, 13, NULL);
    printf("Sent Message: %s\n", buffer);
    if(msgRec == -1){
        printf("Parent FAILED: %d\n", msgRec);
    }
}
if(pid == 0){
    if(ChannelDestroy(chid) == -1){
        printf("ChannelDestroy() failed.\n");
    }
}

I create a channel and then connect the process to the channel. I fork and have the child send the message and the parent receive it. But I can never get the child to send. It always fails.

Aucun commentaire:

Enregistrer un commentaire