2014-05-18 3 views
0

예를 들어 메시지 큐의 "msgrcv"함수에서 MSG_EXCEPT 플래그를 사용하는 방법을 알려줄 수 있습니까?메시지 큐의 MSG_EXCEPT 플래그에 대한 쿼리

나는 그것을하려고하지만 나는 다음과 같은 오류를 줄 것이다 : MSG_EXCEPT 선언하지 않음 "msgrcv"함수에 대한 모든 헤더 파일을 입력했다.

샘플 코드로 해결 방법을 알려주십시오.

수신 측 샘플 코드를 업로드 중입니다.

Receiver.c 

#include <stdio.h> 
#include <sys/msg.h> 
#include <error.h> 
#include <strings.h> 
#include <mqueue.h> 
#include <sys/ipc.h> 
#include <sys/types.h> 

int main() 
{ 
    int msqid; 

    struct message 
    { 
    long type; 
    char text[20]; 
    } msg; 

    struct msqid_ds buf; 

    int msgtype = 3; 
    int num_messages; 
    int count; 
    int key = 1234; 

    msqid = msgget(key,0644); 

    count = msgctl(msqid,IPC_STAT,&buf); 
    num_messages = buf.msg_qnum; 

    printf("Number of messages = %d\n",num_messages); 
    if (msgrcv(msqid, (void *) &msg, sizeof(msg.text),4, MSG_EXCEPT | MSG_NOERROR | IPC_NOWAIT)==-1) 
    { 
    perror("msgrcv");   
    } 

    if(num_messages==0) 
    { 
     printf("Queue is empty\n"); 
    } 
    else 
    {  
    printf("%s \n", msg.text); 
    } 

    return 0; 
} 

답변

0

MSG_EXCEPT의 문제는 그것이 _GNU_SOURCE가 정의 필요가 있다는 점에서 가난하게 문서화 기능에 의존한다는 것이다.

gcc -D_GNU_SOURCE <and all your usual compiler switches> Receiver.c으로 컴파일하면 문제가 해결 될 것입니다.

자세한 내용은 MSG_EXCEPT not defined을 참조하십시오.

관련 문제