Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the sendLock in the stream #41

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
remove the sendLock in the stream
Concurrent use of an io.Writer is not valid.
  • Loading branch information
marten-seemann committed Feb 16, 2021
commit f2c2ce6e280702bcbdc6ecf69c1548a6f59cbabf
9 changes: 2 additions & 7 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ type Stream struct {
recvLock sync.Mutex
recvBuf segmentedBuffer

sendLock sync.Mutex

recvNotifyCh chan struct{}
sendNotifyCh chan struct{}

Expand Down Expand Up @@ -123,11 +121,8 @@ WAIT:
}

// Write is used to write to the stream
func (s *Stream) Write(b []byte) (n int, err error) {
s.sendLock.Lock()
defer s.sendLock.Unlock()
total := 0

func (s *Stream) Write(b []byte) (int, error) {
var total int
for total < len(b) {
n, err := s.write(b[total:])
total += n
Expand Down