Skip to content

Commit

Permalink
Remove context from SendDatagram
Browse files Browse the repository at this point in the history
  • Loading branch information
chungthuang committed Dec 4, 2023
1 parent ee805af commit 6a30c0c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 34 deletions.
4 changes: 2 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,7 @@ func (s *connection) onStreamCompleted(id protocol.StreamID) {
}
}

func (s *connection) SendDatagram(ctx context.Context, p []byte) error {
func (s *connection) SendDatagram(p []byte) error {
if !s.supportsDatagrams() {
return errors.New("datagram support disabled")
}
Expand All @@ -2359,7 +2359,7 @@ func (s *connection) SendDatagram(ctx context.Context, p []byte) error {
}
f.Data = make([]byte, len(p))
copy(f.Data, p)
return s.datagramQueue.AddAndWait(ctx, f)
return s.datagramQueue.AddAndWait(f)
}

func (s *connection) ReceiveDatagram(ctx context.Context) ([]byte, error) {
Expand Down
10 changes: 3 additions & 7 deletions datagram_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ type datagramQueue struct {
}

type queuedDatagramFrame struct {
cancelChan <-chan struct{}
frame *wire.DatagramFrame
peekCount uint8
frame *wire.DatagramFrame
peekCount uint8
}

func newDatagramQueue(hasData func(), logger utils.Logger) *datagramQueue {
Expand All @@ -57,13 +56,10 @@ func newDatagramQueue(hasData func(), logger utils.Logger) *datagramQueue {
// It blocks until the frame has been dequeued.
func (h *datagramQueue) AddAndWait(f *wire.DatagramFrame) error {
frame := &queuedDatagramFrame{
cancelChan: ctx.Done(),
frame: f,
frame: f,
}

select {
case <-ctx.Done():
return dropDatagramCtxCancelledErr
case h.sendQueue <- frame:
h.hasData()
case <-h.closed:
Expand Down
18 changes: 0 additions & 18 deletions datagram_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ var _ = Describe("Datagram Queue", func() {
It("drop after peeking too many times", func() {
f := &wire.DatagramFrame{Data: []byte("foobar")}
errChan := make(chan error, 1)
ctx1, cancel1 := context.WithCancel(context.Background())

go func() {
defer GinkgoRecover()
Expand All @@ -84,23 +83,6 @@ var _ = Describe("Datagram Queue", func() {
Eventually(errChan).Should(Receive(Equal(&DatagramQueuedTooLong{})))
})

It("drop after peeking too many times", func() {
f := &wire.DatagramFrame{Data: []byte("foobar")}
errChan := make(chan error, 1)

go func() {
defer GinkgoRecover()
mtuDiscoverer.EXPECT().CurrentSize().Return(1234)
errChan <- queue.AddAndWait(context.Background(), f)
}()
Eventually(queued).Should(HaveLen(1))
for i := 0; i < int(maxPeekAttempt); i++ {
Expect(queue.Peek()).To(Equal(f))
}
Expect(queue.Peek()).To(BeNil())
Eventually(errChan).Should(Receive(Equal(dropDatagramCtxCancelledErr)))
})

It("closes", func() {
errChan := make(chan error, 1)
go func() {
Expand Down
2 changes: 1 addition & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type Connection interface {
ConnectionState() ConnectionState

// SendDatagram sends a message as a datagram, as specified in RFC 9221.
SendDatagram(context.Context, []byte) error
SendDatagram([]byte) error
// ReceiveDatagram gets a message received in a datagram, as specified in RFC 9221.
ReceiveDatagram(context.Context) ([]byte, error)
}
Expand Down
12 changes: 6 additions & 6 deletions mock_quic_conn_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a30c0c

Please sign in to comment.