mirror of
https://github.com/janet-lang/janet
synced 2025-01-07 06:10:25 +00:00
Disable buffering for files created with ev/to-file
This commit is contained in:
parent
268ff666d2
commit
6ee05785d1
@ -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);
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user