net2

package
v0.0.0-...-e41513e Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: Apache-2.0 Imports: 12 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConnectionBlockedError = errors.New("Connection Blocked")
View Source
var ConnectionClosedError = errors.New("Connection Closed")

Functions

func Accept

func Accept(listener net.Listener) (net.Conn, error)

func RegisterProtocol

func RegisterProtocol(name string, protocol Protocol)

Types

type BufferedConn

type BufferedConn struct {
	net.Conn // So that most methods are embedded
	// contains filtered or unexported fields
}

func NewBufferedConn

func NewBufferedConn(c net.Conn) *BufferedConn

func NewBufferedConnSize

func NewBufferedConnSize(c net.Conn, n int) *BufferedConn

func (*BufferedConn) BufioReader

func (b *BufferedConn) BufioReader() *bufio.Reader

func (*BufferedConn) Discard

func (b *BufferedConn) Discard(n int) (int, error)

func (*BufferedConn) Peek

func (b *BufferedConn) Peek(n int) ([]byte, error)

func (*BufferedConn) Read

func (b *BufferedConn) Read(p []byte) (int, error)

type ClearSendChan

type ClearSendChan interface {
	ClearSendChan(<-chan interface{})
}

type ClientConfig

type ClientConfig struct {
	Name      string
	ProtoName string
	AddrList  []string
	EtcdAddrs []string
	Balancer  string
}

type Codec

type Codec interface {
	Receive() (interface{}, error)
	Send(interface{}) error
	Close() error
}

func NewCodecByName

func NewCodecByName(name string, rw io.ReadWriter) (Codec, error)

type Connection

type Connection interface {
	GetConnID() uint64
	IsClosed() bool
	Close() error
	Codec() Codec
	Receive() (interface{}, error)
	Send(msg interface{}) error
}

type ConnectionFactory

type ConnectionFactory interface {
	NewConnection(serverName string) TcpConnection
}

type ConnectionManager

type ConnectionManager struct {
	// contains filtered or unexported fields
}

func NewConnectionManager

func NewConnectionManager() *ConnectionManager

func (*ConnectionManager) Dispose

func (manager *ConnectionManager) Dispose()

func (*ConnectionManager) GetConnection

func (manager *ConnectionManager) GetConnection(connID uint64) Connection

type MessageBase

type MessageBase interface {
	Encode() []byte
	Decode(b []byte) error
}

type Protocol

type Protocol interface {
	NewCodec(rw io.ReadWriter) (Codec, error)
}

type ProtocolFunc

type ProtocolFunc func(rw io.ReadWriter) (Codec, error)

func (ProtocolFunc) NewCodec

func (pf ProtocolFunc) NewCodec(rw io.ReadWriter) (Codec, error)

type ServerConfig

type ServerConfig struct {
	Name      string
	ProtoName string
	Addr      string
}

type TcpClient

type TcpClient struct {
	// contains filtered or unexported fields
}

func NewTcpClient

func NewTcpClient(name string, chanSize int, protoName, address string, cb TcpClientCallBack) *TcpClient

func (*TcpClient) AutoReconnect

func (c *TcpClient) AutoReconnect() bool

func (*TcpClient) GetConnection

func (c *TcpClient) GetConnection() *TcpConnection

func (*TcpClient) GetRemoteAddress

func (c *TcpClient) GetRemoteAddress() string

func (*TcpClient) GetRemoteName

func (c *TcpClient) GetRemoteName() string

func (*TcpClient) GetTimer

func (c *TcpClient) GetTimer() time.Duration

func (*TcpClient) OnConnectionClosed

func (c *TcpClient) OnConnectionClosed(conn Connection)

func (*TcpClient) Reconnect

func (c *TcpClient) Reconnect()

func (*TcpClient) Send

func (c *TcpClient) Send(msg interface{}) error

func (*TcpClient) Serve

func (c *TcpClient) Serve() bool

func (*TcpClient) SetTimer

func (c *TcpClient) SetTimer(d time.Duration)

func (*TcpClient) StartTimer

func (c *TcpClient) StartTimer()

func (*TcpClient) Stop

func (c *TcpClient) Stop()

type TcpClientCallBack

