tcp

package
v0.0.0-...-a5d5012 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConnectStateInvalid = iota
	ConnectStateConnecting
	ConnectStateConnected
	ConnectStateDisconnected
)

Variables

This section is empty.

Functions

func DispatchMsg

func DispatchMsg(f func(event interface{})) func(event interface{})

func SyncRequest

func SyncRequest(s *Session, msg proto.Message, out proto.Message) error

用于异步RPC同步等待,别在queue或者逻辑线程里面用,只适合http逻辑里面调用,会阻塞

Types

type AcceptSession

type AcceptSession struct {
	*Session
}

func (*AcceptSession) GetSession

func (this_ *AcceptSession) GetSession() *Session

type Acceptor

type Acceptor struct {
	IP   string
	Port string

	sync.Once
	// contains filtered or unexported fields
}

func NewAcceptor

func NewAcceptor(addr string, queue *eventloop.EventLoop, codeC CodeC, logger *logger.Logger, isDebugLog bool) (*Acceptor, error)

func (*Acceptor) CheckPingPong

func (this_ *Acceptor) CheckPingPong(sess *Session)

func (*Acceptor) Close

func (this_ *Acceptor) Close()

func (*Acceptor) GetListener

func (this_ *Acceptor) GetListener() net.Listener

func (*Acceptor) OnNormalMsg

func (this_ *Acceptor) OnNormalMsg(session *Session, msg proto.Message)

func (*Acceptor) OnRPCRequest

func (this_ *Acceptor) OnRPCRequest(session *Session, msg proto.Message) proto.Message

func (*Acceptor) OnSessionConnected

func (this_ *Acceptor) OnSessionConnected(session *Session)

func (*Acceptor) OnSessionDisConnected

func (this_ *Acceptor) OnSessionDisConnected(session *Session, err error)

func (*Acceptor) SetCallback

func (this_ *Acceptor) SetCallback(ai DispatchInterface)

func (*Acceptor) StartAccept

func (this_ *Acceptor) StartAccept()

type AllDoConcurrent

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

func (*AllDoConcurrent) DoConcurrent

func (this_ *AllDoConcurrent) DoConcurrent(msgID string) bool

func (*AllDoConcurrent) RegisterNotConcurrentMsg

func (this_ *AllDoConcurrent) RegisterNotConcurrentMsg(message proto.Message)

如果注册了 对应的并发消息。不管是 rpc 还是 普通消息 ,那么收到此消息将会在协程池中调用相关函数,

type CloseError

type CloseError struct {
	Err error
}

func (*CloseError) Error

func (this_ *CloseError) Error() string

type CodeC

type CodeC interface {
	Encode(v proto.Message) ([]byte, error)
	Decode(data []byte, v proto.Message) error
	String() string
}

type ConnectError

type ConnectError struct {
	Err error
}

func (*ConnectError) Error

func (this_ *ConnectError) Error() string

type ConnectFailedInterface

type ConnectFailedInterface interface {
	OnConnectFailed(connector *Connector, err error)
}

type Connector

type Connector struct {
	ConnectTimeout time.Duration

	ConnectorName string
	// contains filtered or unexported fields
}

func NewConnector

func NewConnector(addr string, queue *eventloop.EventLoop, logger *logger.Logger, connectorName string, options ...Option) *Connector

func (*Connector) Close

func (this_ *Connector) Close(err error)

func (*Connector) Connect

func (this_ *Connector) Connect()

func (*Connector) DoConcurrent

func (this_ *Connector) DoConcurrent(msgID string) bool

func (*Connector) GetAddr

func (this_ *Connector) GetAddr() string

func (*Connector) GetSession

func (this_ *Connector) GetSession() *Session

func (*Connector) OnNormalMsg

func (this_ *Connector) OnNormalMsg(s *Session, msg proto.Message)

func (*Connector) OnRPCRequest

func (this_ *Connector) OnRPCRequest(s *Session, msg proto.Message) proto.Message

func (*Connector) OnSessionConnected

func (this_ *Connector) OnSessionConnected(s *Session)

func (*Connector) OnSessionDisConnected

func (this_ *Connector) OnSessionDisConnected(s *Session, err error)

func (*Connector) RemoteAddr

func (this_ *Connector) RemoteAddr() string

func (*Connector) Request

func (this_ *Connector) Request(msg proto.Message, resp RPCResponse) (err error)

func (*Connector) RequestNoError

func (this_ *Connector) RequestNoError(msg proto.Message, resp RPCResponse)

func (*Connector) Send

func (this_ *Connector) Send(msg proto.Message) (err error)

func (*Connector) SendNoError

func (this_ *Connector) SendNoError(msg proto.Message)

func (*Connector) SetCallback

func (this_ *Connector) SetCallback(ci DispatchInterface)

func (*Connector) SetDoConcurrent

func (this_ *Connector) SetDoConcurrent(dc DoConcurrentInterface)

func (*Connector) SetOnConnectFailed

func (this_ *Connector) SetOnConnectFailed(f func(connector *Connector, err error))

type ConnectorInfo

type ConnectorInfo struct {
	Connector *Connector
	Error     error
}

func (*ConnectorInfo) GetSession

func (this_ *ConnectorInfo) GetSession() *Session

type DefaultDoConcurrent

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

func (*DefaultDoConcurrent) DoConcurrent

func (this_ *DefaultDoConcurrent) DoConcurrent(msgID string) bool

func (*DefaultDoConcurrent) RegisterConcurrentMsg

func (this_ *DefaultDoConcurrent) RegisterConcurrentMsg(message proto.Message)

如果注册了 对应的并发消息。不管是 rpc 还是 普通消息 ,那么收到此消息将会在协程池中调用相关函数,

