sync ostream buffer after whole json write finished #2752
Shadasviar
started this conversation in
Ideas
Replies: 1 comment
-
I understand the issue, but I am not sure whether the library should decide when to flush - I think this is something an application can better decide. In your case, you could create a function that wraps the streaming/flushing. In a general case, the use case may dictate different strategies - maybe it's perfectly fine to never flush. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a custom socket implementation, which inherits from
streambuf
andiostream
, so I can use it withnlohmann::json
like below:As you can see from example code, I always need to call streambuf
flush
method after json was written to the socket, because nlohmann library doesn't call it inside.Of course, I can implement
putc
function of my buffer such way, so it would callsync
and perform write system call for every char/only for end of line character, but I think that it would be good if nlohmann library would callsync
function on output streambuf it use after json was put to buffer, because library knows when json ends. Such behavior could save a lot of write system calls and user should not to callflush
manually.I would want to discuss, if adding syncing buffer to the nlohmann library is a good or bad idea, does it have some drawbacks etc.
Beta Was this translation helpful? Give feedback.
All reactions