From 11ce17f0a66365ece3c5cf043c4dccf5cdf8df9f Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 31 Jan 2017 20:41:38 -0800 Subject: Expand a comment to give more details. (Dear Microsoft: why did you choose not to support line buffering in the MSVC "standard I/O library" routines?) Change-Id: I5add94d2c83e73e9845fea0f355a1923fddf2deb Reviewed-on: https://code.wireshark.org/review/19890 Reviewed-by: Guy Harris --- sharkd_session.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'sharkd_session.c') diff --git a/sharkd_session.c b/sharkd_session.c index faddaa364a..2f5c0334fc 100644 --- a/sharkd_session.c +++ b/sharkd_session.c @@ -1885,7 +1885,20 @@ sharkd_session_process(char *buf, const jsmntok_t *tokens, int count) /* reply for every command are 0+ lines of JSON reply (outputed above), finished by empty new line */ printf("\n"); - /* stdout is on most systems buffered, fflush() to output reply to a socket */ + /* + * We do an explicit fflush after every line, because + * we want output to be written to the socket as soon + * as the line is complete. + * + * The stream is fully-buffered by default, so it's + * only flushed when the buffer fills or the FILE * + * is closed. On UN*X, we could set it to be line + * buffered, but the MSVC standard I/O routines don't + * support line buffering - they only support *byte* + * buffering, doing a write for every byte written, + * which is too inefficient, and full buffering, + * which is what you get if you request line buffering. + */ fflush(stdout); } } -- cgit v1.2.1