Documentation ¶
Overview ¶
Package udpsession is imported from https://github.com/xtaci/kcp-go
Index ¶
- Variables
- func DialWithOptionsReturnConn(ctx context.Context, network, laddr, raddr string, block cipher.BlockCipher) (net.Conn, error)
- func SetGlobalMTU(mtu int32)
- type Listener
- func (l *Listener) Accept() (net.Conn, error)
- func (l *Listener) Addr() net.Addr
- func (l *Listener) Close() error
- func (l *Listener) SetDSCP(dscp int) error
- func (l *Listener) SetDeadline(t time.Time) error
- func (l *Listener) SetReadDeadline(t time.Time) error
- func (l *Listener) SetWriteDeadline(t time.Time) error
- type UDPSession
- func (s *UDPSession) Close() error
- func (s *UDPSession) GetConv() uint32
- func (s *UDPSession) IsClient() bool
- func (s *UDPSession) IsServer() bool
- func (s *UDPSession) LocalAddr() net.Addr
- func (s *UDPSession) Read(b []byte) (n int, err error)
- func (s *UDPSession) RemoteAddr() net.Addr
- func (s *UDPSession) SetACKNoDelay(nodelay bool)
- func (s *UDPSession) SetDSCP(dscp int) error
- func (s *UDPSession) SetDeadline(t time.Time) error
- func (s *UDPSession) SetMtu(mtu int) bool
- func (s *UDPSession) SetPollIntervalMs(interval uint32)
- func (s *UDPSession) SetReadDeadline(t time.Time) error
- func (s *UDPSession) SetStreamMode(enable bool)
- func (s *UDPSession) SetWriteDeadline(t time.Time) error
- func (s *UDPSession) SetWriteDelay(delay bool)
- func (s *UDPSession) Write(b []byte) (n int, err error)
- func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
var ( // Number of KCP packet input errors. KCPInErrors = metrics.RegisterMetric("errors", "KCPInErrors") // Number of KCP packet receive errors. KCPReceiveErrors = metrics.RegisterMetric("errors", "KCPReceiveErrors") // Number of KCP packet send errors. KCPSendErrors = metrics.RegisterMetric("errors", "KCPSendErrors") // Number of UDP read errors. UDPInErrors = metrics.RegisterMetric("errors", "UDPInErrors") )
Functions ¶
func DialWithOptionsReturnConn ¶
func DialWithOptionsReturnConn(ctx context.Context, network, laddr, raddr string, block cipher.BlockCipher) (net.Conn, error)
DialWithOptionsReturnConn calls DialWithOptions and returns a generic net.Conn.
func SetGlobalMTU ¶ added in v1.5.0
func SetGlobalMTU(mtu int32)
SetGlobalMTU adjust the L2 MTU of all UDP sessions. It does nothing if the MTU value is out of range.
Types ¶
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener defines a server which will be waiting to accept incoming UDP connections.
func ListenWithOptions ¶
ListenWithOptions listens for incoming KCP packets addressed to the local address laddr on the network "udp" with packet encryption.
func (*Listener) SetDSCP ¶
SetDSCP sets the 6bit DSCP field in IPv4 header, or 8bit Traffic Class in IPv6 header.
func (*Listener) SetDeadline ¶
SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.
func (*Listener) SetReadDeadline ¶
SetReadDeadline implements the Conn SetReadDeadline method.
type UDPSession ¶
type UDPSession struct {
// contains filtered or unexported fields
}
UDPSession defines a KCP session implemented by UDP.
func DialWithOptions ¶
func DialWithOptions(ctx context.Context, network, laddr, raddr string, block cipher.BlockCipher) (*UDPSession, error)
DialWithOptions connects to the remote address "raddr" on the network "udp" with packet encryption. If "laddr" is empty, an automatic address is used. "block" is the block encryption algorithm to encrypt packets.
func (*UDPSession) Close ¶
func (s *UDPSession) Close() error
Close closes the connection.
To avoid deadlock, caller should never hold s.mu lock before calling this method.
func (*UDPSession) GetConv ¶
func (s *UDPSession) GetConv() uint32
GetConv gets conversation id of a session
func (*UDPSession) IsClient ¶
func (s *UDPSession) IsClient() bool
If this UDP session is owned by client.
func (*UDPSession) IsServer ¶
func (s *UDPSession) IsServer() bool
If this UDP session is owned by proxy server.
func (*UDPSession) LocalAddr ¶
func (s *UDPSession) 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 (*UDPSession) Read ¶
func (s *UDPSession) Read(b []byte) (n int, err error)
Read implements net.Conn
func (*UDPSession) RemoteAddr ¶
func (s *UDPSession) 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 (*UDPSession) SetACKNoDelay ¶
func (s *UDPSession) SetACKNoDelay(nodelay bool)
SetACKNoDelay changes ack flush option, set true to flush ack immediately.
func (*UDPSession) SetDSCP ¶
func (s *UDPSession) SetDSCP(dscp int) error
SetDSCP sets the 6bit DSCP field in IPv4 header, or 8bit Traffic Class in IPv6 header.
It has no effect if it's accepted from Listener.
func (*UDPSession) SetDeadline ¶
func (s *UDPSession) SetDeadline(t time.Time) error
SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.
func (*UDPSession) SetMtu ¶
func (s *UDPSession) SetMtu(mtu int) bool
SetMtu sets the maximum transmission unit (not including UDP header).
func (*UDPSession) SetPollIntervalMs ¶ added in v1.12.0
func (s *UDPSession) SetPollIntervalMs(interval uint32)
SetPollIntervalMs set KCP polling interval in milliseconds.
func (*UDPSession) SetReadDeadline ¶
func (s *UDPSession) SetReadDeadline(t time.Time) error
SetReadDeadline implements the Conn SetReadDeadline method.
func (*UDPSession) SetStreamMode ¶
func (s *UDPSession) SetStreamMode(enable bool)
SetStreamMode toggles the stream mode on/off.
func (*UDPSession) SetWriteDeadline ¶
func (s *UDPSession) SetWriteDeadline(t time.Time) error
SetWriteDeadline implements the Conn SetWriteDeadline method.
func (*UDPSession) SetWriteDelay ¶
func (s *UDPSession) SetWriteDelay(delay bool)
SetWriteDelay delays write for bulk transfer until the next update interval.
func (*UDPSession) Write ¶
func (s *UDPSession) Write(b []byte) (n int, err error)
Write implements net.Conn
func (*UDPSession) WriteBuffers ¶
func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error)
WriteBuffers write a vector of byte slices to the underlying connection