Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7680711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:10:40+00:00 2026-05-31T18:10:40+00:00

After calling msgrcv(), I got a E2BIG: on SunOS, CPP compiler. Output is as

  • 0

After calling msgrcv(), I got a E2BIG: on SunOS, CPP compiler.

Output is as following:

arguments:
MsgID: 335006
pointer: 0xffbfbac8
sizeof: 1040
MsgType: 0
MsgFlag: 2048
RetVal=-1
RM: message waiting failed with error 7.

In manual:

ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);

Maunal says for msgrcv(), E2BIG is got when “message text length is greater than msgsz and MSG_NOERROR isn’t specified in msgflg.”

But in my case, it looks liks the length is equal to msg text. By the way, how this function get the length of void *msgp? It is a void.

Sorry, I posted a long piece of codes since I am afraid to miss something.
Thanks.

EDIT:
Manual says,

The msgp argument is a pointer to caller-defined structure of the  fol-
       lowing 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

I add more information by gdb as following:
227 RetVal = msgrcv( TDM_M[MyModule].msg_id,
228 (void *)&SysMsg,
229 (size_t)sizeof(T_MSGBUF),
230 MsgType,
231 MsgFlag);
23
235 */
(gdb) p sizeof(SysMsg)
$10 = 1044
(gdb) p sizeof(T_MSGBUF)
$11 = 1040

Length – Destination’s size = 4 (= size of long int), looks like it is correct.
In addition, I found the problem only happens to SunOS. The same code works fine on Linux.

Edit I found the root cause. Like the errno E2BIG indicating MsgLength is less than the message received, my send macro count a wrong value which was supposed to be equal to the MsgLength in WAIT_MSG().

Thank you for your advice and answers.

.h file
/* MSGBUF is defined for specific message
* SysMsg is defined as arg for msgrcv
*/

#define MSGBUF_SIZE     1040
#define MSGBODY_SIZE    (MSGBUF_SIZE)
#define MSGBODY_SIZE1   (MSGBUF_SIZE-16)

typedef struct {

   unsigned char        SrcModule;
   unsigned char        DstModule;
   unsigned char        MsgType;       

   unsigned short       SubMsgId;
   unsigned short       Length;
   long int             reserved;
} MsgHeader;

typedef struct _MsgBody {
   unsigned char Data[MSGBODY_SIZE1];
} MSGBODY;

typedef struct _MsgBuf {
   MsgHeader Header;             // the header of message.
   MSGBODY   Body;                   // the message body.
} MSGBUF;

typedef struct _MsgInside {
    long int        MsgType;
    MSGBUF          MsgText;
} SYS_MSG;

.cpp

int WaitMsg (DMMODULE        MyModule,
                MSGBUF*       pMsgBuf,
                long            MsgType,
                int             MsgFlag,
                TIME_USEC       abs_timeout)
{
   SYS_MSG      SysMsg;
   int          RetVal;

   ...

    memset(&SysMsg, 0, sizeof(SYS_MSG));


        printf("arguments:\n");
        printf("MsgID: %d\n", Module[MyModule].msg_id);
        printf("pointer: 0x%x\n", (void *)&SysMsg);
        printf("sizeof: %d\n",  (size_t)sizeof(T_MSGBUF));

         printf("MsgType: %d\n", MsgType);
        printf("MsgFlag: %d\n", MsgFlag);

    /* Module is a global array in which msg_id is storing */
    RetVal = msgrcv( Module [MyModule].msg_id,
                     (void *)&SysMsg,
                     (size_t)sizeof(MSGBUF),
                     MsgType,
                     MsgFlag);

    /* So far, only ENOMSG is handled, the rest is ignored,
     * Maybe a signal handler is needed later.
     */
    if( RetVal == -1 )
    {
        switch (errno)
        {
        case ENOMSG:
            return My_ENOMSG;

        case E2BIG:
        case EACCES:
        case EAGAIN:
        case EFAULT:
        case EIDRM:
        case EINTR:
        case EINVAL:

/* Here is where the error reported */

            printf("%s: message waiting failed with error %d.\n",
                     Module[MyModule].name, errno);
            printf("%s: \n", strerror(errno));

            return FAIL;

      default:

            printf("%s: message waiting failed with error %d.\n",
                     Module[MyModule].name, errno);
            printf("%s: \n", strerror(errno));

            return FAIL;
        }
    }

    memcpy(pMsgBuf, &(SysMsg.MsgText), sizeof(T_MSGBUF));


    printf("message is received by %s.\n",  Module[MyModule].name);


    return SUCC;

}

