tcp

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBufferSize = 4096
)

Variables

This section is empty.

Functions

func HandleSignals

func HandleSignals(onTrapped func(s os.Signal)) (waiter func())

func NewRingBuffer

func NewRingBuffer(size int64) *ringbuf.RingBuffer

NewRingBuffer will allocate, initialize, and return a ring buffer with the specified size.

func StopServer

func StopServer(s *Server)

Types

type Client

type Client struct {
	CmdrTlsConfig *tls.CmdrTlsConfig
	// contains filtered or unexported fields
}

func NewClient

func NewClient(addr string, opts ...ClientOpt) *Client

func (*Client) Close

func (s *Client) Close()

func (*Client) IsClosed

func (s *Client) IsClosed() bool

func (*Client) Send

func (s *Client) Send(data []byte)

type ClientOpt

type ClientOpt func(*Client)

func WithClientOnConnectedFunc

func WithClientOnConnectedFunc(fn OnTcpConnectedFunc) ClientOpt

func WithClientOnDisconnectedFunc

func WithClientOnDisconnectedFunc(fn OnTcpDisconnectedFunc) ClientOpt

func WithClientOnProcessFunc

func WithClientOnProcessFunc(fn OnTcpProcessFunc) ClientOpt

func WithClientReadBufferSize

func WithClientReadBufferSize(size int) ClientOpt

func WithClientTlsConfig

func WithClientTlsConfig(s *tls.CmdrTlsConfig) ClientOpt

type OnTcpConnectedFunc

type OnTcpConnectedFunc func(c *Client, conn net.Conn)

type OnTcpDisconnectedFunc

type OnTcpDisconnectedFunc func(c *Client)

type OnTcpProcessFunc

type OnTcpProcessFunc func(buf []byte, in *bufio.Reader, out *bufio.Writer) (nn int, err error)

type OnTcpServerConnectedWithClient

type OnTcpServerConnectedWithClient func(ss *Server, conn net.Conn)

type OnTcpServerCreateReadWriter

type OnTcpServerCreateReadWriter func(ss *Server, conn net.Conn, tsConnected time.Time) (in io.Reader, out io.Writer)

type OnTcpServerDisconnectedWithClient

type OnTcpServerDisconnectedWithClient func(ss *Server, conn net.Conn, reader io.Reader)

type OnTcpServerListening

type OnTcpServerListening func(ss *Server, l net.Listener)

type OnTcpServerProcessFunc

type OnTcpServerProcessFunc func(buf []byte, in io.Reader, out io.Writer) (nn int, err error)

type Processor

type Processor interface {
	// Process implements Processor interface to announce that i will process the incoming data in Read().
	Process(buf []byte, in io.Reader, out io.Writer) (nn int, err error)
}

Processor 代表在reader处理读取到到报文的同时会立即进行报文的处理。

Reader负责从读取的报文数据块中按照协议进行分包,切分成功 的包(Packet)将被Processor所处理以完成业务逻辑。

如果Reader并未实现Processor接口,Server将会把识别到到 包交给 OnTcpServerProcessFunc 去处理。

type Server

type Server struct {
	CmdrTlsConfig *tls.CmdrTlsConfig
	// contains filtered or unexported fields
}

func StartServer

func StartServer(addr string, opts ...ServerOpt) *Server

func (*Server) Close

func (s *Server) Close() (err error)

func (*Server) Start

func (s *Server) Start() (err error)

func (*Server) Stop

func (s *Server) Stop()

type ServerOpt

type ServerOpt func(*Server)

func WithServerBufferSize

func WithServerBufferSize(size int) ServerOpt

func WithServerConnectedWithClient

func WithServerConnectedWithClient(fn OnTcpServerConnectedWithClient) ServerOpt

func WithServerDisconnectedWithClient

func WithServerDisconnectedWithClient(fn OnTcpServerDisconnectedWithClient) ServerOpt

func WithServerListening

func WithServerListening(fn OnTcpServerListening) ServerOpt

func WithServerOnProcessFunc

func WithServerOnProcessFunc(onProcess OnTcpServerProcessFunc) ServerOpt

func WithServerReadWriter

func WithServerReadWriter(onCreateReadWriter OnTcpServerCreateReadWriter) ServerOpt

func WithTlsConfig

func WithTlsConfig(s *tls.CmdrTlsConfig) ServerOpt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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