L
Ludwig Moser
i got a struct like that:
/* msg uses msgtype, and the data that is transferred */
struct Msg {
long msgType; /* 0 or 1*/
char msgData[SIZE];
};
and i try to send it with msgsnd
so i wrote a fkt to send the msg into my messagequeue:
void send( int lineNumber, long msgTyp ) {
struct Msg msg;
int msgID = -1;
msg.msgType = msgTyp;
sprintf(msg.msgData,"%d\n", lineNumber);
printf("\nmsgData: %s", msg.msgData);
msgID = msgget(msgQueueID, /*IPC_CREAT|*/IPC_EXCL|0666);
if (msgID < 0) {
perror( strerror(errno) );
printf("msgget failed, msgID = %d\n", msgID);
exit(-1);
}
printf("sending msgType %ld\n", msg.msgType);
if (msgsnd(msgID, &msg, SIZE, 0) == -1) {
perror("msgsnd"); /* Fehler */
printf("\nWHY ARE WE HERE? Aliens stole our data! *cry*\n");
exit(-1);
} else {
/* we are done */
printf("Data sent: %s\n", msg.msgData);
exit(0);
}
} // end void send( int lineNumber, long msgTyp )
so, when i run the program
one time i get to "WHY ARE WE HERE?" when msgType=0
and the next time i get OK, when msgType=1
why?
thougt its on my own what type-value i choose?
TIA
Luke
/* msg uses msgtype, and the data that is transferred */
struct Msg {
long msgType; /* 0 or 1*/
char msgData[SIZE];
};
and i try to send it with msgsnd
so i wrote a fkt to send the msg into my messagequeue:
void send( int lineNumber, long msgTyp ) {
struct Msg msg;
int msgID = -1;
msg.msgType = msgTyp;
sprintf(msg.msgData,"%d\n", lineNumber);
printf("\nmsgData: %s", msg.msgData);
msgID = msgget(msgQueueID, /*IPC_CREAT|*/IPC_EXCL|0666);
if (msgID < 0) {
perror( strerror(errno) );
printf("msgget failed, msgID = %d\n", msgID);
exit(-1);
}
printf("sending msgType %ld\n", msg.msgType);
if (msgsnd(msgID, &msg, SIZE, 0) == -1) {
perror("msgsnd"); /* Fehler */
printf("\nWHY ARE WE HERE? Aliens stole our data! *cry*\n");
exit(-1);
} else {
/* we are done */
printf("Data sent: %s\n", msg.msgData);
exit(0);
}
} // end void send( int lineNumber, long msgTyp )
so, when i run the program
one time i get to "WHY ARE WE HERE?" when msgType=0
and the next time i get OK, when msgType=1
why?
thougt its on my own what type-value i choose?
TIA
Luke