int main(int argc, char** argv) { pthread_t recvpid; pthread_t sendpid; MSG_S rcvmsg; int rcvData; MSGQUEUEHANDLE pCxt = createMsgQueue(SIZE); if (NULL == pCxt) { LOGE(TAG, "createMsgQueue failed!\n"); return -1; } pthread_create(&sendpid, NULL, sendThread, pCxt); rcvmsg.m_pMsgData = &rcvData; while(1) { //sleep(1); recvMsg(pCxt, &rcvmsg); printMsg(&rcvmsg); } return 0; }
static int createQueue(char* pcQueueName,int iMsgSize, int iMaxMsg, int* piQueueID) { QueueAttr sAttr; memset(&sAttr,0,sizeof(QueueAttr)); sAttr.liMsgSize = iMsgSize; sAttr.liMaxMsg = iMaxMsg; /*adding one to allow space for control messages*/ *piQueueID = createMsgQueue(pcQueueName,0666,&sAttr); if (*piQueueID < 0) { DEBUG_PRINT("Failed to create %s\n",pcQueueName); } return *piQueueID; }
MessageQueue::MessageQueue(MsqKey create, AccessPerm perm) : _key(create), _id(0) { _id = createMsgQueue(create, perm); }