tarm / serial

BSD 3-Clause "New" or "Revised" License
1.6k stars 451 forks source link

Port.Flush() sets file descriptor to blocking mode in linux #92

Open elliotmr opened 5 years ago

elliotmr commented 5 years ago

the call to p.f.Fd() inside the Port.Flush() sets the file descriptor to blocking mode. Either we should save a reference to the file descriptor in the object field or set the fd back to non-blocking mode after flush is complete.

elliotmr commented 5 years ago

Holy smokes, I just saw that it is specifically setting the file descriptor to be blocking instead of blocking. Is there a specific reason for this?

Just for a little more context, since Go 1.11, if you open an os.File in non-blocking mode, it will add it to the runtime poller and you won't have to sit with a blocked os thread when you call read. This has the added benefit of allowing a concurrent close to the port and it then kicking you out of an active read.