package net
import "github.com/plgd-dev/go-coap/v3/net"
Index ¶
- Variables
- func IsCancelOrCloseError(err error) bool
- func IsConnectionBrokenError(err error) bool
- func IsIPv6(addr net.IP) bool
- type Conn
- func NewConn(c net.Conn) *Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) NetConn() net.Conn
- func (c *Conn) ReadFullWithContext(ctx context.Context, buffer []byte) error
- func (c *Conn) ReadWithContext(ctx context.Context, buffer []byte) (int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) WriteWithContext(ctx context.Context, data []byte) error
- type ContextOption
- func WithContext(ctx context.Context) ContextOption
- func (o ContextOption) ApplyRead(cfg *UDPReadCfg)
- func (o ContextOption) ApplyWrite(cfg *UDPWriteCfg)
- type ControlMessage
- type DTLSListener
- func NewDTLSListener(network string, addr string, dtlsCfg *dtls.Config) (*DTLSListener, error)
- func (l *DTLSListener) Accept() (net.Conn, error)
- func (l *DTLSListener) AcceptWithContext(ctx context.Context) (net.Conn, error)
- func (l *DTLSListener) Addr() net.Addr
- func (l *DTLSListener) Close() error
- type ErrorsOpt
- type InterfaceError
- type MulticastHoplimitOpt
- type MulticastInterfaceErrorOpt
- type MulticastInterfaceMode
- type MulticastInterfaceModeOpt
- type MulticastInterfaceOpt
- type MulticastOption
- func WithAllMulticastInterface() MulticastOption
- func WithAnyMulticastInterface() MulticastOption
- func WithMulticastHoplimit(hoplimit int) MulticastOption
- func WithMulticastInterface(iface net.Interface) MulticastOption
- func WithMulticastInterfaceError(interfaceError InterfaceError) MulticastOption
- func WithMulticastSource(source net.IP) MulticastOption
- type MulticastOptions
- type MulticastSourceOpt
- type ReadWriteOptionHandler
- func (o ReadWriteOptionHandler[F]) ApplyRead(cfg *UDPReadCfg)
- func (o ReadWriteOptionHandler[F]) ApplyWrite(cfg *UDPWriteCfg)
- type TCPListener
- func NewTCPListener(network string, addr string) (*TCPListener, error)
- func (l *TCPListener) Accept() (net.Conn, error)
- func (l *TCPListener) AcceptWithContext(ctx context.Context) (net.Conn, error)
- func (l *TCPListener) Addr() net.Addr
- func (l *TCPListener) Close() error
- type TLSListener
- func NewTLSListener(network string, addr string, tlsCfg *tls.Config) (*TLSListener, error)
- func (l *TLSListener) Accept() (net.Conn, error)
- func (l *TLSListener) AcceptWithContext(ctx context.Context) (net.Conn, error)
- func (l *TLSListener) Addr() net.Addr
- func (l *TLSListener) Close() error
- type UDPConn
- func NewListenUDP(network, addr string, opts ...UDPOption) (*UDPConn, error)
- func NewUDPConn(network string, c *net.UDPConn, opts ...UDPOption) *UDPConn
- func (c *UDPConn) Close() error
- func (c *UDPConn) JoinGroup(ifi *net.Interface, group net.Addr) error
- func (c *UDPConn) LeaveGroup(ifi *net.Interface, group net.Addr) error
- func (c *UDPConn) LocalAddr() net.Addr
- func (c *UDPConn) NetConn() net.Conn
- func (c *UDPConn) Network() string
- func (c *UDPConn) ReadWithContext(ctx context.Context, buffer []byte) (int, *net.UDPAddr, error)
- func (c *UDPConn) ReadWithOptions(buffer []byte, opts ...UDPReadOption) (int, error)
- func (c *UDPConn) RemoteAddr() net.Addr
- func (c *UDPConn) SetMulticastLoopback(on bool) error
- func (c *UDPConn) WriteMulticast(ctx context.Context, raddr *net.UDPAddr, buffer []byte, opts ...MulticastOption) error
- func (c *UDPConn) WriteWithContext(ctx context.Context, raddr *net.UDPAddr, buffer []byte) error
- func (c *UDPConn) WriteWithOptions(buffer []byte, opts ...UDPWriteOption) error
- type UDPConnConfig
- type UDPOption
- type UDPReadApplyFunc
- type UDPReadCfg
- type UDPReadOption
- func WithGetControlMessage(cm **ControlMessage) UDPReadOption
- func WithGetRemoteAddr(raddr **net.UDPAddr) UDPReadOption
- type UDPWriteApplyFunc
- type UDPWriteCfg
- type UDPWriteOption
Variables ¶
var ( ErrListenerIsClosed = io.EOF ErrConnectionIsClosed = io.EOF ErrWriteInterrupted = errors.New("only part data was written to socket") )
var DefaultUDPConnConfig = UDPConnConfig{ Errors: func(error) { }, }
Functions ¶
func IsCancelOrCloseError ¶
func IsConnectionBrokenError ¶
Check if error returned by operation on a socket failed because the other side has closed the connection.
func IsIPv6 ¶
IsIPv6 return's true if addr is IPV6.
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 ¶
NewConn creates connection over net.Conn.
func (*Conn) Close ¶
Close closes the connection.
func (*Conn) LocalAddr ¶
LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.
func (*Conn) NetConn ¶
NetConn returns the underlying connection that is wrapped by c. The Conn returned is shared by all invocations of Connection, so do not modify it.
func (*Conn) ReadFullWithContext ¶
ReadFullWithContext reads stream with context until whole buffer is satisfied.
func (*Conn) ReadWithContext ¶
ReadWithContext reads stream with context.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.
func (*Conn) WriteWithContext ¶
WriteWithContext writes data with context.
type ContextOption ¶
func WithContext ¶
func WithContext(ctx context.Context) ContextOption
WithContext sets the context of operation.
func (ContextOption) ApplyRead ¶
func (o ContextOption) ApplyRead(cfg *UDPReadCfg)
func (ContextOption) ApplyWrite ¶
func (o ContextOption) ApplyWrite(cfg *UDPWriteCfg)
type ControlMessage ¶
type ControlMessage struct { Dst net.IP // destination address of the packet Src net.IP // source address of the packet IfIndex int // interface index, 0 means any interface }
func (*ControlMessage) GetIfIndex ¶
func (c *ControlMessage) GetIfIndex() int
GetIfIndex returns the interface index of the network interface. 0 means no interface index specified.
func (*ControlMessage) String ¶
func (c *ControlMessage) String() string
type DTLSListener ¶
type DTLSListener struct {
// contains filtered or unexported fields
}
DTLSListener is a DTLS listener that provides accept with context.
func NewDTLSListener ¶
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 ¶
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.
type ErrorsOpt ¶
type ErrorsOpt struct {
// contains filtered or unexported fields
}
func WithErrors ¶
func (ErrorsOpt) ApplyUDP ¶
func (h ErrorsOpt) ApplyUDP(o *UDPConnConfig)
type InterfaceError ¶
type MulticastHoplimitOpt ¶
type MulticastHoplimitOpt struct {
// contains filtered or unexported fields
}
type MulticastInterfaceErrorOpt ¶
type MulticastInterfaceErrorOpt struct {
// contains filtered or unexported fields
}
type MulticastInterfaceMode ¶
type MulticastInterfaceMode int
const ( MulticastAllInterface MulticastInterfaceMode = 0 MulticastAnyInterface MulticastInterfaceMode = 1 MulticastSpecificInterface MulticastInterfaceMode = 2 )
type MulticastInterfaceModeOpt ¶
type MulticastInterfaceModeOpt struct {
// contains filtered or unexported fields
}
type MulticastInterfaceOpt ¶
type MulticastInterfaceOpt struct {
// contains filtered or unexported fields
}
type MulticastOption ¶
type MulticastOption interface {
// contains filtered or unexported methods
}
A MulticastOption sets options such as hop limit, etc.
func WithAllMulticastInterface ¶
func WithAllMulticastInterface() MulticastOption
func WithAnyMulticastInterface ¶
func WithAnyMulticastInterface() MulticastOption
func WithMulticastHoplimit ¶
func WithMulticastHoplimit(hoplimit int) MulticastOption
func WithMulticastInterface ¶
func WithMulticastInterface(iface net.Interface) MulticastOption
func WithMulticastInterfaceError ¶
func WithMulticastInterfaceError(interfaceError InterfaceError) MulticastOption
WithMulticastInterfaceError sets the callback for interface errors. If it is set error is not propagated as result of WriteMulticast.
func WithMulticastSource ¶
func WithMulticastSource(source net.IP) MulticastOption
type MulticastOptions ¶
type MulticastOptions struct { IFaceMode MulticastInterfaceMode Iface *net.Interface Source *net.IP HopLimit int InterfaceError InterfaceError }
func DefaultMulticastOptions ¶
func DefaultMulticastOptions() MulticastOptions
func (*MulticastOptions) Apply ¶
func (m *MulticastOptions) Apply(o MulticastOption)
type MulticastSourceOpt ¶
type MulticastSourceOpt struct {
// contains filtered or unexported fields
}
type ReadWriteOptionHandler ¶
type ReadWriteOptionHandler[F UDPWriteApplyFunc | UDPReadApplyFunc] struct { Func F }
func (ReadWriteOptionHandler[F]) ApplyRead ¶
func (o ReadWriteOptionHandler[F]) ApplyRead(cfg *UDPReadCfg)
func (ReadWriteOptionHandler[F]) ApplyWrite ¶
func (o ReadWriteOptionHandler[F]) ApplyWrite(cfg *UDPWriteCfg)
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) (*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 ¶
AcceptWithContext 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.
type TLSListener ¶
type TLSListener struct {
// contains filtered or unexported fields
}
TLSListener is a TLS listener that provides accept with context.
func NewTLSListener ¶
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 ¶
AcceptWithContext 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.
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is a udp connection provides Read/Write with context.
Multiple goroutines may invoke methods on a UDPConn simultaneously.
func NewListenUDP ¶
func NewUDPConn ¶
NewUDPConn creates connection over net.UDPConn.
func (*UDPConn) Close ¶
Close closes the connection.
func (*UDPConn) JoinGroup ¶
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 (*UDPConn) LeaveGroup ¶
LeaveGroup leaves the group address group on the interface ifi regardless of whether the group is any-source group or source-specific group.
func (*UDPConn) LocalAddr ¶
LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.
func (*UDPConn) NetConn ¶
NetConn returns the underlying connection that is wrapped by c. The Conn returned is shared by all invocations of NetConn, so do not modify it.
func (*UDPConn) Network ¶
Network name of the network (for example, udp4, udp6, udp)
func (*UDPConn) ReadWithContext ¶
ReadWithContext reads packet with context.
func (*UDPConn) ReadWithOptions ¶
func (c *UDPConn) ReadWithOptions(buffer []byte, opts ...UDPReadOption) (int, error)
ReadWithOptions reads packet with options. Via opts you can get also the remote address and control message.
func (*UDPConn) RemoteAddr ¶
RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.
func (*UDPConn) SetMulticastLoopback ¶
SetMulticastLoopback sets whether transmitted multicast packets should be copied and send back to the originator.
func (*UDPConn) WriteMulticast ¶
func (c *UDPConn) WriteMulticast(ctx context.Context, raddr *net.UDPAddr, buffer []byte, opts ...MulticastOption) error
WriteMulticast sends multicast to the remote multicast address. By default it is sent over all network interfaces and all compatible source IP addresses with hop limit 1. Via opts you can specify the network interface, source IP address, and hop limit.
func (*UDPConn) WriteWithContext ¶
WriteWithContext writes data with context.
func (*UDPConn) WriteWithOptions ¶
func (c *UDPConn) WriteWithOptions(buffer []byte, opts ...UDPWriteOption) error
WriteWithOptions writes data with options. Via opts you can specify the remote address and control message.
type UDPConnConfig ¶
type UDPConnConfig struct { Errors func(err error) }
type UDPOption ¶
type UDPOption interface { ApplyUDP(*UDPConnConfig) }
A UDPOption sets options such as errors parameters, etc.
type UDPReadApplyFunc ¶
type UDPReadApplyFunc func(cfg *UDPReadCfg)
type UDPReadCfg ¶
type UDPReadCfg struct { Ctx context.Context RemoteAddr **net.UDPAddr ControlMessage **ControlMessage }
func (*UDPReadCfg) ApplyRead ¶
func (c *UDPReadCfg) ApplyRead(cfg *UDPReadCfg)
type UDPReadOption ¶
type UDPReadOption interface { ApplyRead(cfg *UDPReadCfg) }
func WithGetControlMessage ¶
func WithGetControlMessage(cm **ControlMessage) UDPReadOption
WithGetControlMessage fills the control message when reading succeeds.
func WithGetRemoteAddr ¶
func WithGetRemoteAddr(raddr **net.UDPAddr) UDPReadOption
WithGetRemoteAddr fills the remote address when reading succeeds.
type UDPWriteApplyFunc ¶
type UDPWriteApplyFunc func(cfg *UDPWriteCfg)
type UDPWriteCfg ¶
type UDPWriteCfg struct { Ctx context.Context RemoteAddr *net.UDPAddr ControlMessage *ControlMessage }
func (*UDPWriteCfg) ApplyWrite ¶
func (c *UDPWriteCfg) ApplyWrite(cfg *UDPWriteCfg)
type UDPWriteOption ¶
type UDPWriteOption interface { ApplyWrite(cfg *UDPWriteCfg) }
func WithControlMessage ¶
func WithControlMessage(cm *ControlMessage) UDPWriteOption
WithControlMessage sets the control message to packet.
func WithRemoteAddr ¶
func WithRemoteAddr(raddr *net.UDPAddr) UDPWriteOption
WithRemoteAddr sets the remote address to packet.
Source Files ¶
conn.go connUDP.go dtlslistener.go error.go error_unix.go options.go supportsOverrideRemoteAddr.go tcplistener.go tlslistener.go
Directories ¶
Path | Synopsis |
---|---|
net/blockwise | |
net/client | |
net/client/limitParallelRequests | |
net/monitor | |
net/monitor/inactivity | |
net/observation | |
net/responsewriter |
- Version
- v3.3.6 (latest)
- Published
- Sep 18, 2024
- Platform
- linux/amd64
- Imports
- 14 packages
- Last checked
- 1 week ago –
Tools for package owners.