Allow multiple calls to close

This commit is contained in:
Tobias Kaupat
2017-11-27 18:28:08 +01:00
committed by Cristian Maglie
parent 6500d68fc8
commit 545e830e04

View File

@@ -17,7 +17,7 @@ package serial
*/ */
import "syscall" import ("syscall")
type windowsPort struct { type windowsPort struct {
handle syscall.Handle handle syscall.Handle
@@ -58,6 +58,12 @@ func nativeGetPortsList() ([]string, error) {
} }
func (port *windowsPort) Close() error { func (port *windowsPort) Close() error {
defer func() {
port.handle = 0
}()
if port.handle == 0 {
return nil
}
return syscall.CloseHandle(port.handle) return syscall.CloseHandle(port.handle)
} }