![]() |
|
|||
0001 /** 0002 * @brief Simple message queue server process 0003 * 0004 * @file atmiclt0_mqsv.c 0005 */ 0006 /* ----------------------------------------------------------------------------- 0007 * Enduro/X Middleware Platform for Distributed Transaction Processing 0008 * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 0009 * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved. 0010 * This software is released under one of the following licenses: 0011 * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use. 0012 * See LICENSE file for full text. 0013 * ----------------------------------------------------------------------------- 0014 * AGPL license: 0015 * 0016 * This program is free software; you can redistribute it and/or modify it under 0017 * the terms of the GNU Affero General Public License, version 3 as published 0018 * by the Free Software Foundation; 0019 * 0020 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 0021 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 0022 * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3 0023 * for more details. 0024 * 0025 * You should have received a copy of the GNU Affero General Public License along 0026 * with this program; if not, write to the Free Software Foundation, Inc., 0027 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0028 * 0029 * ----------------------------------------------------------------------------- 0030 * A commercial use license is available from Mavimax, Ltd 0031 * contact@mavimax.com 0032 * ----------------------------------------------------------------------------- 0033 */ 0034 #include <string.h> 0035 #include <stdio.h> 0036 #include <stdlib.h> 0037 #include <memory.h> 0038 #include <pthread.h> 0039 #include <unistd.h> 0040 #include <fcntl.h> 0041 #include <sys_mqueue.h> 0042 #include "test000.h" 0043 #include <ndrstandard.h> 0044 #include <ndebug.h> 0045 #include <errno.h> 0046 /*---------------------------Externs------------------------------------*/ 0047 /*---------------------------Macros-------------------------------------*/ 0048 /*---------------------------Enums--------------------------------------*/ 0049 /*---------------------------Typedefs-----------------------------------*/ 0050 /*---------------------------Globals------------------------------------*/ 0051 /*---------------------------Statics------------------------------------*/ 0052 /*---------------------------Prototypes---------------------------------*/ 0053 0054 /** 0055 * This will open some message queue (say, "test000_server") and will provide responses 0056 * back to "test000_client". 0057 * We will use standard API here via sys_mqueue.h 0058 * @param argc 0059 * @param argv 0060 * @return 0061 */ 0062 int main( int argc , char **argv ) 0063 { 0064 int ret = EXSUCCEED; 0065 mqd_t mq = (mqd_t)EXFAIL; 0066 mqd_t mq_clt = (mqd_t)EXFAIL; 0067 struct mq_attr attr; 0068 char buffer[TEST_REPLY_SIZE]; 0069 int must_stop = 0; 0070 int i; 0071 0072 /* initialize the queue attributes */ 0073 attr.mq_flags = 0; 0074 attr.mq_maxmsg = 10; 0075 attr.mq_msgsize = TEST_REPLY_SIZE; 0076 attr.mq_curmsgs = 0; 0077 0078 /* create the message queue */ 0079 if ((mqd_t)EXFAIL==(mq = ndrx_mq_open(SV_QUEUE_NAME, O_CREAT | O_RDONLY, 0644, &attr))) 0080 { 0081 NDRX_LOG(log_error, "Failed to open queue: [%s]: %s", 0082 SV_QUEUE_NAME, strerror(errno)); 0083 EXFAIL_OUT(ret); 0084 } 0085 0086 do 0087 { 0088 ssize_t bytes_read; 0089 0090 /* receive the message 0091 * Maybe have some timed receive 0092 */ 0093 NDRX_LOG(log_debug, "About to RCV!"); 0094 0095 if (EXFAIL==(bytes_read=ndrx_mq_receive(mq, buffer, 0096 TEST_REPLY_SIZE, NULL))) 0097 { 0098 NDRX_LOG(log_error, "Failed to get message: %s", strerror(errno)); 0099 EXFAIL_OUT(ret); 0100 } 0101 0102 NDRX_LOG(log_debug, "Read bytes: %d", bytes_read); 0103 NDRX_DUMP(log_debug, "Received data", buffer, TEST_REPLY_SIZE); 0104 0105 /* translate to reply format */ 0106 for (i=1;i<TEST_REPLY_SIZE; i++) 0107 { 0108 buffer[i] = buffer[i]+1; 0109 } 0110 0111 /* Sender reply */ 0112 0113 if ((mqd_t)EXFAIL==(mq_clt = ndrx_mq_open(CL_QUEUE_NAME, O_RDWR, 0644, &attr))) 0114 { 0115 NDRX_LOG(log_error, "Failed to open queue: [%s]: %s", 0116 SV_QUEUE_NAME, strerror(errno)); 0117 EXFAIL_OUT(ret); 0118 } 0119 0120 NDRX_DUMP(log_debug, "Sending data", buffer, TEST_REPLY_SIZE); 0121 if (EXFAIL==ndrx_mq_send(mq_clt, buffer, 0122 TEST_REPLY_SIZE, 0)) 0123 { 0124 NDRX_LOG(log_error, "Failed to send message: %s", strerror(errno)); 0125 EXFAIL_OUT(ret); 0126 } 0127 0128 /* close server queue... */ 0129 if (EXFAIL==ndrx_mq_close(mq_clt)) 0130 { 0131 NDRX_LOG(log_error, "Failed to close client queue: %s", 0132 strerror(errno)); 0133 EXFAIL_OUT(ret); 0134 } 0135 0136 } while (!must_stop); 0137 0138 out: 0139 /* cleanup */ 0140 0141 if ((mqd_t)EXFAIL!=mq && EXFAIL==ndrx_mq_close(mq)) 0142 { 0143 NDRX_LOG(log_error, "Failed to close queue: %s", strerror(errno)); 0144 } 0145 0146 return ret; 0147 } 0148 0149 0150 /* vim: set ts=4 sw=4 et smartindent: */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |