home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / wizards / 3718 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.5 KB  |  92 lines

  1. Newsgroups: comp.unix.wizards,bnr.sys.sun
  2. Path: sparky!uunet!cs.utexas.edu!torn!cunews!nrcnet0!bnrgate!bcrka451!norm
  3. From: norm@bnr.ca (Norm MacNeil)
  4. Subject: HELP: MsgQueue not "reading"?
  5. Message-ID: <1992Aug27.211637.14089@bcrka451.bnr.ca>
  6. Originator: norm@bcrks122
  7. Sender: 5E00 Corkstown News Server
  8. Reply-To: norm@bnr.ca
  9. Organization: Bell-Northern Research Ltd.
  10. Date: Thu, 27 Aug 1992 21:16:37 GMT
  11. Lines: 79
  12.  
  13.  
  14. A small test to check message queues is as follows:
  15. 1) program "msgd" loops and checks the message queue every 10 seconds and loop max
  16.    4 times - simply reads the queue
  17. 2) program "sendmsg" reads input and places string on the queue
  18.  
  19. "msgd" starts and runs fine, but when I run sendmsg, I get:
  20.  
  21. msgsnd: Invalid argument
  22.  
  23. but I can't figure out what is wrong.
  24.  
  25. -- sendmsg.c:
  26. #include <stdio.h>
  27. #include <sys/types.h>
  28. #include <sys/ipc.h>
  29. #include <sys/msg.h>
  30. extern int errno;
  31. main(argc, argv)
  32.   int argc;
  33.   char *argv[];
  34. {
  35.   int Key, MsgQID, MsgFlag, MsgSize = 1024, I, MsgRet, Len;
  36.   struct msgbuf *MsgP;
  37.   char Buffer[1025];
  38.  
  39.   if ((MsgQID = msgget(101, (0600))) == -1) {
  40.     perror("msgget()");
  41.     printf("Unable to grab message queue.\n");
  42.     exit(1);
  43.   }
  44.   else {
  45.     printf("Message Queue %d accessed.\n", MsgQID);
  46.     if ((MsgP = (struct msgbuf *) malloc(sizeof(struct msgbuf) + MsgSize))
  47.      == NULL) {
  48.       perror("malloc");
  49.       printf("Unable to allocate memory for Msg Buffer\n");
  50.       exit(1);
  51.     };
  52.     printf("Enter message for queue: ");
  53.     gets(Buffer);
  54.     Len = strlen(Buffer);
  55.     for(I=0;I<Len;I++)
  56.       MsgP->mtext[I] = Buffer[I];
  57.  
  58.     printf("Sending message (");
  59.     for(I=0;I<Len; I++)
  60.       printf("%c", MsgP->mtext[I]);
  61.     printf(")\n");
  62.     printf("About to call msgsnd(%d, %d, %d, %d)\n", MsgQID, MsgP, Len,
  63.       IPC_NOWAIT);
  64.     if ((MsgRet = msgsnd(MsgQID, MsgP, Len, IPC_NOWAIT | 0 )) == -1) {
  65.       printf("errno is %d\n", errno);
  66.       perror("msgsnd");
  67.       printf("Unable to send message to queue.\n");
  68.       exit(1);
  69.     }
  70.     else {
  71.       printf("MsgOp: received ID: %d\n", MsgRet);
  72.     };
  73.  
  74.   };
  75.   printf("Exiting Message Sender.\n");
  76.  
  77. };
  78.  
  79. -- end of sendmsg.c
  80.  
  81. Any ideas?  BTW, the msgd.c is standard create the queue (IPC_CREAT|IPC_EXCL|
  82. 0600).
  83.  
  84. Thanks,
  85.   Norm.
  86. -- 
  87. +-----------------------------------------------------------------------+
  88.  Norm MacNeil                     Phone: (613) 763-7497
  89.  CAD Operation Tools Development    Fax: (613) 763-3317
  90.  Bell-Northern Research Ltd.      EMail: norm@bnr.ca.BITNET (INTERNET)
  91.  #include <disclaimer.std>       "Roller bladers do it in-line!"
  92.