...
#define WAIT_MSG(MyModule,pMsgBuf,time_us )             \
        WaitMsg((MyModule),(pMsgBuf),0,IPC_NOWAIT,0)

int main()
{
   int rc = -1;
   MSGBUF    msgbuf; 

   rc = WAIT_MSG( RM, &msgbuf, 0 );
    ...
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:10:42+00:00Added an answer on May 31, 2026 at 6:10 pm

    The error E2BIG indicates that the message you are trying to receive doesn’t fit in your buffer. You have to make the buffer bigger. Your buffer is around 1020 or 1024 bytes, I’m not sure. If the incoming message is bigger, you get E2BIG.

    By the way, how this function get the length of void *msgp? It is a void.

    It seems like you are a little unclear on how pointers work. Pointers just point to a single location in memory, they don’t have lengths. (Even non-void pointers don’t have a “length”.) Whenever you specify a region of memory, you have to specify both its starting location (void *) and its length (size_t). When you pass a range of memory to a function in C, the length is typically specified in one of three ways:

    1. The length is fixed. For example, when you call setjmp, you pass a pointer to a region of memory which is sizeof(jmp_buf) bytes long.
    2. The length is passed as a separate argument. For example, fwrite or msgrcv.
    3. The length is discovered using a sentinel. For example, strlen.

    Advice:

    1. If you need to pass a pointer as void *, don’t use a cast; this can hide a bug in your code if you accidentally cast a non-pointer to void *. Pointers are automatically cast to void * when necessary.
    2. The result of sizeof is always size_t, don’t cast it. It’s like writing (int)1, (double)0.5, or (const char [6])"Hello".
    3. Don’t use sizeof(type) for memcpy or msgrcv arguments. Typos in memcpy arguments are a common source of errors, and referring to distant types makes them harder to spot when reading code.

      // Not so good
      // Reading the code, I have to look for the definition of pMsgBuf
      // in order to know if sizeof(T_MSGBUF) is correct
      memcpy(pMsgBuf, &(SysMsg.MsgText), sizeof(T_MSGBUF));
      // Who knows if sizeof(MSGBUF) is correct?
      msgrcv(..., &SysMsg, sizeof(MSGBUF), ...);
      
      // Better
      // Reading the code, I know sizeof(*pMsgBuf) is correct,
      // but &(SysMsg.MsgText) might be a different type.
      memcpy(pMsgBuf, &(SysMsg.MsgText), sizeof(*pMsgBuf));
      msgrcv(..., &SysMsg, sizeof(SysMsg), ...);
      
      // Best
      // Most errors will be caught by the compiler.
      static void msgbuf_copy(MSGBUF *dest, const MSGBUF *src)
      { memcpy(dest, src, sizeof(*dest)); }
      
      msgbuf_copy(pMsgBuf, &SysMsg.MsgText);
      
    4. If you want your messages to be 1024 bytes, write that in the code. Don’t assemble a structure that just happens to add up to 1024 bytes, make it happen explicitly.

      typedef struct {
         unsigned char        SrcModule;
         unsigned char        DstModule;
         unsigned char        MsgType;       
      
         unsigned short       SubMsgId;
         unsigned short       Length;
         long int             reserved;
      } MsgHeader;
      
      typedef struct {
         MsgHeader Header;
         char Body[1024 - sizeof(MsgHeader)];
      } MSGBUF;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it safe to immediately initialize a Qt4 pointer after calling deleteLater() ? I.e.
WPF, Browserlike app. I got one page containing a ListView. After calling a PageFunction
In the following code, the issue is that after calling method .find_name on an
i receive this exception after calling the following method. And it only comes when
A struct like the following works fine, I can use t after calling malloc(sizeof(mystruct))
After calling notifydatasetchanged(); I want to scroll to the bottom of list so that
After calling to a com component procedure , an error raised OLE error C0000094.
Is it possible somehow to close StreamReader after calling ReadToEnd method in construction like
I would like to know if after calling functions the data I have in
I'm interacting with the Magento API and after calling: $result = $soap->call( $session_id, 'catalog_product.list'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.