srv_getmsgq

Description

Get the next message from a message queue.

Syntax

CS_RETCODE srv_getmsgq(msgqid, msgp, getflags, infop)
SRV_OBJID    msgqid;
CS_VOID       **msgp;
CS_INT          getflags;
CS_INT         *infop;

Parameters

msgqid

The identifier for the message queue from which to get a message. To reference the message queue by name, call srv_getobjid with the name to yield the message queue ID.

msgp

A pointer to a pointer variable that srv_getmsgq sets to the message’s address.

getflags

The values for getflags can be OR’d together. Table 3-50 lists the legal values for getflags, and their significance:

Table 3-50: Values for getflags (srv_getmsgq)

Value

Significance

SRV_M_WAIT

If no message is available, srv_getmsgq sleeps until a message is delivered.

SRV_M_NOWAIT

srv_getmsgq returns immediately whether a message is available or not.

SRV_M_READ_ONLY

The default behavior of srv_getmsgq is to remove the message from the message list and to wake up any thread that is waiting for the message to be read. If SRV_M_READ_ONLY is set, a message pointer is returned, but the message is not removed from the list and the thread waiting for the message to be read does not wake up. This option can be used to peek at the head of the message queue to see if the message is intended for the thread.

infop

A pointer to a CS_INT. Table 3-51 describes the possible values returned in *infop if srv_getmsgq returns CS_FAIL:

Table 3-51: Values for infop (srv_getmsgq)

Value

Meaning

SRV_I_WOULDWAIT

The SRV_M_NOWAIT flag was set in the getflags field and there are no messages to be read.

SRV_I_DELETED

While waiting for a message, the message queue was deleted.

SRV_I_INTERRUPTED

The SRV_M_WAIT flag was set in the getflags field and this call was interrupted before the message arrived.

SRV_I_UNKNOWN

Some other error occurred. Look in the log file for a message.

Returns

Table 3-52: Return values (srv_getmsgq)

Returns

To indicate

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

Examples

Example 1

#include <ospublic.h>
/*
 ** Local prototype
 */
CS_VOID    ex_srv_getmsgq PROTOTYPE((
SRV_OBJID  msgqid,
CS_INT     *infop
));
/*
 ** EX_SRV_GETMSGQ
**
**    Example routine to get messages from a message queue.
**
** Arguments:
**    msgqid-    The id of the message queue from which to get
 **               the message.
**
**    infop-     Will hold information about why this routine
 **               failed. Comes directly from srv_getmsg.
** Returns:
**    Nothing. If this routine returns, it is because srv_getmsgq
 **    failed. Check infop to see why it failed.
*/
CS_VOID    ex_srv_getmsgq(msgqid, infop)
SRV_OBJID  msgqid;
CS_INT     *infop;
{
     CS_CHAR   *message;   /* This message is a string. */
    /*
     ** Loop processing messages. Go to sleep if no messages are
     ** available.
     */
    while (srv_getmsgq(msgqid, (CS_VOID *)&message, SRV_M_WAIT,
             infop)== CS_SUCCEED)
    {
        /* Process message.*/
    }
    /* infop will contain the reason why it failed. */
    return ;
}

Usage

See also

srv_createmsgq, srv_deletemsgq, srv_getobjid, srv_putmsgq