@@ -15,8 +15,8 @@ import (
15
15
"sync"
16
16
"unsafe"
17
17
18
- "golang.org/x/sys/unix"
19
18
"go.bug.st/serial/unixutils"
19
+ "golang.org/x/sys/unix"
20
20
)
21
21
22
22
type unixPort struct {
@@ -51,22 +51,31 @@ func (port *unixPort) Close() error {
51
51
return nil
52
52
}
53
53
54
- func (port * unixPort ) Read (p []byte ) (n int , err error ) {
54
+ func (port * unixPort ) Read (p []byte ) (int , error ) {
55
55
port .closeLock .RLock ()
56
56
defer port .closeLock .RUnlock ()
57
57
if ! port .opened {
58
58
return 0 , & PortError {code : PortClosed }
59
59
}
60
60
61
61
fds := unixutils .NewFDSet (port .handle , port .closeSignal .ReadFD ())
62
- res , err := unixutils .Select (fds , nil , fds , - 1 )
63
- if err != nil {
64
- return 0 , err
65
- }
66
- if res .IsReadable (port .closeSignal .ReadFD ()) {
67
- return 0 , & PortError {code : PortClosed }
62
+ for {
63
+ res , err := unixutils .Select (fds , nil , fds , - 1 )
64
+ if err == unix .EINTR {
65
+ continue
66
+ }
67
+ if err != nil {
68
+ return 0 , err
69
+ }
70
+ if res .IsReadable (port .closeSignal .ReadFD ()) {
71
+ return 0 , & PortError {code : PortClosed }
72
+ }
73
+ n , err := unix .Read (port .handle , p )
74
+ if err == unix .EINTR {
75
+ continue
76
+ }
77
+ return n , err
68
78
}
69
- return unix .Read (port .handle , p )
70
79
}
71
80
72
81
func (port * unixPort ) Write (p []byte ) (n int , err error ) {
0 commit comments