net

package
v0.0.0-...-00b2352 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ErrServerClosed = Error("server closed")

Variables

This section is empty.

Functions

func SetUDPSocketOptions

func SetUDPSocketOptions(conn *net.UDPConn) error

SetUDPSocketOptions set controls FlagDst,FlagInterface to UDPConn.

func WriteToSessionUDP

func WriteToSessionUDP(conn *net.UDPConn, session *ConnUDPContext, b []byte) (int, error)

WriteToSessionUDP acts just like net.UDPConn.WriteTo(), but uses a *SessionUDP instead of a net.Addr.

Types

type Conn

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

Conn is a generic stream-oriented network connection that provides Read/Write with context.

Multiple goroutines may invoke methods on a Conn simultaneously.

func NewConn

func NewConn(c net.Conn, heartBeat time.Duration) *Conn

NewConn creates connection over net.Conn.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) LocalAddr

func (c *Conn) 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 (*Conn) ReadFullWithContext

func (c *Conn) ReadFullWithContext(ctx context.Context, buffer []byte) error

ReadFullContext reads stream with context until whole buffer is satisfied.

func (*Conn) ReadWithContext

func (c *Conn) ReadWithContext(ctx context.Context, buffer []byte) (int, error)

ReadContext reads stream with context.

func (*Conn) RemoteAddr

func (c *Conn) 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 (*Conn) WriteWithContext

func (c *Conn) WriteWithContext(ctx context.Context, data []byte) error

WriteContext writes data with context.

type ConnDTLS

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

func NewConnDTLS

func NewConnDTLS(conn net.Conn) *ConnDTLS

func (*ConnDTLS) Close

func (c *ConnDTLS) Close() error

func (*ConnDTLS) LocalAddr

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

func (*ConnDTLS) Read

func (c *ConnDTLS) Read(b []byte) (n int, err error)

func (*ConnDTLS) RemoteAddr

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

func (*ConnDTLS) SetDeadline

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

func (*ConnDTLS) SetReadDeadline

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

func (*ConnDTLS) SetWriteDeadline

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

func (*ConnDTLS) Write

func (c *ConnDTLS) Write(b []byte) (n int, err error)

type ConnUDP

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

ConnUDP is a udp connection provides Read/Write with context.

Multiple goroutines may invoke methods on a ConnUDP simultaneously.

func NewConnUDP

func NewConnUDP(c *net.UDPConn, heartBeat time.Duration, multicastHopLimit int) *ConnUDP

NewConnUDP creates connection over net.UDPConn.

func (*ConnUDP) Close

func (c *ConnUDP) Close() error

Close closes the connection.

func (*ConnUDP) JoinGroup

func (c *ConnUDP) JoinGroup(ifi *net.Interface, group net.Addr) error

JoinGroup joins the group address group on the interface ifi. By default all sources that can cast data to group are accepted. It's possible to mute and unmute data transmission from a specific source by using ExcludeSourceSpecificGroup and IncludeSourceSpecificGroup. JoinGroup uses the system assigned multicast interface when ifi is nil, although this is not recommended because the assignment depends on platforms and sometimes it might require routing configuration.

func (*ConnUDP) LocalAddr

func (c *ConnUDP) 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 (*ConnUDP) ReadWithContext

func (c *ConnUDP) ReadWithContext(ctx context.Context, buffer []byte) (int, *ConnUDPContext, error)

ReadWithContext reads packet with context.

func (*ConnUDP) RemoteAddr

func (c *ConnUDP) 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 (*ConnUDP) SetMulticastLoopback

func (c *ConnUDP) SetMulticastLoopback(on bool) error

SetMulticastLoopback sets whether transmitted multicast packets should be copied and send back to the originator.

func (*ConnUDP) WriteWithContext

func (c *ConnUDP) WriteWithContext(ctx context.Context, udpCtx *ConnUDPContext, buffer []byte) error

WriteWithContext writes data with context.

type ConnUDPContext

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

ConnUDPContext holds the remote address and the associated out-of-band data.

func NewConnUDPContext

func NewConnUDPContext(raddr *net.UDPAddr, oob []byte) *ConnUDPContext

NewConnUDPContext creates conn udp context.

func ReadFromSessionUDP

func ReadFromSessionUDP(conn *net.UDPConn, b []byte) (int, *ConnUDPContext, error)

ReadFromSessionUDP acts just like net.UDPConn.ReadFrom(), but returns a session object instead of a net.UDPAddr.

func (*ConnUDPContext) Key

func (s *ConnUDPContext) Key() string

Key returns the key session for the map using

func (*ConnUDPContext) RemoteAddr

func (s *ConnUDPContext) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

type DTLSListener

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

DTLSListener is a DTLS listener that provides accept with context.

func NewDTLSListener

func NewDTLSListener(network string, addr string, cfg *dtls.Config, heartBeat time.Duration) (*DTLSListener, error)

NewDTLSListener creates dtls listener. Known networks are "udp", "udp4" (IPv4-only), "udp6" (IPv6-only).

func (*DTLSListener) Accept

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

Accept waits for a generic Conn.

func (*DTLSListener) AcceptWithContext

func (l *DTLSListener) AcceptWithContext(ctx context.Context) (net.Conn, error)

AcceptWithContext waits with context for a generic Conn.

func (*DTLSListener) Addr

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

Addr represents a network end point address.

func (*DTLSListener) Close

func (l *DTLSListener) Close() error

Close closes the connection.

func (*DTLSListener) SetDeadline

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

SetDeadline sets deadline for accept operation.

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type TCPListener

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

TCPListener is a TCP network listener that provides accept with context.

func NewTCPListener

func NewTCPListener(network string, addr string, heartBeat time.Duration) (*TCPListener, error)

NewTCPListener creates tcp listener. Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only).

func (*TCPListener) Accept

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

Accept waits for a generic Conn.

func (*TCPListener) AcceptWithContext

func (l *TCPListener) AcceptWithContext(ctx context.Context) (net.Conn, error)

AcceptContext waits with context for a generic Conn.

func (*TCPListener) Addr

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

Addr represents a network end point address.

func (*TCPListener) Close

func (l *TCPListener) Close() error

Close closes the connection.

func (*TCPListener) SetDeadline

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

SetDeadline sets deadline for accept operation.

type TLSListener

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

TLSListener is a TLS listener that provides accept with context.

func NewTLSListener

func NewTLSListener(network string, addr string, cfg *tls.Config, heartBeat time.Duration) (*TLSListener, error)

NewTLSListener creates tcp listener. Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only).

func (*TLSListener) Accept

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

Accept waits for a generic Conn.

func (*TLSListener) AcceptWithContext

func (l *TLSListener) AcceptWithContext(ctx context.Context) (net.Conn, error)

AcceptContext waits with context for a generic Conn.

func (*TLSListener) Addr

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

Addr represents a network end point address.

func (*TLSListener) Close

func (l *TLSListener) Close() error

Close closes the connection.

func (*TLSListener) SetDeadline

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

SetDeadline sets deadline for accept operation.

Jump to

Keyboard shortcuts

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