Skip to content

Commit

Permalink
Support write deadline for data channel
Browse files Browse the repository at this point in the history
When sctp BlockWrite is enabled, datachannel
can set deadline for Write.
  • Loading branch information
cnderrauber committed Dec 10, 2024
1 parent 6d24d74 commit 11fb983
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions datachannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ type Writer interface {
WriteDataChannel([]byte, bool) (int, error)
}

// WriterDeadliner extends an io.Writer to expose setting a write deadline.

Check failure on line 38 in datachannel.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: comment on exported type WriteDeadliner should be of the form "WriteDeadliner ..." (with optional leading article) (revive)
type WriteDeadliner interface {
SetWriteDeadline(time.Time) error
}

// ReadWriteCloser is an extended io.ReadWriteCloser
// that also implements our Reader and Writer.
type ReadWriteCloser interface {
Expand All @@ -45,6 +50,12 @@ type ReadWriteCloser interface {
io.Closer
}

type ReadWriteCloserDeadliner interface {

Check failure on line 53 in datachannel.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported type ReadWriteCloserDeadliner should have comment or be unexported (revive)
ReadWriteCloser
ReadDeadliner
WriteDeadliner
}

// DataChannel represents a data channel
type DataChannel struct {
Config
Expand Down Expand Up @@ -224,6 +235,12 @@ func (c *DataChannel) SetReadDeadline(t time.Time) error {
return c.stream.SetReadDeadline(t)
}

// SetWriteDeadline sets a deadline for writes to return,
// only available if the BlockWrite is enabled for sctp
func (c *DataChannel) SetWriteDeadline(t time.Time) error {
return c.stream.SetWriteDeadline(t)

Check warning on line 241 in datachannel.go

View check run for this annotation

Codecov / codecov/patch

datachannel.go#L240-L241

Added lines #L240 - L241 were not covered by tests
}

// MessagesSent returns the number of messages sent
func (c *DataChannel) MessagesSent() uint32 {
return atomic.LoadUint32(&c.messagesSent)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/pion/datachannel

require (
github.com/pion/logging v0.2.2
github.com/pion/sctp v1.8.34
github.com/pion/sctp v1.8.35
github.com/pion/transport/v3 v3.0.7
github.com/stretchr/testify v1.10.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
github.com/pion/sctp v1.8.34 h1:rCuD3m53i0oGxCSp7FLQKvqVx0Nf5AUAHhMRXTTQjBc=
github.com/pion/sctp v1.8.34/go.mod h1:yWkCClkXlzVW7BXfI2PjrUGBwUI0CjXJBkhLt+sdo4U=
github.com/pion/sctp v1.8.35 h1:qwtKvNK1Wc5tHMIYgTDJhfZk7vATGVHhXbUDfHbYwzA=
github.com/pion/sctp v1.8.35/go.mod h1:EcXP8zCYVTRy3W9xtOF7wJm1L1aXfKRQzaM33SjQlzg=
github.com/pion/transport/v3 v3.0.7 h1:iRbMH05BzSNwhILHoBoAPxoB9xQgOaJk+591KC9P1o0=
github.com/pion/transport/v3 v3.0.7/go.mod h1:YleKiTZ4vqNxVwh77Z0zytYi7rXHl7j6uPLGhhz9rwo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down

0 comments on commit 11fb983

Please sign in to comment.