diff --git a/mock_sender_test.go b/mock_sender_test.go index ee38ab6c..e396c6d2 100644 --- a/mock_sender_test.go +++ b/mock_sender_test.go @@ -10,6 +10,7 @@ package quic import ( + net "net" reflect "reflect" protocol "github.com/quic-go/quic-go/internal/protocol" @@ -188,6 +189,42 @@ func (c *MockSenderSendCall) DoAndReturn(f func(*packetBuffer, uint16, protocol. return c } +// SendProbe mocks base method. +func (m *MockSender) SendProbe(arg0 *packetBuffer, arg1 net.Addr) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SendProbe", arg0, arg1) +} + +// SendProbe indicates an expected call of SendProbe. +func (mr *MockSenderMockRecorder) SendProbe(arg0, arg1 any) *MockSenderSendProbeCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendProbe", reflect.TypeOf((*MockSender)(nil).SendProbe), arg0, arg1) + return &MockSenderSendProbeCall{Call: call} +} + +// MockSenderSendProbeCall wrap *gomock.Call +type MockSenderSendProbeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSenderSendProbeCall) Return() *MockSenderSendProbeCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSenderSendProbeCall) Do(f func(*packetBuffer, net.Addr)) *MockSenderSendProbeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSenderSendProbeCall) DoAndReturn(f func(*packetBuffer, net.Addr)) *MockSenderSendProbeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + // WouldBlock mocks base method. func (m *MockSender) WouldBlock() bool { m.ctrl.T.Helper() diff --git a/send_queue.go b/send_queue.go index bde02334..d19762be 100644 --- a/send_queue.go +++ b/send_queue.go @@ -1,9 +1,14 @@ package quic -import "github.com/quic-go/quic-go/internal/protocol" +import ( + "net" + + "github.com/quic-go/quic-go/internal/protocol" +) type sender interface { Send(p *packetBuffer, gsoSize uint16, ecn protocol.ECN) + SendProbe(*packetBuffer, net.Addr) Run() error WouldBlock() bool Available() <-chan struct{} @@ -57,6 +62,10 @@ func (h *sendQueue) Send(p *packetBuffer, gsoSize uint16, ecn protocol.ECN) { } } +func (h *sendQueue) SendProbe(p *packetBuffer, addr net.Addr) { + h.conn.WriteTo(p.Data, addr) +} + func (h *sendQueue) WouldBlock() bool { return len(h.queue) == sendQueueCapacity } diff --git a/send_queue_test.go b/send_queue_test.go index d8d903b5..623a8149 100644 --- a/send_queue_test.go +++ b/send_queue_test.go @@ -2,6 +2,7 @@ package quic import ( "errors" + "net" "testing" "time" @@ -170,3 +171,13 @@ func TestSendQueueWriteError(t *testing.T) { t.Fatal("timeout") } } + +func TestSendQueueSendProbe(t *testing.T) { + mockCtrl := gomock.NewController(t) + c := NewMockSendConn(mockCtrl) + q := newSendQueue(c) + + addr := &net.UDPAddr{IP: net.IPv4(42, 42, 42, 42), Port: 42} + c.EXPECT().WriteTo([]byte("foobar"), addr) + q.SendProbe(getPacketWithContents([]byte("foobar")), addr) +}