Documentation
¶
Index ¶
- Constants
- Variables
- func KcpOutoput(ctx context.Context, ln *net.UDPConn, addr *net.UDPAddr) (f func([]byte, int))
- func KcpOutoputByConn(ctx context.Context, conn net.Conn) (f func([]byte, int))
- func KcpUpdata(ctx context.Context, conf KcpConfig)
- func SetReadWriteBuff(ctx context.Context, rwc io.ReadWriteCloser, read, write int) (err error)
- func UpdataAdd(c *Conn)
- func UpdataDel(c *Conn)
- type Conn
- type KcpCli
- type KcpConfig
- type QuicConn
- type UdpConn
- type UdpConnCli
- type Zip
Constants ¶
View Source
const (
UdpBufLen = 1472 //UDP发送、接收,kcp发送、接收缓冲的大小
)
IP协议规定路由器最少能转发:512数据+60IP首部最大+4预留=576字节,即最少可以转发512-8=504字节UDP数据 内网一般1500字节,UDP:1500-IP(20)-UDP(8)=1472字节数据
Variables ¶
View Source
var ( ErrDecoderClosed = zstd.ErrDecoderClosed ErrUnexpectedEOF = io.ErrUnexpectedEOF )
View Source
var (
ErrBufferTooSmall = errors.NewCode(0, 10001, "buffer is too small")
)
Functions ¶
func KcpOutoput ¶
kcp send()之后,会在flush()的时候调用这里的函数,将数据包通过udp 发送出去
func KcpOutoputByConn ¶
func SetReadWriteBuff ¶
SetReadWriteBuff 设置 conn 读写缓存的大小
Types ¶
type Conn ¶
type Conn struct {
Addr *net.UDPAddr //只在创建的时候写入,其他时候只读,所以不加锁读
KCP *kcp.KCP //kcp线程不安全,所以必须加锁
RefleshTime int64 //每次收到数据包,就更新这个时间,在kcp_updata()的时候检查这个时间,超时则删除
M int // KCP 是否又可接收的完整数据
*sync.Mutex //kcp操作锁,因为有可能并发创建kcp,所以必须在Conn创建之初创建锁
// contains filtered or unexported fields
}
Conn 每条连接建立一个Conn
type KcpCli ¶
type KcpCli struct {
net.Conn
ID int
KCP *kcp.KCP //kcp线程不安全,所以必须加锁
RefleshTime int64 //每次收到数据包,就更新这个时间,在kcp_updata()的时候检查这个时间,超时则删除
M int // KCP 是否又可接收的完整数据
*sync.Mutex //kcp操作锁,因为有可能并发创建kcp,所以必须在Conn创建之初创建锁
// contains filtered or unexported fields
}
KcpCli 每条连接建立一个Conn
type UdpConn ¶
type UdpConn struct {
Addr *net.UDPAddr //只在创建的时候写入,其他时候只读,所以不加锁读
ChRead chan []byte
sync.Mutex //kcp操作锁,因为有可能并发创建kcp,所以必须在Conn创建之初创建锁
W sync.Mutex //kcp操作锁,因为有可能并发创建kcp,所以必须在Conn创建之初创建锁
// contains filtered or unexported fields
}
UdpConn 每条连接建立一个Conn
type UdpConnCli ¶
type UdpConnCli struct {
Conn net.Conn
sync.Mutex //kcp操作锁,因为有可能并发创建kcp,所以必须在Conn创建之初创建锁
W sync.Mutex //kcp操作锁,因为有可能并发创建kcp,所以必须在Conn创建之初创建锁
// contains filtered or unexported fields
}
UdpConn 每条连接建立一个Conn
func (*UdpConnCli) Close ¶
func (c *UdpConnCli) Close() error
Click to show internal directories.
Click to hide internal directories.