Reading from a message queue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ramon

    Reading from a message queue

    Hi,

    I'm currently writing a program that tries to read (from a message
    queue) either a message of type 123 or a one of type 111.

    I've tried the following code but it seems that it is not working:


    // reads from the message queue
    if ( msgrcv(qid, &mesg, sizeof(mesg), 123 || 111, 1) < 0 )
    /** error occurs and halt **/

    if (mesg.mtype == 123) {
    ....
    }

    else {
    ....
    }


    Is there a way to write a code that can read either a message from the
    message queue of type A or a one of type B /without/ busy waiting??

    Thankx


    cc: comp.unix.progr ammer
  • Morris Dovey

    #2
    Re: Reading from a message queue

    Ramon wrote:
    I'm currently writing a program that tries to read (from a message
    queue) either a message of type 123 or a one of type 111.
    >
    I've tried the following code but it seems that it is not working:
    if ( msgrcv(qid, &mesg, sizeof(mesg), 123 || 111, 1) < 0 )
    msgrcv() is a *nix extension. You'll have better luck asking on
    cc: comp.unix.progr ammer
    --
    Morris Dovey
    DeSoto Solar
    DeSoto, Iowa USA

    Comment

    • Ben Bacarisse

      #3
      Re: Reading from a message queue

      Ramon <ramif_47@yahoo .co.ukwrites:
      I'm currently writing a program that tries to read (from a message
      queue) either a message of type 123 or a one of type 111.
      >
      I've tried the following code but it seems that it is not working:
      >
      // reads from the message queue
      if ( msgrcv(qid, &mesg, sizeof(mesg), 123 || 111, 1) < 0 )
      The C part of the answer is that writing 123 || 11 there is just like
      writing 1 (the way C represents "true") because || is a logical (and
      not a bitwise) or operation.
      Is there a way to write a code that can read either a message from the
      message queue of type A or a one of type B /without/ busy waiting??
      >
      cc: comp.unix.progr ammer
      And there you'll the that other part of the answer (which is "no, not
      in general").

      --
      Ben.

      Comment

      Working...