Documentation
¶
Index ¶
- Constants
- Variables
- func NewAckPacket(tunnelID, seq, length uint32) *mpxPacket
- func NewHeartbeatPacket() *mpxPacket
- func NewRSTPacket(tunnID uint32, data []byte) *mpxPacket
- func NewSetWeightPacket(weight uint32) *mpxPacket
- func PacketFromReader(r io.Reader) (*mpxPacket, error)
- func ParseType(t uint8) packetType
- func Verbose(enable bool)
- type Conn
- type ConnPool
- func (p *ConnPool) Accept() (*Tunnel, error)
- func (p *ConnPool) AddConn(conn net.Conn) error
- func (p *ConnPool) AddConnWithWeight(conn net.Conn, weight uint32) error
- func (p *ConnPool) Addr() net.Addr
- func (p *ConnPool) Close() error
- func (p *ConnPool) ConnCount() int
- func (p *ConnPool) Connect(data []byte) (*Tunnel, error)
- func (p *ConnPool) Dial(data []byte) (*Tunnel, error)
- func (p *ConnPool) Serve() error
- func (p *ConnPool) ServeWithListener(lis net.Listener) error
- func (p *ConnPool) StartWithDialer(dialer Dialer, connNum int) (err error)
- type Dialer
- type Tunnel
- func (t *Tunnel) Close() error
- func (t *Tunnel) LastSeen() time.Time
- func (t *Tunnel) LocalAddr() net.Addr
- func (t *Tunnel) Read(buf []byte) (int, error)
- func (t *Tunnel) RemoteAddr() net.Addr
- func (t *Tunnel) RemoteClose()
- func (t *Tunnel) SetDeadline(ti time.Time) error
- func (t *Tunnel) SetReadDeadline(ti time.Time) error
- func (t *Tunnel) SetWriteDeadline(ti time.Time) error
- func (t *Tunnel) Write(b []byte) (n int, err error)
Constants ¶
const ( Connect packetType = iota Disconnect Data RST Heartbeat SetWeight ACK )
const ( Connected state = iota Closed )
Variables ¶
var (
ErrClosed = errors.New("closed")
)
var (
MaxCachedNum = 65535
)
Functions ¶
func NewAckPacket ¶
func NewAckPacket(tunnelID, seq, length uint32) *mpxPacket
func NewHeartbeatPacket ¶
func NewHeartbeatPacket() *mpxPacket
func NewRSTPacket ¶
func NewSetWeightPacket ¶
func NewSetWeightPacket(weight uint32) *mpxPacket
func PacketFromReader ¶
Types ¶
type ConnPool ¶
type ConnPool struct {
// contains filtered or unexported fields
}
ConnPool 是使用mpx主要用到的结构体 接受任何实现了 net.Conn 接口的连接作为输入 可以直接调用 AddConn 方法将Conn输入,也可以调用 ServeWithListener 输入一个 net.Listener ,调用 StartWithDialer 输入一个 dailer (mpx库中的一个interface)来使用mpx
func (*ConnPool) AddConnWithWeight ¶
func (*ConnPool) Close ¶
Close closes the listener. Any blocked Accept operations will be unblocked and return errors.
func (*ConnPool) Serve ¶
Serve 启用服务,适用于使用 AddConn 方法输入连接的情况下启用服务 如果已经调用 ServeWithListener 或 StartWithDialer,请勿调用该方法
func (*ConnPool) ServeWithListener ¶
ServeWithListener 启用服务,通过 net.Listener 输入连接 请勿和 Serve 同时调用
type Tunnel ¶
type Tunnel struct { ID uint32 // contains filtered or unexported fields }
func (*Tunnel) Close ¶
Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.
func (*Tunnel) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*Tunnel) RemoteClose ¶
func (t *Tunnel) RemoteClose()
func (*Tunnel) SetDeadline ¶
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.
An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.
A zero value for t means I/O operations will not time out.
Note that if a TCP connection has keep-alive turned on, which is the default unless overridden by Dialer.KeepAlive or ListenConfig.KeepAlive, then a keep-alive failure may also return a timeout error. On Unix systems a keep-alive failure on I/O can be detected using errors.Is(err, syscall.ETIMEDOUT).
func (*Tunnel) SetReadDeadline ¶
SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.
func (*Tunnel) SetWriteDeadline ¶
SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.