type TcpClientCallBack interface {
	OnNewClient(c *TcpClient)
	OnClientDataArrived(c *TcpClient, msg interface{}) error
	OnClientClosed(c *TcpClient)
	OnClientTimer(c *TcpClient)
}

type TcpClientGroupManager

type TcpClientGroupManager struct {
	// contains filtered or unexported fields
}

func NewTcpClientGroupManager

func NewTcpClientGroupManager(protoName string, clients map[string][]string, cb TcpClientCallBack) *TcpClientGroupManager

func (*TcpClientGroupManager) AddClient

func (cgm *TcpClientGroupManager) AddClient(name string, address string)

func (*TcpClientGroupManager) BroadcastData

func (cgm *TcpClientGroupManager) BroadcastData(name string, msg interface{}) error

func (*TcpClientGroupManager) GetConfig

func (cgm *TcpClientGroupManager) GetConfig() interface{}

func (*TcpClientGroupManager) RemoveClient

func (cgm *TcpClientGroupManager) RemoveClient(name string, address string)

func (*TcpClientGroupManager) SendData

func (cgm *TcpClientGroupManager) SendData(name string, msg interface{}) error

func (*TcpClientGroupManager) SendDataToAddress

func (cgm *TcpClientGroupManager) SendDataToAddress(name, address string, msg interface{}) error

func (*TcpClientGroupManager) Serve

func (cgm *TcpClientGroupManager) Serve() bool

func (*TcpClientGroupManager) Stop

func (cgm *TcpClientGroupManager) Stop() bool

type TcpConnection

type TcpConnection struct {
	Context interface{}
	// contains filtered or unexported fields
}

func NewTcpConnection

func NewTcpConnection(name string, conn net.Conn, sendChanSize int, codec Codec, cb closeCallback) *TcpConnection

func (*TcpConnection) Close

func (c *TcpConnection) Close() error

func (*TcpConnection) Codec

func (c *TcpConnection) Codec() Codec

func (*TcpConnection) GetConnID

func (c *TcpConnection) GetConnID() uint64

func (*TcpConnection) GetNetConn

func (c *TcpConnection) GetNetConn() net.Conn

func (*TcpConnection) IsClosed

func (c *TcpConnection) IsClosed() bool

func (*TcpConnection) LoadAddr

func (c *TcpConnection) LoadAddr() net.Addr

func (*TcpConnection) Name

func (c *TcpConnection) Name() string

func (*TcpConnection) Receive

func (c *TcpConnection) Receive() (interface{}, error)

func (*TcpConnection) RemoteAddr

func (c *TcpConnection) RemoteAddr() net.Addr

func (*TcpConnection) Send

func (c *TcpConnection) Send(msg interface{}) error

func (*TcpConnection) String

func (c *TcpConnection) String() string

type TcpConnectionCallback

type TcpConnectionCallback interface {
	OnNewConnection(conn *TcpConnection)
	OnConnectionDataArrived(c *TcpConnection, msg interface{}) error
	OnConnectionClosed(c *TcpConnection)
}

type TcpServer

type TcpServer struct {
	// contains filtered or unexported fields
}

func NewTcpServer

func NewTcpServer(args TcpServerArgs) *TcpServer

func (*TcpServer) GetConnection

func (s *TcpServer) GetConnection(connID uint64) *TcpConnection

func (*TcpServer) OnConnectionClosed

func (s *TcpServer) OnConnectionClosed(conn Connection)

func (*TcpServer) Pause

func (s *TcpServer) Pause()

func (*TcpServer) SendByConnID

func (s *TcpServer) SendByConnID(connID uint64, msg interface{}) error

根据ConnId发送数据

func (*TcpServer) Serve

func (s *TcpServer) Serve()

func (*TcpServer) Serve2

func (s *TcpServer) Serve2()

TODO(@benqi): 讨巧的办法

func (*TcpServer) Stop

func (s *TcpServer) Stop()

type TcpServerArgs

type TcpServerArgs struct {
	Listener                net.Listener
	ServerName              string
	ProtoName               string
	SendChanSize            int
	ConnectionCallback      TcpConnectionCallback
	MaxConcurrentConnection int
}

Directories

Path Synopsis
Test codec
Test codec
examples

Jump to

Keyboard shortcuts

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