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

Fix/poll deadline timeout #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ type pollDesc struct {

var pdPool = sync.Pool{
New: func() interface{} {
return &pollDesc{
desc := &pollDesc{
unblockRd: make(chan interface{}, 1),
unblockWr: make(chan interface{}, 1),
rdTimer: time.NewTimer(0),
wdTimer: time.NewTimer(0),
}
// creating timer with 0 duration makes it fire right away. Read the channel to prevent a false fire later
<-desc.rdTimer.C
<-desc.wdTimer.C
return desc
},
}

Expand Down Expand Up @@ -200,8 +204,8 @@ func (pd *pollDesc) setDeadline(t time.Time, mode PollMode) {
if mode == ModeRead || mode == ModeRead+ModeWrite {
pd.rdSeq++
pd.rtSeq = pd.rdSeq
if pd.rdDeadline > 0 {
pd.rdTimer.Stop()
if pd.rdDeadline > 0 && !pd.rdTimer.Stop() {
<-pd.rdTimer.C
}
pd.rdDeadline = d
if d > 0 {
Expand All @@ -214,8 +218,8 @@ func (pd *pollDesc) setDeadline(t time.Time, mode PollMode) {
if mode == ModeWrite || mode == ModeRead+ModeWrite {
pd.wdSeq++
pd.wtSeq = pd.wdSeq
if pd.wdDeadline > 0 {
pd.wdTimer.Stop()
if pd.wdDeadline > 0 && !pd.wdTimer.Stop() {
<-pd.wdTimer.C
}
pd.wdDeadline = d
if d > 0 {
Expand Down
4 changes: 3 additions & 1 deletion read.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func (s SrtSocket) Read(b []byte) (n int, err error) {
if !errors.Is(err, error(EAsyncRCV)) || s.blocking {
return
}
s.pd.wait(ModeRead)
if err = s.pd.wait(ModeRead); err != nil {
return
}
n, err = srtRecvMsg2Impl(s.socket, b, nil)
}
}
4 changes: 3 additions & 1 deletion write.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func (s SrtSocket) Write(b []byte) (n int, err error) {
if !errors.Is(err, error(EAsyncSND)) || s.blocking {
return
}
s.pd.wait(ModeWrite)
if err = s.pd.wait(ModeWrite); err != nil {
return
}
n, err = srtSendMsg2Impl(s.socket, b, nil)
}
}