How to do a synchronous write to the pipe?

Hey all, doing a two-way channel of the two pipes and when testing noticed that recording data on the one hand get a breakdown of the message when receiving. for example
OnRead2 f
OnRead2 f
OnRead2 ffff
OnRead2 f
i.e. printed turned into three lines.
I tried to set the O_SYNC flag, but the situation has not changed.
The FIFO is opened and creates a so
if(mkfifo(pipeForWriting, S_IFIFO|S_IRWXU|S_IRWXG|S_IRWXO) != 0)
 return 0;
 printf("create named pipe error = %d\n", errno); /* an error occurred */
 return errno;

pipeForWritingDescriptor = open(pipeForWriting, O_SYNC|O_WRONLY);

How to make so that to read the entire message?
June 27th 19 at 15:21
1 answer
June 27th 19 at 15:23
So it is understandable. You best go to "messages" with their structure.
In the header of the message simply put its length, and in a loop read the body to achieve length. This way you will not depend on buffers and other async record.
The actual socket is the same story, and the other threads.
I something similar I assumed, just was hoping the whole way to do a full reading. - magnolia_VonRueden13 commented on June 27th 19 at 15:26
well, if the messages are the same length, then just read to achieve. Well, or the pipe you don't quite fit, or take a type library and zeromq to score the pipe. They are not for this. In fact, there are more ipc shared memory and queue. Not that with them more, they are at least. With them the problem with the initialization. Well, or again, zeromq and friends... - Kasey.Cruickshank commented on June 27th 19 at 15:29
: Ah, Yes. If the lines end with a carriage return, then use printf and scanf, it's not ironic. - Kasey.Cruickshank commented on June 27th 19 at 15:32
Well, or fputs/fgets - Kasey.Cruickshank commented on June 27th 19 at 15:35
many thanks, and one more question, I'm just curious to hear opinions. The question is related to architecture, so I'm writing a client, i.e. is it essentially creates an instance of the class pipe and waits through payp when will the team die, the pipe instance at the initialization creates a stream listener, which hung callback. Well, from next come the data fall in the callback, and there should be a build of some sort. I got the idea to write a class that will buffer data and the request to give the received command. Now, the processing of the commands should be in one thread and receive data via the callback. Thus, it turns out that without the global instance of the class can not do? here's how to make this work with buffering? - magnolia_VonRueden13 commented on June 27th 19 at 15:38
: Well, the "global class" here is not needed. And buffersize better to do it via the message queue. And this link on this line to pass in the callback and handler teams. In principle, this is the traditional model of consumer-producer. If you write in C++ using a framework, you probably already have classes.
And "global class" is usually called a singleton. But not to do just one class, usually create an object of type Context, and it is passed to all the entities that you want. The only take care of synchronizing access using locks. - Kasey.Cruickshank commented on June 27th 19 at 15:41
Yes, a reference to the queue (queue) can be put in your context object. - Kasey.Cruickshank commented on June 27th 19 at 15:44

Find more questions by tags ConveyorC++Linux