type DefaultLogDispatch

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

func (*DefaultLogDispatch) OnNormalMsg

func (this_ *DefaultLogDispatch) OnNormalMsg(s *Session, msg proto.Message)

func (*DefaultLogDispatch) OnRPCRequest

func (this_ *DefaultLogDispatch) OnRPCRequest(s *Session, msg proto.Message) proto.Message

func (*DefaultLogDispatch) OnSessionConnected

func (this_ *DefaultLogDispatch) OnSessionConnected(s *Session)

func (*DefaultLogDispatch) OnSessionDisConnected

func (this_ *DefaultLogDispatch) OnSessionDisConnected(s *Session, err error)

type DispatchInterface

type DispatchInterface interface {
	OnSessionConnected(*Session)
	OnSessionDisConnected(*Session, error)
	OnRPCRequest(*Session, proto.Message) proto.Message
	OnNormalMsg(*Session, proto.Message)
}

type DoConcurrentInterface

type DoConcurrentInterface interface {
	DoConcurrent(msgID string) bool
}

type ErrServerClosed

type ErrServerClosed string

func (*ErrServerClosed) Error

func (e *ErrServerClosed) Error() string

type HookDispatchInterface

type HookDispatchInterface interface {
	OnSessionConnected(*Session) bool
	OnSessionDisConnected(*Session, error) bool
	OnRPCRequest(*Session, proto.Message) (proto.Message, bool)
	OnNormalMsg(*Session, proto.Message) bool
}

type JSONCodeC

type JSONCodeC struct{}

func (*JSONCodeC) Decode

func (this_ *JSONCodeC) Decode(data []byte, v proto.Message) error

func (*JSONCodeC) Encode

func (this_ *JSONCodeC) Encode(v proto.Message) ([]byte, error)

func (*JSONCodeC) String

func (this_ *JSONCodeC) String() string

type MsgIDType

type MsgIDType string
const (
	RPCTimeout MsgIDType = "RPC_REQUEST_TIMEOUT"
	RPCError   MsgIDType = "RPC_REQUEST_ERROR"
)

type Option

type Option func(c *Connector)

func WithConnectTimeout

func WithConnectTimeout(timeout time.Duration) Option

func WithJsonCodeC

func WithJsonCodeC() Option

func WithOpenDebugLog

func WithOpenDebugLog() Option

func WithReconnect

func WithReconnect() Option

type Packet

type Packet struct {
	Protocol packetProtocol
	RPCIndex uint32
	MsgID    string
	Msg      proto.Message
	Sess     *Session
}

func (*Packet) GetSession

func (this_ *Packet) GetSession() *Session

type ProtoCodeC

type ProtoCodeC struct{}

func (*ProtoCodeC) Decode

func (this_ *ProtoCodeC) Decode(data []byte, v proto.Message) error

func (*ProtoCodeC) Encode

func (this_ *ProtoCodeC) Encode(v proto.Message) ([]byte, error)

func (*ProtoCodeC) String

func (this_ *ProtoCodeC) String() string

type RPCResponse

type RPCResponse func(m proto.Message)

type Session

type Session struct {
	CodeC
	sync.Once

	SessionName string
	SessionID   string
	Dispatch    DispatchInterface
	// contains filtered or unexported fields
}

func NewSession

func NewSession(conn net.Conn, queue *eventloop.EventLoop, batchSend bool, codec CodeC, logger *logger.Logger, rpcTimeout time.Duration, isDebugLog bool) *Session

func (*Session) Close

func (this_ *Session) Close(err error)

func (*Session) GetLogger

func (this_ *Session) GetLogger() *logger.Logger

func (*Session) LocalAddr

func (this_ *Session) LocalAddr() string

func (*Session) Next

func (this_ *Session) Next(prevTime time.Time) time.Time

func (*Session) RemoteAddr

func (this_ *Session) RemoteAddr() string

func (*Session) RemoteTcp4IP

func (this_ *Session) RemoteTcp4IP() string

func (*Session) Request

func (this_ *Session) Request(msg proto.Message, resp RPCResponse) error

func (*Session) RequestNoError

func (this_ *Session) RequestNoError(msg proto.Message, resp RPCResponse)

func (*Session) Send

func (this_ *Session) Send(msg proto.Message) error

func (*Session) SendBytes

func (this_ *Session) SendBytes(msgID string, msg []byte) error

func (*Session) SendBytesNoError

func (this_ *Session) SendBytesNoError(msgID string, msg []byte)

func (*Session) SendNoError

func (this_ *Session) SendNoError(msg proto.Message)

func (*Session) SendPing

func (this_ *Session) SendPing() error

func (*Session) SendPong

func (this_ *Session) SendPong() error

func (*Session) Start

func (this_ *Session) Start()

type SessionClosed

type SessionClosed struct {
	Err  error
	Sess *Session
}

func (*SessionClosed) GetSession

func (this_ *SessionClosed) GetSession() *Session

type SessionInterface

type SessionInterface interface {
	GetSession() *Session
}

type SessionMap

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

func NewSessionMap

func NewSessionMap(log *logger.Logger) *SessionMap

func (*SessionMap) AddSession

func (this_ *SessionMap) AddSession(s *Session)

func (*SessionMap) DelSession

func (this_ *SessionMap) DelSession(s *Session)

func (*SessionMap) GetSession

func (this_ *SessionMap) GetSession(sessionID string) (*Session, bool)

func (*SessionMap) SendBySessionID

func (this_ *SessionMap) SendBySessionID(sessionID string, msg proto.Message)

func (*SessionMap) SendToAll

func (this_ *SessionMap) SendToAll(msg proto.Message)

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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