net2

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func Accept

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

func AcceptTCP

func AcceptTCP(listener *net.TCPListener) (*net.TCPConn, error)

func ListenUdp

func ListenUdp(addr2 string) (net.PacketConn, 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) PeekByte

func (b *BufferedConn) PeekByte() (uint8, error)

func (*BufferedConn) PeekUint32

func (b *BufferedConn) PeekUint32() (uint32, error)

func (*BufferedConn) Read

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

func (*BufferedConn) String

func (b *BufferedConn) String() string

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
	Context() interface{}
}

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 PeekAble

type PeekAble interface {
	Peek(n int) ([]byte, error)
	PeekByte() (uint8, error)
	PeekUint32() (uint32, error)
	Discard(n int) (int, 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 NewTcpConnection2

func NewTcpConnection2(name string, conn net.Conn, sendChanSize int, codec Codec, isWebsocket bool, 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) IsWebsocket

func (c *TcpConnection) IsWebsocket() 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

func (*TcpServer) Serve

func (s *TcpServer) Serve()

func (*TcpServer) Serve2

func (s *TcpServer) Serve2()

TODO(@benqi): 讨巧的办法

func (*TcpServer) Stop

func (s *TcpServer) Stop()

type TcpServer2

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

func NewTcpServer2

func NewTcpServer2(c *TcpServerConfig, accepts int, cb TcpConnectionCallback) (s *TcpServer2, err error)

func (*TcpServer2) GetConnection

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

func (*TcpServer2) OnConnectionClosed

func (s *TcpServer2) OnConnectionClosed(conn Connection)

func (*TcpServer2) Pause

func (s *TcpServer2) Pause()

func (*TcpServer2) SendByConnID

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

func (*TcpServer2) Serve

func (s *TcpServer2) Serve()

func (*TcpServer2) Stop

func (s *TcpServer2) Stop()

type TcpServerArgs

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

type TcpServerConfig

type TcpServerConfig struct {
	Addrs        []string
	ServerName   string
	ProtoName    string
	SendBuf      int
	ReceiveBuf   int
	Keepalive    bool
	SendChanSize int
}

type UdpConnection

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

func NewUdpConnection

func NewUdpConnection() *UdpConnection

type UdpConnectionCallback

type UdpConnectionCallback interface {
	OnUdpNew(conn *UdpConnection)
	OnUdpDataArrived(c *UdpConnection, msg interface{}) error
	OnUdpClosed(c *UdpConnection)
}

type UdpServer

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

func NewUdpServer

func NewUdpServer(args UdpServerArgs) *UdpServer

func (*UdpServer) Pause

func (s *UdpServer) Pause()

func (*UdpServer) Serve

func (s *UdpServer) Serve()

func (*UdpServer) Stop

func (s *UdpServer) Stop()

type UdpServerArgs

type UdpServerArgs struct {
	PacketConn   *net.UDPConn
	ServerName   string
	ProtoName    string
	SendChanSize int
}

type WebsocketConfig

type WebsocketConfig struct {
	Addrs        []string
	ServerName   string
	ProtoName    string
	SendBuf      int
	ReceiveBuf   int
	Keepalive    bool
	SendChanSize int
}

type WebsocketServer

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

func NewWebsocketServer

func NewWebsocketServer(c *WebsocketConfig, accepts int, cb TcpConnectionCallback) (s *WebsocketServer, err error)

func (*WebsocketServer) GetConnection

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

func (*WebsocketServer) OnConnectionClosed

func (s *WebsocketServer) OnConnectionClosed(conn Connection)

func (*WebsocketServer) Pause

func (s *WebsocketServer) Pause()

func (*WebsocketServer) SendByConnID

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

func (*WebsocketServer) Serve

func (s *WebsocketServer) Serve()

func (*WebsocketServer) Stop

func (s *WebsocketServer) Stop()

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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