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

reduce usage of goto #40

Merged
merged 1 commit into from
Feb 16, 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
30 changes: 12 additions & 18 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ START:
s.recvLock.Lock()
if s.recvBuf.Len() == 0 {
s.recvLock.Unlock()
goto WAIT
select {
case <-s.recvNotifyCh:
goto START
case <-s.readDeadline.wait():
return 0, ErrTimeout
}
}

// Read any bytes
Expand All @@ -112,14 +117,6 @@ START:
// Send a window update potentially
err = s.sendWindowUpdate()
return n, err

WAIT:
select {
case <-s.recvNotifyCh:
goto START
case <-s.readDeadline.wait():
return 0, ErrTimeout
}
}

// Write is used to write to the stream
Expand Down Expand Up @@ -164,7 +161,12 @@ START:
// If there is no data available, block
window := atomic.LoadUint32(&s.sendWindow)
if window == 0 {
goto WAIT
select {
case <-s.sendNotifyCh:
goto START
case <-s.writeDeadline.wait():
return 0, ErrTimeout
}
}

// Determine the flags if any
Expand All @@ -184,14 +186,6 @@ START:

// Unlock
return int(max), err

WAIT:
select {
case <-s.sendNotifyCh:
goto START
case <-s.writeDeadline.wait():
return 0, ErrTimeout
}
}

// sendFlags determines any flags that are appropriate
Expand Down