c++ - Standard way to implement a buffered stream that flushes at a constant interval? -


i'm simulating packets source produces packets @ given packet/second interval. want make stream class operates ostream object, allowing operator<< used output things through it, caveat each value inserted should released buffer file descriptor, in order, @ specified interval.

so, instance, might have socket file descriptor sockfd , say:

mybuffer buffer(sockfd, 1000); //interval of 1000 milliseconds buffer << 1 << 2 << 3; 

and output timed such output

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

to socket. i'm looking @ boost.iostreams right now, solution? there magical phrase can google describes problem i'm not aware of?

any appreciated.

thanks brad

one option doing that's orthogonal building custom streams class maintain queue of strings that's polled thread every second. each time queue polled, thread reads out first element , sends across network.

this doesn't use streams library, think might want. internally, streams glob input mass of text, losing information parts of text correspond each object inserted.

edit: should have mentioned first time around, please sure use appropriate synchronization on queue! you'll want use mutex guard access it, or use clever lock-free queue if doesn't work. sure not blindly read , write multiple threads.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -