Allow multiple calls to close
This commit is contained in:
committed by
Cristian Maglie
parent
6500d68fc8
commit
545e830e04
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user