Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

Retrieving the Size of the Next Message in a Server-Side Queue

The ctSysQueueMlen() function can be used to obtain the length of the next available message on the server-side queue (system queue). The syntax for ctSysQueueMlen() is:

ctCONV NINT ctDECL ctSysQueueMlen(NINT qhandle,LONG timeout)

Parameter qhandle is a system queue handle returned by a call to ctSysQueueOpen(). Parameter timeout specifies a time in milliseconds that ctSysQueueMlen() will block if the queue is empty. A timeout value of ctWAITFOREVER causes ctSysQueueMlen() to block until data is available in the queue. Use ctSysQueueMlen() to determine the appropriate size of a buffer before calling ctSysQueueRead(). ctSysQueueMlen() returns the length of the next available message, or a negative value on error.

Example

#include <ctreep.h>


int main(void)

{

NINT eRet = 0;

NINT hQueue = -1;

TEXT buffer[256];

NINT isam_init = 0;

NINT len;


/* init ISAM */

eRet = (NINT)INTISAMX(6, 7, 4, 6, 0, "ADMIN", "ADMIN", "FAIRCOMS");

if (eRet != NO_ERROR)

{

printf("INTISAM failed with error %d\n", eRet);

goto Exit;

}

isam_init++;

/* create a new queue */

hQueue = ctSysQueueOpen("MyQueue", 0);

if (hQueue < 0)

{

eRet = -hQueue;

printf("ctSysQueueOpen failed with error %d\n", eRet);

goto Exit;

}

/* write text to a queue using ctSysQueueWrite */

eRet = ctSysQueueWrite(hQueue, "This is the first line", 23);

if (eRet != NO_ERROR)

{

printf("ctSysQueueWrite failed with error %d\n", eRet);

goto Exit;

}

/* retrieve the size of the message in queue */

len = ctSysQueueMlen(hQueue, 100);

if (len < 0)

{

eRet = -len;

printf("ctSysQueueMlen failed with error %d\n", eRet);

goto Exit;

}

printf("Message length is %d\n", len);

/* check the len of the message */

if (len > sizeof(buffer))

{

printf("buffer is not large enough to receive message\n");

goto Exit;

}

eRet = ctSysQueueRead(hQueue, buffer, sizeof(buffer), ctWAITFOREVER);

/* check if read time-out */

if (eRet == NO_ERROR)

printf("Read: %s\n", buffer);

else if (eRet == NTIM_ERR)

printf("ctSysQueueRead time-out\n");

else

printf("ctSysQueueRead failed with error %d\n", eRet);


Exit:

/* close the queue */

if (hQueue >= 0)

{

eRet = ctSysQueueClose(hQueue);

if (eRet != NO_ERROR)

printf("ctSysQueueClose failed with error %d\n", eRet);

}

if (isam_init)

CLISAM();

return (int)eRet;

}

TOCIndex