IPC 를 위해 MessageQueue 를 사용해야 했다.

그런데 문제는 msgsnd 시스템 함수를 통해 데이터를 보낼려고 하는데 자꾸 에러가 나는것..

[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,232]<ERR>Queue Create Failed. Queue Already Created. Id[4653059]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,217]<ERR>Queue Create Failed. Invalid Queue Key[-1]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,217]<ERR>Queue Create Failed. Invalid Queue Key[1215752192]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,224]<ERR>Queue Create Failed. Invalid Queue Size!! Size[1215752192]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,283][3]<INF>Queue Create Success!! Input Key[494949], Size[10000] => Created Key[494949], Id[4685827], Size[10000]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,283][3]<INF>Queue Create Success!! Input Key[494949], Size[10000] => Created Key[494949], Id[4718595], Size[10000]
[22:17:29.537][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,84][3]<INF>Queue Write. Id[4718595],Type[0],Buf[THIS IS TEST],Size[5]
[22:17:29.538][/home/jonathan/workspace/19.Projects/CUTE/source/nxlib/common/queue.c,195][1]<WriteQueue>msgsnd error:-1, 22(Invalid argument)
[22:17:29.538][/home/jonathan/workspace/19.Projects/CUTE/source/nxlib/common/queue.c,196][1]<WriteQueue>Info Id[4718595], Type[0], Data[THIS ], Len[5], Ret[-1]
[22:17:29.538][/home/jonathan/workspace/19.Projects/CUTE/source/oxdsagent/queuectl.cpp,88]<ERR>Queue Write Failed!

로그 내용이다.. 문제가 생기는 부분은 마지막 부분의 <WriteQueue>msgsnd error:-1, 22(Invalid argument) 부분.

전혀 문제가 발생할 부분이 없는데 문제가 발생해서 한참을 헤매다가 겨우답을 찾았다.

 

msgsnd 의 맨페이지에서 답을 찾을 수 있었다.

DESCRIPTION
The  msgsnd()  and  msgrcv() system calls are used, respectively, to send messages to, and receive messages from, a message queue.  The calling process must have write permission on the
message queue in order to send a message, and read permission to receive a message.

The msgp argument is a pointer to caller-defined structure of the following general form:

struct msgbuf {
long mtype;       /* message type, must be > 0 */
char mtext[1];    /* message data */
};

The mtext field is an array (or other structure) whose size is specified by msgsz, a nonnegative integer value.  Messages of zero length (i.e., no mtext field) are permitted.  The mtype
field must have a strictly positive integer value.  This value can be used by the receiving process for message selection (see the description of msgrcv() below).

문제는 메시지 큐 타입을 ‘0’으로 하고 msgsnd를 호출 했던 것…

맨페이지에 명확하게 적혀 있었다.”/* message type, must be > 0 */” …. 아..;;

 

큐 타입을 1로 하고 호출하자 정상 작동 되었다.

1 Comment on 메시지 큐 타입 관련.. msgsnd

  1. pastanerd says:

    훌륭한 글입니다. 도와주셔서 감사합니다..

Leave a Reply to pastanerd Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.