Haivision / srtgo

Go bindings for SRT. Advantages of SRT technology for an easy to use programming language
Mozilla Public License 2.0
185 stars 52 forks source link

Add various fixes for SetDeadline functionality #70

Closed nlon982 closed 5 months ago

nlon982 commented 5 months ago

As per https://github.com/Haivision/srtgo/pull/63 (and https://github.com/Haivision/srtgo/pull/58, but the fixes aren't as nice)...

SetDeadline has a few silly mistakes:

Issue 1) When the poll descriptor is created, it is with a duration of 0, which causes the deadline timer to fire right away and that's waiting the next time a deadline is set up. Issue 2) If there is a delay between setting up deadlines, and the timer fired after the poll.Wait() had returned, that timer signal is not cleared from the channel and will cause wait to return immediately. Issue 3) The return value from poll.Wait() is not checked in the Read and Write functions, which will cause a Read to hang if there is no data on the socket

Example of 1:

socket, socketCreateErr = srtgo.NewSrtSocket(s.host, s.port, s.options)

spa.socket.SetWriteDeadline() // Use deadline

err := socket.Connect() // Will return immediately, because the deadline timer fires immediately

Example of 3:

socket, socketCreateErr = srtgo.NewSrtSocket(s.host, s.port, s.options)
err := socket.Connect()

socket.ReadPacket(srtPacket) // Will wait forever, because there isn't actually a check if the deadline has been met.

As per my experiments...

Issue 4) SetWriteDeadline is currently equivalent to both SetReadDeadline and SetWriteDeadline, due to a silly mistake.