P
P
Pavel Kaptur2017-04-07 19:49:22
linux
Pavel Kaptur, 2017-04-07 19:49:22

How to make a synchronous recording in the pipe?

Hello everyone, I am making a two-way channel of two pipes and during testing I noticed that when writing data on one side I get a breakdown of the message upon receipt. For example

f
OnRead2 f
ffffff
OnRead2 f
OnRead2 ffff
OnRead2 f
those. printed turned into three lines.
I tried to set the O_SYNC flag, but the situation did not change.
FIFO is opened and created like this
if(mkfifo(pipeForWriting, S_IFIFO|S_IRWXU|S_IRWXG|S_IRWXO) != 0)
    {
    if(errno==EEXIST)
      return 0;
    printf("create named pipe error = %d\n", errno); /* произошла ошибка */
      return errno;
    }

pipeForWritingDescriptor = open(pipeForWriting, O_SYNC|O_WRONLY);

How can I make it read the entire message?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2017-04-07
@drem1lin

Is it clear now. Your best bet is to switch to "messages" with your own structure.
In the header of the message, simply put its length, and already in the loop you read the body itself until the length is reached. Thus, you will not depend on buffers and other write asynchrony.
Actually with sockets the same story, and with the rest of the threads.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question