消息队列发送函数报错,错误码为22。谢谢回答
#include <netinet/in.h>
#include <sys/types.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/msg.h>
#include <sys/ipc.h>
struct stClient
{
int iConCounter; /*连接次数*/
int iConId; /*客户端创建ID号*/
int iStatistics; /*服务端接收的次数,做为映射关系标识*/
};
/*消息队列结构体*/
struct stMsgs
{
long mtype;
struct stClient stMsg;
};
/*创建消息队列*/
int msgcreat (int iKey)
{
int iMsgid = 0;
printf("消息队列中获取的KEY值为%d\n", iKey);
/*创建消息队列*/
iMsgid = msgget (iKey, 0666 | IPC_CREAT);/*创建消息队列*/
if (iMsgid <0)
{
printf("创建消息对列错误,错误码为%d", errno);
return -1;
}
printf("创建消息队列成功,消息队列描述符为%d", iMsgid);
return 0;
}
/*消息对列关键字获取函数*/
int msggain()
{
int iMsgid;
int iKey;
iKey = 4321; /*获取Key值*/
iMsgid = msgget (iKey, 0666 | IPC_CREAT); /*打开消息队列*/
if (iMsgid < 0)
{
printf("打开消息队列错误,错误码为%d", errno);
return -1;
}
printf("打开消息队列成功,消息队列描述符为%d", iMsgid);
return iMsgid;
}
msgsnd: Invalid or incomplete multibyte or wide character
错误码为22
/*发送消息队列函数*/
int msgsend (int iMsgid, struct stMsgs *stMsgSend)
{
int iRet;
/*发送消息*/
while(1) /*只发送一次,成功就跳出循环*/
{
iRet = msgsnd (iMsgid, stMsgSend, sizeof((*stMsgSend).stMsg), 0);
if(iRet < 0)
{
if(errno == EINTR)
{
printf("信号中段发送错误");
continue;
}
else
{
printf("消息队列ID号为%d,发送数据为%d %d %d", iMsgid, (*stMsgSend).stMsg.iConCounter,
(*stMsgSend).stMsg.iConId, (*stMsgSend).stMsg.iStatistics);
printf("消息队列发送系统错误,错误码为%d", errno);
perror("msgsnd");
return -1;
}
}
break;/*发送成功跳出循环*/
}
printf("消息队列发送成功");
return 0;
}
/*接收消息队列函数*/
int msgreceive (int iMsgid)
{
int iRet;
struct stClient stReceive;
while (1) /*将消息队列中所有消息输出*/
{
iRet = msgrcv(iMsgid, &stReceive, sizeof(stReceive), 0, 0);
if(iRet < 0)
{
if (errno == EINTR)
{
printf("信号中段接收错误");
continue;
}
else
{
printf("消息队列系统错误接收失败,错误码为%d", errno);
return -1;
}
}
/*将消息队列接收数据输出*/
printf("与共享内存的映射关系为%d\n", stReceive.iStatistics);
printf("客户端连接次数为%d\n", stReceive.iConCounter);
printf("客户端的socket描述字为%d\n", stReceive.iConId);
}
return 0;
}
int main()
{
int iKey;
int iMsgId;
struct stMsgs stMsgSend;
memset(&stMsgSend, 0x0, sizeof(stMsgSend));
stMsgSend.mtype = msggain();
stMsgSend.stMsg.iConCounter = 2;
stMsgSend.stMsg.iConId = 1;
stMsgSend.stMsg.iStatistics = 10;
msgcreat(4321);
iMsgId = msggain();
msgsend (iMsgId, &stMsgSend);
msgreceive(iMsgId);
return 0;
}
#include <sys/types.h>
#include <netdb.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/msg.h>
#include <sys/ipc.h>
struct stClient
{
int iConCounter; /*连接次数*/
int iConId; /*客户端创建ID号*/
int iStatistics; /*服务端接收的次数,做为映射关系标识*/
};
/*消息队列结构体*/
struct stMsgs
{
long mtype;
struct stClient stMsg;
};
/*创建消息队列*/
int msgcreat (int iKey)
{
int iMsgid = 0;
printf("消息队列中获取的KEY值为%d\n", iKey);
/*创建消息队列*/
iMsgid = msgget (iKey, 0666 | IPC_CREAT);/*创建消息队列*/
if (iMsgid <0)
{
printf("创建消息对列错误,错误码为%d", errno);
return -1;
}
printf("创建消息队列成功,消息队列描述符为%d", iMsgid);
return 0;
}
/*消息对列关键字获取函数*/
int msggain()
{
int iMsgid;
int iKey;
iKey = 4321; /*获取Key值*/
iMsgid = msgget (iKey, 0666 | IPC_CREAT); /*打开消息队列*/
if (iMsgid < 0)
{
printf("打开消息队列错误,错误码为%d", errno);
return -1;
}
printf("打开消息队列成功,消息队列描述符为%d", iMsgid);
return iMsgid;
}
msgsnd: Invalid or incomplete multibyte or wide character
错误码为22
/*发送消息队列函数*/
int msgsend (int iMsgid, struct stMsgs *stMsgSend)
{
int iRet;
/*发送消息*/
while(1) /*只发送一次,成功就跳出循环*/
{
iRet = msgsnd (iMsgid, stMsgSend, sizeof((*stMsgSend).stMsg), 0);
if(iRet < 0)
{
if(errno == EINTR)
{
printf("信号中段发送错误");
continue;
}
else
{
printf("消息队列ID号为%d,发送数据为%d %d %d", iMsgid, (*stMsgSend).stMsg.iConCounter,
(*stMsgSend).stMsg.iConId, (*stMsgSend).stMsg.iStatistics);
printf("消息队列发送系统错误,错误码为%d", errno);
perror("msgsnd");
return -1;
}
}
break;/*发送成功跳出循环*/
}
printf("消息队列发送成功");
return 0;
}
/*接收消息队列函数*/
int msgreceive (int iMsgid)
{
int iRet;
struct stClient stReceive;
while (1) /*将消息队列中所有消息输出*/
{
iRet = msgrcv(iMsgid, &stReceive, sizeof(stReceive), 0, 0);
if(iRet < 0)
{
if (errno == EINTR)
{
printf("信号中段接收错误");
continue;
}
else
{
printf("消息队列系统错误接收失败,错误码为%d", errno);
return -1;
}
}
/*将消息队列接收数据输出*/
printf("与共享内存的映射关系为%d\n", stReceive.iStatistics);
printf("客户端连接次数为%d\n", stReceive.iConCounter);
printf("客户端的socket描述字为%d\n", stReceive.iConId);
}
return 0;
}
int main()
{
int iKey;
int iMsgId;
struct stMsgs stMsgSend;
memset(&stMsgSend, 0x0, sizeof(stMsgSend));
stMsgSend.mtype = msggain();
stMsgSend.stMsg.iConCounter = 2;
stMsgSend.stMsg.iConId = 1;
stMsgSend.stMsg.iStatistics = 10;
msgcreat(4321);
iMsgId = msggain();
msgsend (iMsgId, &stMsgSend);
msgreceive(iMsgId);
return 0;
}
...全文
相关推荐
ucOS消息队列使用
##### 消息队列操作消息队列的操作主要包括接收、发送和查询等。**1. 接收消息**可以使用`OSQPend()`函数来接收消息队列中的消息。
基于RT-Thread星火一号的温湿度监测与报警系统实践
从嵌入式系统开发的视角切入,先介绍RTOS与传统裸机开发的差异,说明多任务设计在环境监测中的价值。然后以STM32F407开发板与SHT30传感器为例,讲解如何通过RT-Thread的sensor框架快速接入硬件,并利用线程、消息队列、事件集实现数据采集、阈值报警与显示。文章还涵盖滞回比较、滤波去抖、FinSH调试等实用技巧,最后对比51单片机方案,给出选型建议。该实践适合希望从裸机开发过渡到RTOS的开发者,也可作为课程设计或产品原型的参考。
核心面试聚焦:业务问题+系统问题+设计题---字节、阿里、美团等整理统计
业务系统及其他相关面试问题整理:线上相关问题排查+高并发系统的限流+高并发秒杀系统设计+负载均衡+一个网站有 20 亿 url 存在一个黑名单中,这个黑名单要怎么存?若此时随便输入一个 url,你如何快速判断该 url 是否在这个黑名单中?并且需在给定内存空间(比如:500M)内快速判断出?
Ucos学习之邮箱与消息队列
- **消息队列的删除**:使用`OSQDelete`函数删除消息队列。 - **消息的发送**:通过`OSQPost`函数将消息发送到消息队列。
联通SGIP网管错误码,2012年的资源
- 一般指系统消息队列已满。12. **33** - 超过流量限制。 - 当发送方在一秒钟内的发送量达到或超过设定的阈值时触发。13. **34** - 登陆太频繁。


