void doit(mqd_t mqsend, mqd_t mqrecv) { char buff[MSGSIZE]; Mq_send(mqsend, buff, 1, 0); if (Mq_receive(mqrecv, buff, MSGSIZE, NULL) != 1) err_quit("mq_receive error"); }
/* * ===================================================================== * Function:MsgQSend() * Description: send a message to a message queue * Input: msgQId -- msgQ id * msgBuffer -- message to send * msgLength -- length of the message to be sent * timeTick -- wait time (in ticks) * WAIT_FOREVER, this routine block until queue not full * NO_WAIT, this routine return immediately with errorno * wait time, this routine block until queue not full or time up * msgPriority -- MSG_PRI_NORMAL or MSG_PRI_URGENT * MSG_PRI_NORMAL(0) add the message to the tail of the queue * MSG_PRI_URGENT(1) add the message to the head of the queue * Output: N/A * Return: OK on success or ERROR otherwise. *====================================================================== */ int MsgQSend(MSG_QUEUE_ID msgQId, const char* msgBuffer, int msgLength, int timeTick, int msgPriority) { #ifdef LINUX_OS if (msgQId == AII_NULL || msgBuffer == AII_NULL) { return (-1); } return Mq_send((mqd_t)(*msgQId), msgBuffer, msgLength, timeTick, msgPriority); #elif VXWORKS_OS if (msgQId == AII_NULL || msgBuffer == AII_NULL) { return (-1); } return msgQSend(msgQId, msgBuffer, msgLength, timeTick, msgPriority); #endif }
int main(int argc, char **argv) { mqd_t mqd; void *ptr; size_t len; uint_t prio; if (argc != 4) err_quit("usage: mqsend <name> <#bytes> <priority>"); len = atoi(argv[2]); prio = atoi(argv[3]); mqd = Mq_open(argv[1], O_WRONLY); ptr = Calloc(len, sizeof(char)); Mq_send(mqd, ptr, len, prio); exit(0); }
int main(int argc, char **argv) { int i, nloop; mqd_t mq1, mq2; char buff[MSGSIZE]; pid_t childpid; struct mq_attr attr; if (argc != 2) err_quit("usage: lat_pxmsg <#loops>"); nloop = atoi(argv[1]); attr.mq_maxmsg = MAXMSG; attr.mq_msgsize = MSGSIZE; mq1 = Mq_open(Px_ipc_name(NAME1), O_RDWR | O_CREAT, FILE_MODE, &attr); mq2 = Mq_open(Px_ipc_name(NAME2), O_RDWR | O_CREAT, FILE_MODE, &attr); if ( (childpid = Fork()) == 0) { for ( ; ; ) { /* child */ if (Mq_receive(mq1, buff, MSGSIZE, NULL) != 1) err_quit("mq_receive error"); Mq_send(mq2, buff, 1, 0); } exit(0); } /* 4parent */ doit(mq1, mq2); Start_time(); for (i = 0; i < nloop; i++) doit(mq1, mq2); printf("latency: %.3f usec\n", Stop_time() / nloop); Kill(childpid, SIGTERM); Mq_close(mq1); Mq_close(mq2); Mq_unlink(Px_ipc_name(NAME1)); Mq_unlink(Px_ipc_name(NAME2)); exit(0); }