我做了一个消息队列,但是当助手向他的客户发送消息时,客户收到错误的号码:-1081388352。这适用于我发送的每个号码。在 msgget 期间甚至在 msgcrv 或 msgsnd 期间都没有错误。发送代码:
key_t chiave_ac = ftok("prenotazione.c", 'M');
if(chiave_ac == -1){
perror("ftock");
exit(EXIT_FAILURE);
}
int coda_ac = msgget(chiave_ac, IPC_CREAT | 0642);
if(coda_ac == -1){
perror("msgget");
exit(EXIT_FAILURE);
}
if (msgsnd(coda_ac, &m, sizeof(messaggio)-sizeof(long), 0) == -1) {
perror("msgsnd");
exit(EXIT_FAILURE);
}
收到:
key_t chiave_ac = ftok("prenotazione.c", 'M');
if(chiave_ac == -1){
printf("Errore nel generare la chiaveAC \n");
perror("ftok");
exit(1);
}
int id_ac = msgget(chiave_ac, 0);
if (id_ac == -1){
perror("msgget ac");
exit(EXIT_FAILURE);
}
if( msgrcv(id_ac, &risp, sizeof(messaggio)-sizeof(long), getpid(), 0) == -1){
printf("errore ricezione \n");
fflush(stdout);
}
我做错了什么?某些标志有错误?
[从评论中添加:]
typedef struct
{
long type;
int pid;
scelta tipo;
int aula;
int giorno;
bool finito;
} messaggio;