Solved

Problem with msgsnd (writing to message queue)

Posted on 2004-09-22
6
1,884 Views
Last Modified: 2013-12-26
Hi Experts,

I have a program which reads from an Oracle cursor and after formatting the record, writes to a message queue using the function listed below:

int  WriteMsgQueue(my_msgbuf sBuf)
{
   int rc;
   int buf_length;
   sBuf.mtype = 1;
   buf_length = sizeof(sBuf.mtext);
  /* read from the buffer and write to the message queue */

   /* read from the buffer and write to the message queue */
   rc=(msgsnd(msqid, &sBuf, buf_length, IPC_NOWAIT));

   if (rc == -1)
      perror("msgsnd");
/*  }   */
  return(rc);

My problem is that after successfully sending the first record, I encountered the error message

   "msgsnd :  Invalid parameter"

for each of the next records before the program bombs out.

Please help......

Rgds,
samsul
0
Comment
Question by:sbzainal
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12130862
can you please include the definition of my_msgbuf?
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12130906
>sBuf.mtype = 1;
I think this value is used for message identification and should be unique for each message and should be in range of 0<mtype<MSGMAX

msgsnd specifically points out this error ... extracts from man page -->>>

The mtype field must have a strictly positive integer value that can be used by the receiving process for message selection (see the section about msgrcv).

EINVAL
Invalid msqid value, or nonpositive mtype value, or invalid msgsz value (less than 0 or greater than the system value MSGMAX).

0
 

Author Comment

by:sbzainal
ID: 12131782
Actually, the error reads as "msgsnd: Invalid identifier", my apologies..!! But since I run the program in debug mode and I found that the receiving program reads one record and wait for another process before continuing with reading my message queue (while at same time my program is writing to the queue - making it full, I guess). When I replace the NOWAIT option with zero, my program did not bomb but instead it waits.  Any comments ??

FYi, my program is a client, the receiving program is the middle-guy with a server at the end.

The other program uses the following function to read my queue :

bool hReadMsgQ()
{
 // Read data from MsgQ
 nMsgQBuffLen = msgrcv(nInMsgQNum, &msgQBuff, BUFF_SIZE, 1, 1);

 // No data from MsgQ
 if (nMsgQBuffLen < 0)
   return false;

 // There is data from MsgQ
 return true;

I'm very new to these IP stuff, so please help...!!

Rgds.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 45

Expert Comment

by:sunnycoder
ID: 12131971
>When I replace the NOWAIT option with zero, my program did not bomb but instead it waits.  Any comments ??
Are you aure that your error message is Invalid Identifier and not EAGAIN ?
Print the error number and error message using perror and post it here
0
 

Author Comment

by:sbzainal
ID: 12139425
I was running the program on an HP system running HPUX 11....the error was EINVAL rather than EAGAIN. I subsequently ran the program and got this error "msgsnd: Resources temporarily unavailable" - I seriously think its got somthing to do with the kernel resources for message queues being exhausted.  How do I get the information on kernel message queue limits (the system administrator is either not a friendly person or an uncooperative one) i.e. which commands shall I use ???

Thx
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 150 total points
ID: 12140984
Are you freeing the message queue when you are finished using it? ulimit command is used to check the resource limits
I have provided explanation for both the error messages, try getting rid of IPC_NOWAIT and using a different identifier and report back the results
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 37
Windows Drag & Drop Location 2 94
Path of Workbook 3 59
Making an alias 7 79
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now