UCM Unitec Home Page
      

Receive Message

 UcmRecv(F)

Synopsis   Environment   Description   Diagnostics   Globals   Notes   See also   Examples

Synopsis

#include "ucm.h"

int UcmRecv(sock, msgId, msg, msgLen, flag);
T_SOCKET sock;
char *msgId, *msg;
int msgLen, flag;

Environment

Unix, Win32

Description

UcmRecv reads the next available message through the BSD stream type socket sock and places it into the buffer pointed to by msg. The received message is truncated to msgLen bytes if it is larger than msgLen. The truncated part of the message is lost and no indication of the truncation is given to the calling process. By specifying msgLen as -1, the entire message up to the UCM defined limit of UCM_MAX_MSG bytes (see ucm.h) may be received.

One or more (bitwise inclusive OR-operation) of the following modes may be selected in the parameter flag:

UF_NOFLAGS No special processing / normal case.
UF_NOWAIT Normally UcmRecv will suspend execution until the next message comes available or the timeout span specified through UcmCntl has expired. Setting the UF_NOWAITt flag causes UcmRecv to return immediately with a return value of -1 and errno set to ENOMSG if no pending messages exist.
UF_TIMEOUT This flag causes UcmRecv to return with the UE_NOMSG error when the time span set with the UC_TIMEOUT UcmCntl command has elapsed without receiving any message.

UcmRecv will fail and no message will be received if one or more of the following is true:

UE_NOTINIT The UCM software has not been initialize (see UcmInit)
UE_BADSOCK The value of sock is not a valid socket descriptor or the socket is not open.
UE_INTR The read process has been interrupted by a signal.
UE_NOMSG No message is available and UF_NOWAIT is set or UF_TIMEOUT is set and the timeout span specified via UcmCntl has expired.
UE_CONNECT The socket has been closed.

Diagnostics

Upon successful completion UcmRecv returns a value equal to the number of bytes actually placed into msg. Otherwise, UCM_ERROR is returned and ucmErrno is set to indicate the error.

Notes

The header ucm.h defines constants and types, that may be used to allocate msgId and msg buffers:
Name Description
UCM_MAX_MSG Constant, maximum message size in the current implementation (see also Chapter 9, Configuration Limits)
UCM_MAX_MSGID Constant, maximum message ID size
T_UCM_MSG Type, message buffer, large enough to hold any UCM message
T_UCM_MSGID Type, message ID buffer, large enough to hold any UCM message ID

Globals

char *ucmProgName;     /* reference */

See also

UcmCntl, UcmConnect, UcmOpen

Examples

 
#include "ucm.h"

T_SOCKET socket;
T_UCM_MSG msg; /* buffer to hold message */
T_UCM_MSGID msgId; /* buffer to hold message ID */
int len; /* size of message received */
...
len = UcmRecv(sock, msgId, msg, -1, UF_NOFLAGS);
printf("UcmRecv returned %d\n", len);
 

Back to top