A standard way to implement a buffered stream that is flushed at a constant interval?

I simulate packets from a source that creates packets with a given packet / second interval. I want to create a stream class that works as an object ostream, allowing operator<<it to be used to output data through it, but with the caveat that each inserted value must be freed from the buffer in the file descriptor, so that, at a certain interval.

So, for example, I can have a socket with a file descriptor sockfdand say:

MyBuffer buffer(sockfd, 1000); //Interval of 1000 milliseconds
buffer << 1 << 2 << 3;

and the output will be synchronized so that it outputs

1
<1 second gap>
2
<1 second gap>
3

. Boost.Iostreams , ? - , Google, , ?

.

+3
2

, , - , . , , .

, , , . , , , .

EDIT: , , , ! , , . , .

+2

1000ms ? , Sleep (1000) <. , , .

+2

Source: https://habr.com/ru/post/1792906/


All Articles