1
0
mirror of https://github.com/janet-lang/janet synced 2025-09-03 19:38:04 +00:00

Disable buffering for files created with ev/to-file

This commit is contained in:
Michael Camilleri
2024-12-15 20:37:58 +09:00
parent 268ff666d2
commit 6ee05785d1
2 changed files with 9 additions and 2 deletions

View File

@@ -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);

View File

@@ -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))