srt

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

package srt provides a portable interface for SRT.

Although the package provides access to low-level SRT primitives, most clients will need only the basic interface provided by the Dial, Listen, and Accept functions and the associated Conn and Listener interfaces.

Index

Constants

This section is empty.

Variables

View Source
var DefaultResolver = &Resolver{nr: net.DefaultResolver}

DefaultResolver is the resolver used by the package-level Lookup functions and by Dialers without a specified Resolver.

Functions

func Dial

func Dial(network, address string) (net.Conn, error)

Dial connects to the address on the named network.

Known networks are "srt", "srt4" (IPv4-only), "srt6" (IPv6-only).

For SRT networks, the address has the form "host:port". The host must be a literal IP address, or a host name that can be resolved to IP addresses. The port must be a literal port number or a service name. If the host is a literal IPv6 address it must be enclosed in square brackets, as in "[2001:db8::1]:80" or "[fe80::1%zone]:80". The zone specifies the scope of the literal IPv6 address as defined in RFC 4007. The functions JoinHostPort and SplitHostPort manipulate a pair of host and port in this form. When using SRT, and the host resolves to multiple IP addresses, Dial will try each IP address in order until one succeeds.

Examples:

Dial("srt", "golang.org:1024")
Dial("srt", "198.51.100.1:1024")
Dial("srt", "[2001:db8::1]:domain")
Dial("srt", "[fe80::1%lo0]:53")
Dial("srt", ":1024")

For SRT networks, if the host is empty or a literal unspecified IP address, as in ":80", "0.0.0.0:80" or "[::]:80" for SRT, "", "0.0.0.0" or "::" for IP, the local system is assumed.

For Unix networks, the address must be a file system path.

func DialTimeout

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

DialTimeout acts like Dial but takes a timeout.

The timeout includes name resolution, if required. When using SRT, and the host in the address parameter resolves to multiple IP addresses, the timeout is spread over each consecutive dial, such that each is given an appropriate fraction of the time to connect.

See func Dial for a description of the network and address parameters.

func Listen

func Listen(network, address string) (net.Listener, error)

Listen announces on the local network address.

func ListenContext

func ListenContext(ctx context.Context, network, address string) (net.Listener, error)

ListenContext announces on the local network address.

The network must be "srt", "srt4", "srt6", "unix" or "unixpacket".

For SRT networks, if the host in the address parameter is empty or a literal unspecified IP address, Listen listens on all available unicast and anycast IP addresses of the local system. To only use IPv4, use network "srt4". The address can use a host name, but this is not recommended, because it will create a listener for at most one of the host's IP addresses. If the port in the address parameter is empty or "0", as in "127.0.0.1:" or "[::1]:0", a port number is automatically chosen. The Addr method of Listener can be used to discover the chosen port.

See func Dial for a description of the network and address parameters.

func Option

func Option(ctx context.Context, key string) (string, bool)

Option returns the value of the option with the given key on ctx, and a boolean indicating whether that option exists.

func SetLoggingHandler added in v0.2.0

func SetLoggingHandler(handler LoggingHandlerFunc)

SetLoggingHandler set logging handler

func Shutdown

func Shutdown()

Shutdown clean up srt library

func WithOptions

func WithOptions(ctx context.Context, options OptionSet) context.Context

WithOptions returns a new context.Context with the given options added. A option overwrites a prior option with the same key.

Types

type Dialer

type Dialer struct {
	// Timeout is the maximum amount of time a dial will wait for
	// a connect to complete. If Deadline is also set, it may fail
	// earlier.
	//
	// The default is no timeout.
	//
	// When using SRT and dialing a host name with multiple IP
	// addresses, the timeout may be divided between them.
	//
	// With or without a timeout, the operating system may impose
	// its own earlier timeout. For instance, SRT timeouts are
	// often around 3 minutes.
	Timeout time.Duration

	// Deadline is the absolute point in time after which dials
	// will fail. If Timeout is set, it may fail earlier.
	// Zero means no deadline, or dependent on the operating system
	// as with the Timeout option.
	Deadline time.Time

	// LocalAddr is the local address to use when dialing an
	// address. The address must be of a compatible type for the
	// network being dialed.
	// If nil, a local address is automatically chosen.
	LocalAddr net.Addr

	// DualStack enables RFC 6555-compliant "Happy Eyeballs"
	// dialing when the network is "srt" and the host in the
	// address parameter resolves to both IPv4 and IPv6 addresses.
	// This allows a client to tolerate networks where one address
	// family is silently broken.
	DualStack bool

	// FallbackDelay specifies the length of time to wait before
	// spawning a fallback connection, when DualStack is enabled.
	// If zero, a default delay of 300ms is used.
	FallbackDelay time.Duration

	// Resolver optionally specifies an alternate resolver to use.
	Resolver *Resolver
}

A Dialer contains options for connecting to an address.

The zero value for each field is equivalent to dialing without that option. Dialing with the zero value of Dialer is therefore equivalent to just calling the Dial function.

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial connects to the address on the named network.

See func Dial for a description of the network and address parameters.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connects to the address on the named network using the provided context.

The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.

When using SRT, and the host in the address parameter resolves to multiple network addresses, any dial timeout (from d.Timeout or ctx) is spread over each consecutive dial, such that each is given an appropriate fraction of the time to connect. For example, if a host has 4 IP addresses and the timeout is 1 minute, the connect to each single address will be given 15 seconds to complete before trying the next one.

See func Dial for a description of the network and address parameters.

type LoggingHandlerFunc added in v0.2.0

type LoggingHandlerFunc logging.HandlerFunc

type OpError

