Я пытаюсь отправить сообщение "test" с помощью mqueue, но при получении сообщения EMSGSIZE происходит сбой.Код:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <sys/types.h>
#include <sys/wait.h>
#include <mqueue.h>
#include <errno.h>
using namespace std;
int main() {
mqd_t mqdes;
mqdes = mq_open("/mq.12345", O_RDWR | O_CREAT, (S_IRWXU | S_IRWXG | S_IRWXO), NULL);
if (mqdes == -1) {
switch (errno) {
case EACCES:
cout << "EACCESS" << endl;
break;
case EEXIST:
cout << "EEXIST" << endl;
break;
case EINTR:
cout << "EINTR" << endl;
break;
case EINVAL:
cout << "EINVAL" << endl;
break;
case EMFILE:
cout << "EMFILE" << endl;
break;
case ENAMETOOLONG:
cout << "TOOLONG" << endl;
break;
case ENFILE:
cout << "ENFILE" << endl;
break;
case ENOENT:
cout << "ENOENT" << endl;
break;
case ENOSPC:
cout << "ENOSPC" << endl;
break;
}
} else {
cout << "Success" << endl;
}
pid_t pid;
pid = fork();
if (pid > 0) {
// Child process
string serialized = "test";
if (mq_send(mqdes, serialized.c_str(), strlen(serialized.c_str()), 0) != 0){
switch (errno) {
case EAGAIN:
cout << "EAGAIN" << endl;
break;
case EBADF:
cout << "EBADF" << endl;
break;
case EINTR:
cout << "EINTR" << endl;
break;
case EINVAL:
cout << "EINVAL" << endl;
break;
case EMSGSIZE:
cout << "EMSGSIZAE" << endl;
break;
case ENOSYS:
cout << "ENOSYS" << endl;
break;
}
} else {
cout << "Sent" << endl;
}
exit(1);
} else {
// Parent process
}
int status;
while (wait(&status) > 0) {
}
ssize_t size;
char* buf;
cout << mq_receive(mqdes, buf, 8, NULL) << endl;
switch (errno) {
case EAGAIN:
cout << "EAGAIN" << endl;
break;
case EBADF:
cout << "EBADF" << endl;
break;
case EMSGSIZE:
cout << "EMSGSIZAE" << endl;
break;
case EINTR:
cout << "EINTR" << endl;
break;
case ENOSYS:
cout << "ENOSYS" << endl;
break;
}
return 0;
}
При получении он печатает -1 и EMSGSIZE errno.Что не так?
РЕДАКТИРОВАТЬ: я использую Fedora 15