tcp

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2019 License: BSD-3-Clause Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultDNSCacheDuration = time.Minute

DefaultDNSCacheDuration is the duration for caching resolved TCP addresses by Dial* functions.

View Source
const (
	DefaultDialTimeout = 3 * time.Second
)

Variables

View Source
var ErrDialTimeout = errors.New("dialing to the given TCP address timed out")

ErrDialTimeout is returned when TCP dialing is timed out.

Functions

func Dial

func Dial(addr string) (net.Conn, error)

Dial dials the given TCP addr using tcp4.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DefaultDNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
  • It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialTimeout for customizing dial timeout.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func DialDualStack

func DialDualStack(addr string) (net.Conn, error)

DialDualStack dials the given TCP addr using both tcp4 and tcp6.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DefaultDNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
  • It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialDualStackTimeout for custom dial timeout.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func DialDualStackTimeout

func DialDualStackTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialDualStackTimeout dials the given TCP addr using both tcp4 and tcp6 using the given timeout.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DefaultDNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func DialTimeout

func DialTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialTimeout dials the given TCP addr using tcp4 using the given timeout.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DefaultDNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

Types

type Resolver

type Resolver interface {
	LookupIPAddr(context.Context, string) (names []net.IPAddr, err error)
}

type TCPDialer

type TCPDialer struct {
	// Concurrency controls the maximum number of concurrent Dails
	// that can be performed using this object.
	// Setting this to 0 means unlimited.
	//
	// WARNING: This can only be changed before the first Dial.
	// Changes made after the first Dial will not affect anything.
	Concurrency int

	// This may be used to override DNS resolving policy, like this:
	// var dialer = &http.TCPDialer{
	// 	Resolver: &net.Resolver{
	// 		PreferGo:     true,
	// 		StrictErrors: false,
	// 		Dial: func (ctx context.Context, network, address string) (net.Conn, error) {
	// 			d := net.Dialer{}
	// 			return d.DialContext(ctx, "udp", "8.8.8.8:53")
	// 		},
	// 	},
	// }
	Resolver Resolver
	// contains filtered or unexported fields
}

TCPDialer contains options to control a group of Dial calls.

func (*TCPDialer) Dial

func (d *TCPDialer) Dial(addr string) (net.Conn, error)

Dial dials the given TCP addr using tcp4.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DefaultDNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
  • It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialTimeout for customizing dial timeout.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func (*TCPDialer) DialDualStack

func (d *TCPDialer) DialDualStack(addr string) (net.Conn, error)

DialDualStack dials the given TCP addr using both tcp4 and tcp6.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DefaultDNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.
  • It returns ErrDialTimeout if connection cannot be established during DefaultDialTimeout seconds. Use DialDualStackTimeout for custom dial timeout.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func (*TCPDialer) DialDualStackTimeout

func (d *TCPDialer) DialDualStackTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialDualStackTimeout dials the given TCP addr using both tcp4 and tcp6 using the given timeout.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DefaultDNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

func (*TCPDialer) DialTimeout

func (d *TCPDialer) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)

DialTimeout dials the given TCP addr using tcp4 using the given timeout.

This function has the following additional features comparing to net.Dial:

  • It reduces load on DNS resolver by caching resolved TCP addressed for DefaultDNSCacheDuration.
  • It dials all the resolved TCP addresses in round-robin manner until connection is established. This may be useful if certain addresses are temporarily unreachable.

This dialer is intended for custom code wrapping before passing to Client.Dial or HostClient.Dial.

For instance, per-host counters and/or limits may be implemented by such wrappers.

The addr passed to the function must contain port. Example addr values:

  • foobar.baz:443
  • foo.bar:80
  • aaa.com:8080

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL