询问 msgrcv ,不适用于根据优先级接受消息

asking about msgrcv , does not work for accept messages accourding priority

this is my code and in the last part,msgrecv does not accept the messages from the queue accourding the correct preiority , eg: 10 is most important to accept then type=20 then type=30 ... that is my goal is to accept messages in this manner ... can anyone show me where is the problem? because the acceptance is accoures without priority .. Thanks.. that is the code

     #include <sys/msg.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <stdio.h>
 #include <string.h>
#include "fifo.h"
 typedef struct mymsg {
  long mtype;
  char mtext[100];
  int private;
 }mymsg;

 int main()
 {


  int msqid;
  mymsg msg,buff;
  msqid=msgget(6000,IPC_CREAT|0666);

  if(msqid==-1){
  perror("FAiled to create message queue\n");
  }
  else{
  printf("Message queue id:%u\n",msqid);
  }



 //ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp,int msgflg);
int x=0 ; 
    while(1){
          int privatefifo;
          if(msgrcv(msqid,&buff,sizeof(msg)-sizeof(long),10,/*IPC_NOWAIT*/MSG_NOERROR | IPC_NOWAIT)>-1)
            x=10;
          else if(msgrcv(msqid,&buff,sizeof(msg)-sizeof(long),20,/*IPC_NOWAIT*/MSG_NOERROR | IPC_NOWAIT)>-1)
            x=20;
          else if(msgrcv(msqid,&buff,sizeof(msg)-sizeof(long),30,/*IPC_NOWAIT*/MSG_NOERROR | IPC_NOWAIT)>-1)
            x=30;




          printf("The message received is: %s , , from %d\n",buff.mtext,x);
        strcpy(msg.mtext,"i replay you");
             msg.mtype=buff.mtype;

        if(msgsnd(buff.private,&msg,sizeof(msg)-sizeof(long),0)==-1){
            perror("msgsnd failed:");
          }
          else{
           printf("Message sent successfully\n");
          }


}
 }

我修复了它,只是我必须在 x 的值上放置一个条件,以确保满足 3 个条件之一或其中 none 个条件。.