Browse Source

PrismNative: Use setvbuf() to set stdout to line-buffered.

By default, stdout is line-buffered when connected to a tty but
completely buffered when redirected to a file or piped to another
program. This makes it hard to get an accurate picture of the current
log output and state of a running PRISM instance by looking at a log
file or terminal output for something like 'prism ... | tee log-file'.

On the other hand, we don't want to call .flush() on the logs all the
time manually. By using setvbuf, we set stdout to line-buffered, i.e.,
it will be flushed automatically for every line-ending. By passing
NULL as the buffer pointer, we ask the libc to construct a buffer,
passing 1024 as a (reasonable) hint for the buffer size, even for long
lines.

[from Joachim Klein]


git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@10127 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 11 years ago
parent
commit
f2d1d8fed6
  1. 1
      prism/src/prism/PrismNative.cc

1
prism/src/prism/PrismNative.cc

@ -185,6 +185,7 @@ JNIEXPORT void JNICALL Java_prism_PrismNative_PN_1SetExportAdvFilename(JNIEnv *e
JNIEXPORT jlong __jlongpointer JNICALL Java_prism_PrismNative_PN_1GetStdout(JNIEnv *env, jclass cls)
{
setvbuf(stdout, NULL, _IOLBF, 1024);
return ptr_to_jlong(stdout);
}

Loading…
Cancel
Save