Bonjour,

J'ai un problème avec l'utilisation de la fonction msgsnd.

Lors de l'execution de mon programme, j'obtiens un jolie :
msgsnd : Invalid Argugment

Je me suis rendu compte que l'erreur vient de la taille passée en paramètre, en effet en remplacent sizeof(struct Msg_reponse)-sizeof(long) par un entier assez grand, je n'ai plus le problème.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
void envoyerReponse(int msgid,struct Msg_reponse* message){
	if(msgsnd(msgid, message, sizeof(struct Msg_reponse)-sizeof(long),0) == -1){
		perror("msgsnd");
		exit(1);
	}
}
Les structures utilisées :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
typedef union
{
	Liste_Clients liste_clients;
	Liste_Webcams liste_webcams;
	Ack ack;
}Reponse;
 
 
typedef struct{
	char opt;
	Reponse reponse;
}Reponse_option;
 
struct Msg_reponse{
	long type;
	Reponse_option reponse_option;
};
Selon man msgsnd :
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 non-negative integer value.
Dans mon cas, mtext est un Reponse_option donc un Reponse_option a bien la taille d'un struct Msg_reponse - la taille d'un long.

De plus, si je remplace :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
sizeof(struct Msg_reponse)-sizeof(long)
par :
, j'obtiens le même message d'erreur ...



Quelqu'un peut t-il m'éclairer ?

Merci d'avance.