00001 00010 #include <errno.h> 00011 #include <sys/msg.h> 00012 #include <sys/sem.h> 00013 #include <unistd.h> 00014 #include <string.h> 00015 #include "MsgQInternal.h" 00016 00017 00018 00019 /******************************************************************************* 00020 * MsgQReceive (qName, msg, maxNBytes, timeout, err) 00021 * Description: Function for receiving a message with internal copy 00022 ********************************************************************************/ 00023 00024 EXPORT_C int MsgQReceive(ULONG qName, char* msg, ULONG maxNBytes, int timeout, int* err) { 00025 MSGQ_INFO* pMsgQInfo = NULL; 00026 ssize_t rxBytes; 00027 int toTicks; 00028 00029 struct { 00030 long mtype; 00031 char mtext[MAX_MSG_LEN]; 00032 } message; 00033 00034 /* check parameters */ 00035 if ((pMsgQInfo = MsgQTableLookup(qName)) != NULL) { 00036 if(timeout != NO_WAIT && timeout != WAIT_FOREVER) 00037 toTicks = timeout < 10 ? 1: (ULONG)((timeout * sysconf(_SC_CLK_TCK)) / 1000); 00038 else 00039 toTicks = timeout; 00040 00041 message.mtype = 1; 00042 /* receive message */ 00043 if((rxBytes = msgrcv(pMsgQInfo->qId, &message, (size_t)maxNBytes, 1, toTicks)) != -1) { 00044 message.mtext[rxBytes-4] = '\0'; 00045 bcopy(message.mtext, msg, rxBytes); 00046 pMsgQInfo->numMsgs--; 00047 *err = OK; 00048 return ((ULONG)rxBytes); 00049 } 00050 else 00051 *err = errno; 00052 } 00053 else 00054 *err = KMsgQLibQIdErr; 00055 00056 return(ERROR); 00057 } 00058 00059
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.