我不知道为什么我得到错误Message too long at mq_receive
。我查看了所有与我的问题类似的帖子,我尝试了他们所说的话,但仍无法解决问题。有人能帮助我吗?mq_receive的留言太长了
#include <stdio.h>
int main(int argc, char **argv) {
struct peticion pet;
struct respuesta res;
struct mq_attr attr1;
attr1.mq_msgsize = sizeof(pet);
attr1.mq_maxmsg = 10;
mqd_t cS = mq_open("/servidor", O_CREAT | O_RDONLY, 0700, attr1);
if (cS == -1) {
printf("ERROR: No se ha podido abrir la cola del servidor\n");
exit(-1);
}
while (1) {
if (mq_receive(cS, (char*)&pet, sizeof(pet), 0) == -1) {
printf("ERROR: El servidor no ha sido capaz de recibir peticiones\n");
exit(-1);
}
switch (pet.cod) {
case 0:
init(pet.colaCliente);
break;
case 1:
introducirPar(pet.key, pet.value, pet.colaCliente);
break;
case 2:
obtenerValor(pet.key, pet.colaCliente);
break;
case 3:
borrarPar(pet.key, pet.colaCliente);
break;
}
}
mq_close(cS);
mq_unlink((const char*)&cS);
return 0;
}
好抓!你应该编译更多的警告:'gcc -Wall -Wextra'或'clang -Weverything'。 – chqrlie