diff --git a/src/core/ev.c b/src/core/ev.c index f6d46a8d..ce27c838 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -3312,6 +3312,9 @@ static JanetFile *get_file_for_stream(JanetStream *stream) { /* _close(fd); */ return NULL; } + if (setvbuf(f, NULL, _IONBF, 0)) { + return NULL; + } #else int newHandle = dup(stream->handle); if (newHandle < 0) return NULL; @@ -3320,6 +3323,10 @@ static JanetFile *get_file_for_stream(JanetStream *stream) { close(newHandle); return NULL; } + if (setvbuf(f, NULL, _IONBF, 0)) { + close(newHandle); + return NULL; + } #endif return janet_makejfile(f, flags); } @@ -3327,7 +3334,8 @@ static JanetFile *get_file_for_stream(JanetStream *stream) { JANET_CORE_FN(janet_cfun_to_file, "(ev/to-file)", "Create core/file copy of the stream. This value can be used " - "when blocking IO behavior is needed.") { + "when blocking IO behavior is needed. Buffering is turned off " + "for the file.") { janet_fixarity(argc, 1); JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type); JanetFile *iof = get_file_for_stream(stream); diff --git a/test/suite-ev.janet b/test/suite-ev.janet index 1bbbe623..46820953 100644 --- a/test/suite-ev.janet +++ b/test/suite-ev.janet @@ -422,7 +422,6 @@ (expect-read bob "Whats your name?\n") (def fbob (ev/to-file bob)) (file/write fbob "bob") -(file/flush fbob) (:close fbob) (expect-read bob "Welcome bob\n") (def alice (net/connect test-host test-port))