Open
Description
My app is trying to read from a tty file like this:
val source = SystemFileSystem.source(Path("/dev/ttyUSB0")).buffered()
var count = 0
while (true) {
val b = source.readByte()
count++
println("Received '${Char(b.toInt())}' - count=$count")
}
- On JVM, this will print single bytes as soon as they are available
- On Native, this will wait for 8k bytes before printing all of them together, then wait for the next 8k
Reproducer
I've setup a project here.
To setup you can use socat
to create 2 linked pseudo-tty, like this:
socat PTY,link=/tmp/source,raw,echo=0 PTY,link=/tmp/sink,raw,echo=0 &
More info
- For regular files, no difference between Java/Native
- I guess
fread
here won't return partial results. Not sure if that's expected and/or intended. - But Java's
InputStream.read
here does. - Some discussion about buffering in Provide Sink/Source implementations writing to stdout/reading from stdin #375 may be related (I think stdin/stdout would probably behave the same as tty files?)