mqueue

linux mq_open ignores mq_msgsize attribute

自作多情 提交于 2019-12-24 03:05:13
问题 All, used to think that I was sane, now not so sure. I am trying to create a message queue whose mq_msgsize attribute is OTHER than 8192, which seems to be the default. I have attached my code below -- it has a number of printf's showing the value. If you can point out what I doing wrong, I will be eternally grateful. bool Subscriber::Subscribe( void ) { mqd_t qid; bool brv = false; msg_topic_t topic = this->GetTopic(); struct mq_attr q_attr; int rv = 0; if (VALID_TOPIC( topic )) { if (this-

Handling mq_open failures after mq_unlink

有些话、适合烂在心里 提交于 2019-12-08 02:14:45
问题 I'm writing a client/server process on Suse Linux using Posix message queues to communicate, similar to the accepted answer in "How do I use mqueue in a c program on a Linux based system?". When the server dies, it does an mq_close and mq_unlink . However, the client gets no notification of this, so calls to mq_send in the client will continue to work even though the queue has been unlinked. The problem is, when the server is restarted, it tries to create a queue with mq_open with O_CREAT,

send struct in mq_send

非 Y 不嫁゛ 提交于 2019-11-29 13:36:31
I am using POSIX IPC and according to the documentation - http://man7.org/linux/man-pages/man3/mq_send.3.html mq_send() method only sends char* data and mq_recv() recieves only character data. However, I want to send a custom struct to my msg queue and on the receiving end, I want to get the struct. sample struct: struc Req { pid_t pid; char data[4096]; } So, does anyone know how to accomplish this in C lang? You just need to pass the address of the struct and cast it to the appropriate pointer type: const char * for mq_send and char * for mq_receive . typedef struct Req { pid_t pid; char data

send struct in mq_send

百般思念 提交于 2019-11-28 03:08:06
问题 I am using POSIX IPC and according to the documentation - http://man7.org/linux/man-pages/man3/mq_send.3.html mq_send() method only sends char* data and mq_recv() recieves only character data. However, I want to send a custom struct to my msg queue and on the receiving end, I want to get the struct. sample struct: struc Req { pid_t pid; char data[4096]; } So, does anyone know how to accomplish this in C lang? 回答1: You just need to pass the address of the struct and cast it to the appropriate

How do I use mqueue in a c program on a Linux based system?

与世无争的帅哥 提交于 2019-11-27 10:51:57
How do I use mqueue (message queue) in a c program on a Linux based system? I'm looking for some good code examples that can show how this is done in a correct and proper way, maybe a howto. The following is a simple example of a server that receives messages from clients until it receives an "exit" message telling it to stop. The code for the server : #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <errno.h> #include <mqueue.h> #include "common.h" int main(int argc, char **argv) { mqd_t mq; struct mq_attr attr; char buffer[MAX

How do I use mqueue in a c program on a Linux based system?

五迷三道 提交于 2019-11-26 17:58:01
问题 How do I use mqueue (message queue) in a c program on a Linux based system? I'm looking for some good code examples that can show how this is done in a correct and proper way, maybe a howto. 回答1: The following is a simple example of a server that receives messages from clients until it receives an "exit" message telling it to stop. The code for the server : #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <errno.h> #include