home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.wizards,bnr.sys.sun
- Path: sparky!uunet!cs.utexas.edu!torn!cunews!nrcnet0!bnrgate!bcrka451!norm
- From: norm@bnr.ca (Norm MacNeil)
- Subject: HELP: MsgQueue not "reading"?
- Message-ID: <1992Aug27.211637.14089@bcrka451.bnr.ca>
- Originator: norm@bcrks122
- Sender: 5E00 Corkstown News Server
- Reply-To: norm@bnr.ca
- Organization: Bell-Northern Research Ltd.
- Date: Thu, 27 Aug 1992 21:16:37 GMT
- Lines: 79
-
-
- A small test to check message queues is as follows:
- 1) program "msgd" loops and checks the message queue every 10 seconds and loop max
- 4 times - simply reads the queue
- 2) program "sendmsg" reads input and places string on the queue
-
- "msgd" starts and runs fine, but when I run sendmsg, I get:
-
- msgsnd: Invalid argument
-
- but I can't figure out what is wrong.
-
- -- sendmsg.c:
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- extern int errno;
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int Key, MsgQID, MsgFlag, MsgSize = 1024, I, MsgRet, Len;
- struct msgbuf *MsgP;
- char Buffer[1025];
-
- if ((MsgQID = msgget(101, (0600))) == -1) {
- perror("msgget()");
- printf("Unable to grab message queue.\n");
- exit(1);
- }
- else {
- printf("Message Queue %d accessed.\n", MsgQID);
- if ((MsgP = (struct msgbuf *) malloc(sizeof(struct msgbuf) + MsgSize))
- == NULL) {
- perror("malloc");
- printf("Unable to allocate memory for Msg Buffer\n");
- exit(1);
- };
- printf("Enter message for queue: ");
- gets(Buffer);
- Len = strlen(Buffer);
- for(I=0;I<Len;I++)
- MsgP->mtext[I] = Buffer[I];
-
- printf("Sending message (");
- for(I=0;I<Len; I++)
- printf("%c", MsgP->mtext[I]);
- printf(")\n");
- printf("About to call msgsnd(%d, %d, %d, %d)\n", MsgQID, MsgP, Len,
- IPC_NOWAIT);
- if ((MsgRet = msgsnd(MsgQID, MsgP, Len, IPC_NOWAIT | 0 )) == -1) {
- printf("errno is %d\n", errno);
- perror("msgsnd");
- printf("Unable to send message to queue.\n");
- exit(1);
- }
- else {
- printf("MsgOp: received ID: %d\n", MsgRet);
- };
-
- };
- printf("Exiting Message Sender.\n");
-
- };
-
- -- end of sendmsg.c
-
- Any ideas? BTW, the msgd.c is standard create the queue (IPC_CREAT|IPC_EXCL|
- 0600).
-
- Thanks,
- Norm.
- --
- +-----------------------------------------------------------------------+
- Norm MacNeil Phone: (613) 763-7497
- CAD Operation Tools Development Fax: (613) 763-3317
- Bell-Northern Research Ltd. EMail: norm@bnr.ca.BITNET (INTERNET)
- #include <disclaimer.std> "Roller bladers do it in-line!"
-