type OpError struct {
	// Op is the operation which caused the error, such as
	// "read" or "write".
	Op string

	// Net is the network type on which this error occurred,
	// such as "tcp" or "udp6".
	Net string

	// For operations involving a remote network connection, like
	// Dial, Read, or Write, Source is the corresponding local
	// network address.
	Source net.Addr

	// Addr is the network address for which this error occurred.
	// For local operations, like Listen or SetDeadline, Addr is
	// the address of the local endpoint being manipulated.
	// For operations involving a remote network connection, like
	// Dial, Read, or Write, Addr is the remote address of that
	// connection.
	Addr net.Addr

	// Err is the error that occurred during the operation.
	Err error
}

OpError is the error type usually returned by functions in the net package. It describes the operation, network type, and address of an error.

func (*OpError) Error

func (e *OpError) Error() string

func (*OpError) Temporary

func (e *OpError) Temporary() bool

func (*OpError) Timeout

func (e *OpError) Timeout() bool

type OptionSet

type OptionSet struct {
	// contains filtered or unexported fields
}

OptionSet is a set of options.

func Options

func Options(args ...string) OptionSet

Options takes an even number of strings representing key-value pairs and makes a OptionSet containing them. A option overwrites a prior option with the same key.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

A Resolver looks up names and numbers.

A nil *Resolver is equivalent to a zero Resolver.

func (*Resolver) LookupIPAddr

func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)

LookupIPAddr looks up host using the local resolver. It returns a slice of that host's IPv4 and IPv6 addresses.

func (*Resolver) LookupPort

func (r *Resolver) LookupPort(ctx context.Context, network, service string) (port int, err error)

LookupPort looks up the port for the given network and service.

type SRTAddr

type SRTAddr struct {
	IP   net.IP
	Port int
	Zone string // IPv6 scoped addressing zone
}

SRTAddr represents the address of a SRT end point.

func ResolveSRTAddr

func ResolveSRTAddr(network, address string) (*SRTAddr, error)

ResolveSRTAddr returns an address of SRT end point.

The network must be a SRT network name.

If the host in the address parameter is not a literal IP address or the port is not a literal port number, ResolveSRTAddr resolves the address to an address of SRT end point. Otherwise, it parses the address as a pair of literal IP address and port number. The address parameter can use a host name, but this is not recommended, because it will return at most one of the host name's IP addresses.

See func Dial for a description of the network and address parameters.

func (*SRTAddr) Network

func (a *SRTAddr) Network() string

Network returns the address's network name, "srt".

func (*SRTAddr) String

func (a *SRTAddr) String() string

type SRTConn

type SRTConn struct {
	// contains filtered or unexported fields
}

SRTConn is an implementation of the Conn interface for SRT network connections.

func DialSRT

func DialSRT(network string, laddr, raddr *SRTAddr) (*SRTConn, error)

DialSRT acts like Dial for SRT networks.

The network must be a SRT network name; see func Dial for details.

If laddr is nil, a local address is automatically chosen. If the IP field of raddr is nil or an unspecified IP address, the local system is assumed.

func (*SRTConn) Close

func (c *SRTConn) Close() error

Close closes the connection.

func (*SRTConn) LocalAddr

func (c *SRTConn) LocalAddr() net.Addr

LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.

func (*SRTConn) Read

func (c *SRTConn) Read(b []byte) (int, error)

Read implements the Conn Read method.

func (*SRTConn) ReadFrom

func (c *SRTConn) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements the io.ReaderFrom ReadFrom method.

func (*SRTConn) RemoteAddr

func (c *SRTConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.

func (*SRTConn) SetDeadline

func (c *SRTConn) SetDeadline(t time.Time) error

SetDeadline implements the Conn SetDeadline method.

func (*SRTConn) SetReadDeadline

func (c *SRTConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements the Conn SetReadDeadline method.

func (*SRTConn) SetWriteDeadline

func (c *SRTConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the Conn SetWriteDeadline method.

func (*SRTConn) Stats added in v0.2.0

func (c *SRTConn) Stats() map[string]interface{}

func (*SRTConn) StreamID

func (c *SRTConn) StreamID() (string, error)

StreamID return stream ID

func (*SRTConn) Write

func (c *SRTConn) Write(b []byte) (int, error)

Write implements the Conn Write method.

type SRTListener

type SRTListener struct {
	// contains filtered or unexported fields
}

SRTListener is a SRT network listener. Clients should typically use variables of type Listener instead of assuming SRT.

func ListenSRT

func ListenSRT(network string, laddr *SRTAddr) (*SRTListener, error)

ListenSRT acts like Listen for SRT networks.

The network must be a SRT network name; see func Dial for details.

If the IP field of laddr is nil or an unspecified IP address, ListenSRT listens on all available unicast and anycast IP addresses of the local system. If the Port field of laddr is 0, a port number is automatically chosen.

func (*SRTListener) Accept

func (l *SRTListener) Accept() (net.Conn, error)

Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.

func (*SRTListener) AcceptSRT

func (l *SRTListener) AcceptSRT() (*SRTConn, error)

AcceptSRT accepts the next incoming call and returns the new connection.

func (*SRTListener) Addr

func (l *SRTListener) Addr() net.Addr

Addr returns the listener's network address, a *SRTAddr. The Addr returned is shared by all invocations of Addr, so do not modify it.

func (*SRTListener) Close

func (l *SRTListener) Close() error

Close stops listening on the SRT address. Already Accepted connections are not closed.

func (*SRTListener) SetDeadline

func (l *SRTListener) SetDeadline(t time.Time) error

SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.

Jump to

Keyboard shortcuts

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