bugst / go-serial

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

Double Close() on the same port should be a no-op #38

Closed cmaglie closed 4 years ago

cmaglie commented 6 years ago

If the user do a double Close() on the same port object the underlying handle is actually closed twice. This may not be a problem when working with one Port object at a time, but it may result in problematic behavior in multi-threaded environments (in particular on unix where handles are reused this may result in the first object 'leaking' the handle).

Ideally the Close() method should return the PortClosed error if called twice.

niondir commented 6 years ago

Here is my windows fix for this. Feel free to cherry pick:

https://github.com/Lobaro/go-serial/commit/9f75a18e7cf739a6d65d1405f13bea1307307e50 https://github.com/Lobaro/go-serial/commit/06091fa1ae6a1330e3b43854667e0f4137bd347e