From 8b15be4a656d0f9cc0b55149fdf2d4d7de659fc0 Mon Sep 17 00:00:00 2001 From: Pedro Fialho Date: Thu, 25 Jan 2024 11:54:07 -0800 Subject: [PATCH] DialV2: add support for custom timeout --- bmc.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bmc.go b/bmc.go index 0851421..6373337 100644 --- a/bmc.go +++ b/bmc.go @@ -39,6 +39,10 @@ func Dial(_ context.Context, addr string) (SessionlessTransport, error) { // functionality. Note v4 is preferred to v6 if a hostname is passed returning // both A and AAAA records. func DialV2(addr string) (*V2SessionlessTransport, error) { + return DialV2WithCustomTimeout(addr, 1*time.Second) +} + +func DialV2WithCustomTimeout(addr string, timeout time.Duration) (*V2SessionlessTransport, error) { v2ConnectionOpenAttempts.Inc() t, err := newTransport(addr) if err != nil { @@ -46,13 +50,13 @@ func DialV2(addr string) (*V2SessionlessTransport, error) { return nil, err } v2ConnectionsOpen.Inc() - return newV2SessionlessTransport(t), nil + return newV2SessionlessTransport(t, timeout), nil } -func newV2SessionlessTransport(t transport.Transport) *V2SessionlessTransport { +func newV2SessionlessTransport(t transport.Transport, timeout time.Duration) *V2SessionlessTransport { return &V2SessionlessTransport{ Transport: t, - V2Sessionless: newV2Sessionless(t, time.Second), + V2Sessionless: newV2Sessionless(t, timeout), } }