bugst / go-serial

A cross-platform serial library for go-lang.
BSD 3-Clause "New" or "Revised" License
618 stars 188 forks source link

Timeout : return an error compatible with os.IsTimeout() #118

Open maitredede opened 2 years ago

maitredede commented 2 years ago

Like *net.Conn.Read() or *os.File.Read() when a timeout occurs, return an error that can be checked with os.IsTimeout()

maitredede commented 2 years ago

The actual behavior is "return 0 without error", that can also be understood as "end of stream". Network connections and file reads have their own timeout errors that can be detected with os.IsTimeout().

zeroZshadow commented 2 years ago

This is exactly the issue i'm running into. I'm using io.ReadFull to fill a buffer directly from the port. However if a timeout is hit due to misconfiguration, it will loop forever. Thanks for fixing this!

quite commented 1 month ago

@maitredede do you have time to rebase this?

quite commented 1 month ago

@maitredede i you don't have time, i think i can take over with a new PR (keeping you as author of course).

maitredede commented 1 month ago

Hello @quite, I have rebased/updated :smiley:

quite commented 1 month ago

@maitredede great! I hope @cmaglie will get some time to look over this and merge it

andradei commented 1 month ago

This would be very useful to have as I'm testing various types of connections and all of them have timeouts except for my serial ones and this would fix it.