xtcp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: MIT Imports: 15 Imported by: 8

Documentation

Index

Constants

View Source
const MaxConnNotLimit = -1

Variables

This section is empty.

Functions

func CanProxy

func CanProxy(addr string) bool

func Dial

func Dial(ctx context.Context, network, addr string) (c net.Conn, err error)

func GetVarValue

func GetVarValue(object VarObject, name string) (value string, ok bool)

func NetListen

func NetListen(listen *Listen) (net.Listener, error)

func NetListenConcurrent

func NetListenConcurrent(ctx context.Context, ln net.Listener,
	maxConnection ConnectionNum) (l net.Listener, err error)

func NetListenConcurrentAndName

func NetListenConcurrentAndName(ctx context.Context, ln net.Listener,
	maxConnection ConnectionNum, name string) (l net.Listener, err error)

func NetListenTLS

func NetListenTLS(ln net.Listener, file *TlsFile) (l net.Listener, err error)

func StartAndBlock

func StartAndBlock(name string, config *Net, handler func(conn *Conn))

Deprecated

Types

type Conn

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

func NewConn

func NewConn(ctx context.Context, c net.Conn) *Conn

主要使用在client dial后的net.Conn 生成新的xtcp.Conn

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Context

func (c *Conn) Context() context.Context

func (*Conn) GetVar

func (c *Conn) GetVar(name string) (value string, ok bool)

func (*Conn) Id

func (c *Conn) Id() connid.Id

func (*Conn) Write

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

func (*Conn) WriteBuffers

func (c *Conn) WriteBuffers(buffers net.Buffers) (n int, err error)

对于不支持 writev 的系统,将会使用 循环的方式,为了保证 buffer 是一个整体被写入,所以加一个同步

type ConnectionNum

type ConnectionNum int64

func (ConnectionNum) Value

func (n ConnectionNum) Value() int64

type Handler

type Handler interface {
	Handle(conn *Conn)
}

type HandlerFun

type HandlerFun func(conn *Conn)

func (HandlerFun) Handle

func (h HandlerFun) Handle(conn *Conn)

type Listen

type Listen string

func (*Listen) CanTLS

func (l *Listen) CanTLS() bool

func (*Listen) LogString

func (l *Listen) LogString() string

func (*Listen) Network

func (l *Listen) Network() string

func (*Listen) On

func (l *Listen) On() bool

func (*Listen) String

func (l *Listen) String() string

能直接使用在net.Listen()的字符串

type Net

type Net struct {
	Listen         Listen        `conf:",1、xxx.xxx.xxx.xxx:[0-9] 2、:[0-9] 3、pipe:[0-9] 4、unix:|xxx|xxx|xxx|xxx.socket:0"`
	MaxConnections ConnectionNum `conf:",-1:not limit"`
	TLS            bool
	TlsFile        TlsFile
}

func DefaultNetConfig

func DefaultNetConfig() *Net

type Server

type Server struct {
	Net     *Net
	Handler Handler
	Name    string
}

func (*Server) ServeAndBlock

func (s *Server) ServeAndBlock()

type TlsFile

type TlsFile struct {
	PrivateKeyPEMFile string `conf:",support relative path, must PEM encode data"`
	CertPEMFile       string `conf:",support relative path, must PEM encode data"`
}

func (*TlsFile) RealCertFile

func (t *TlsFile) RealCertFile() string

func (*TlsFile) RealKeyFile

func (t *TlsFile) RealKeyFile() string

type VarObject

type VarObject interface {
	RemoteAddr() net.Addr
	LocalAddr() net.Addr
}

Jump to

Keyboard shortcuts

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