Skip to content

Commit 8c54bd9

Browse files
committedSep 22, 2019
Allow concurrent access NetConn wrapper reading
Updates #88
1 parent a5ecad7 commit 8c54bd9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed
 

Diff for: ‎netconn.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"math"
99
"net"
10+
"sync"
1011
"sync/atomic"
1112
"time"
1213
)
@@ -69,8 +70,9 @@ type netConn struct {
6970

7071
readTimer *time.Timer
7172
readContext context.Context
72-
eofed bool
7373

74+
readMu sync.Mutex
75+
eofed bool
7476
reader io.Reader
7577
}
7678

@@ -89,6 +91,9 @@ func (c *netConn) Write(p []byte) (int, error) {
8991
}
9092

9193
func (c *netConn) Read(p []byte) (int, error) {
94+
c.readMu.Lock()
95+
defer c.readMu.Unlock()
96+
9297
if c.eofed {
9398
return 0, io.EOF
9499
}

0 commit comments

Comments
 (0)
Please sign in to comment.