testosmsgqsend.c

来自「ReWorks里一个有关消息队列的例子。」· C语言 代码 · 共 52 行

C
52
字号
#include "msgqTest.h"

#define MESSAGE_SIZE (sizeof(long) * 4)  
static long    buffer[ MESSAGE_SIZE / sizeof(long) ];
static long    recBuf[ MESSAGE_SIZE / sizeof(long) ];
static unsigned32 MsgQ_id;
static unsigned32 msgq_size;

int testOSMsgQSendandReceive()
{
    OS_STATUS status;
    
    
    printf("*** test of OSMsgQSendandReceive ***\n");
    printf("create a MsgQ.\n");
    status = OSMsgQCreate("msg",10,20,OS_DEFAULT,&MsgQ_id); 
    if(status != OS_OK)
    {
 		printf("OSMsgQCreate error:[%s]\n",serrno(errno));
		return (-1);
 	}
 	
	strcpy( buffer, "hello world" );
 	printf("OSMsgQSend send the buf\"%s\" to MsgQ.\n",buffer);	
	status = OSMsgQSend( MsgQ_id, buffer, MESSAGE_SIZE ); 
    if(status != OS_OK)
    {
 		printf("OSMsgQSend error:[%s]\n",serrno(errno));
		return (-1);
 	}	
  	
  	printf("receive the buf.\n");
  	status = OSMsgQReceive(MsgQ_id,recBuf,&msgq_size,OS_DEFAULT,OS_NO_TIMEOUT);
    if(status != OS_OK)
    {
 		printf("OSMsgQReceive error:[%s]\n",serrno(errno));
		return (-1);
 	}
 	else
 	{
    	printf("OSMsgQReceive success,recBuf \"%s\"\n",recBuf);  
    	printf("so OSMsgQSend success too!\n");  
  	}
  	
   	OSMsgQDelete(MsgQ_id); 
   	printf("*** OSMsgQSendandReceive test OK! ***\n\n");
	return 1;
}   
 


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?