- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编写一个使用 unix 消息队列的程序。问题是这样的,程序报告我“错误:22:无效参数”。我已经 brpwsed,但它不能满足我的搜索。这是简单的代码:
bool msg::send(int key, void* data)
{
(void) data;
bool res = false;
m_msgId = msgget(key, m_mask);
if (m_msgId == -1) {
// noone create it
if ((m_msgId = msgget(key, m_mask | IPC_CREAT)) == -1) {
fprintf(stderr, "Error creating message: %d:(%s)\n",
errno,
strerror(errno));
return res;
}
}
union {
msg m;
char c[sizeof(msg)];
} u = {*this}; // it`s a deep copy
// here the program fails //
int ret = msgsnd(m_msgId, u.c,
sizeof(msg), IPC_NOWAIT);
if (ret == -1) {
if (errno != EAGAIN) {
// here is errno 22 //
fprintf(stderr, "Error creating message: %d:(%s)\n",
errno,
strerror(errno));
return res;
} else {
if (msgsnd(m_msgId, u.c,
sizeof(msg), 0) == -1) {
fprintf(stderr, "Error creating message: %d:(%s)\n",
errno,
strerror(errno));
res = false;
}
}
}
res = true;
return res;
}
如果我尝试发送像“1234567”这样的普通字符串,那没问题。但是这个缓冲区发送失败。我做错了什么?谢谢。
最佳答案
msgsnd
的一个 EINVAL 条件是 "the value of mtype is less than 1" 。
msgsnd
期望发送缓冲区是一个 long 描述消息类型 (mtype) 后跟消息本身。您错误地没有设置消息类型,因此 msgsnd
会将消息的第一个 long 长度字节解释为 mtype。当消息为 "1234567"
但因 *this
而失败时,这恰好有效。
你想定义这样的东西:
struct mymsg {
long mtype;
char mtext[SUFFICIENTLY_LARGE];
};
并在显式设置 mtype>= 1 的同时将消息复制到 mtext 中的内存。
关于c - Linux ipc msgsnd() 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40047214/
我的主要流程(重要代码): let introWindow let win = null function createWindow() { // Create the browser win
信号量是一种 IPC 机制吗? 最佳答案 是的,在许多平台下,信号量可以跨进程同步。您将为此使用“命名”信号量——多个进程通过名称访问对象,类似于文件系统对象。 在 POSIX 中,您可以通过 sem
我一直在关注 Thrift 对 Windows 和 VS 开发的支持,感谢许多贡献者,它已经取得了长足的进步。有针对编译器和 C++ 库的 VS 2010 项目,我已经确认它们在 0.8 中运行良好。
或者它们是同义词吗? 最佳答案 维基百科通常非常适合这些目的。 RPC: Remote procedure call (RPC) is an Inter-process communication t
是否有标准库的一部分? 我一直在四处挖掘,但我看不到任何明显的实现它的东西,或者在 Process 上的任何东西可以让你这样做? 我错过了吗?还是我必须为此功能做一些 C 包装器工作? (如果是这样,
我计划在同一主机上运行的两个进程之间为我的 IPC(进程间通信)使用 unix 域套接字。但在选择 unix 套接字之前,我还必须研究数据安全性。 我只是想知道如果我使用 unix 套接字而不加密我在
System V IPC 和 POSIX IPC 之间有什么区别? 为什么我们有两个标准? 如何决定使用哪些 IPC 函数? 最佳答案 两者都有相同的基本工具——信号量、共享内存和消息队列。它们提供的
在我的menu.js中的“label:'Database'”下,单击事件返回错误:ipc未定义。我想,如果这是 main.js 文件的一部分,并且如果我已经在全局范围内声明了一个 const 为 ip
我正在设置两个 docker 容器 - 一个作为服务器在内存中保存数据,另一个作为客户端访问该数据。为此,我相信我需要使用 --ipc在容器之间共享内存的标志。 Docker documentatio
我正在尝试使用来自 HDFS 的文件运行 flink 作业。我创建了一个数据集如下 - DataSource> visits = env.readHadoopFile(new TextInputFor
我在 NetBeans IDE 8.0.2 中使用 hadoop 2.7.0 和 java oracle jdk1.7.0_79。当我尝试使用 Java 文件与 Hadoop 通信时,出现以下错误。是
我一直在使用 Electrons 同步和异步 RPC 通信机制,并且可以很好地在进程之间传递我的数据。但是,我现在需要不断地向渲染器进程发送事件数据(有点像聊天应用程序)并更新一些文本。 这在 Ele
我正在用 Go 编写一个负载平衡的服务器系统。 负载平衡服务器将与多个应用服务器通信并处理请求。这些服务器既可以在同一台机器上运行,也可以在网络上运行。 我已经弄清楚了网络,但现在我需要为负载均衡器找
我有一个关于操作系统中进程间通信的问题。 两个进程是否可以通过打开同一个文件(据说是在两个进程之前创建的,所以两个进程都有文件处理程序)然后通过写入该文件进行通信来相互通信? 如果是,这个方法属于什么
Closed. This question is opinion-based。它当前不接受答案。 想改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。 6年前关闭。
我有一个使用 System V 共享内存段的应用程序。通常它在内部管理这些,没有人需要接触它们。但对于紧急情况,我们有一个实用程序可以手动清除共享内存段。 问题是,为了做到这一点,它运行ipcs,并使
当使用node-ipc通过IPC在NodeJS进程之间进行通信时,启动服务器并监听连接,或者创建客户端并连接到服务器似乎非常简单。 但是有些事情看起来并不那么简单: How can the serve
我正在寻找有关我可以在我自制的 AVR32 板操作系统中实现的可能 IPC 机制的建议。 我目前的选择是实现 Tanenbaum 所写书籍中描述的按摩传递机制。 这是一个不错的选择吗?有没有更简单的方
我去面试了。面试官问我: If two nodes are sending two messages of the same identifier (0x100) with different dat
我正在寻找一种进程间通信工具,可以在相同或不同系统上运行的语言和/或环境之间使用。例如,它应该允许在 Java、C# 和/或 C++ 组件之间发送信号,并且还应该支持某种排队机制。唯一明显与环境和语言
我是一名优秀的程序员,十分优秀!