network

package
v0.0.0-...-78a0d84 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ReAcceptDelay = 5

Variables

This section is empty.

Functions

func AddSession

func AddSession(s defs.ISession)

func DelSession

func DelSession(sessionId string)

func GetSession

func GetSession(sessionId string) defs.ISession

func ListenTcp

func ListenTcp(addr string) net.Listener

func RangeSession

func RangeSession(f func(sId string, s defs.ISession) bool)

func WaitExit

func WaitExit()

Types

type Connection

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

func NewConnection

func NewConnection(conn net.Conn) *Connection

func (*Connection) Close

func (c *Connection) Close() bool

func (*Connection) DelContext

func (c *Connection) DelContext(key interface{})

func (*Connection) GetConn

func (c *Connection) GetConn() net.Conn

func (*Connection) GetContext

func (c *Connection) GetContext(key interface{}) interface{}

func (*Connection) GetId

func (c *Connection) GetId() string

func (*Connection) IsClosed

func (c *Connection) IsClosed() bool

func (*Connection) LocalAddr

func (c *Connection) LocalAddr() string

func (*Connection) OnConnection

func (c *Connection) OnConnection()

func (*Connection) ReadPacket

func (c *Connection) ReadPacket(packet defs.IPacket)

func (*Connection) RemoteAddr

func (c *Connection) RemoteAddr() string

func (*Connection) SetAuthorizedCallback

func (c *Connection) SetAuthorizedCallback(cb defs.AuthorizedCallback)

func (*Connection) SetCloseCallback

func (c *Connection) SetCloseCallback(cb defs.CloseCallback)

func (*Connection) SetCodec

func (c *Connection) SetCodec(codec defs.ICodec)

func (*Connection) SetConnCallback

func (c *Connection) SetConnCallback(cb defs.ConnCallback)

func (*Connection) SetContext

func (c *Connection) SetContext(key, value interface{})

func (*Connection) SetIOModule

func (c *Connection) SetIOModule(ioModule defs.IIOModule)

func (*Connection) SetMsgCallback

func (c *Connection) SetMsgCallback(cb defs.MsgCallback)

func (*Connection) SetWriteCompleteCallback

func (c *Connection) SetWriteCompleteCallback(cb defs.WriteCompleteCallback)

func (*Connection) Start

func (c *Connection) Start() bool

func (*Connection) UpdateCodec

func (c *Connection) UpdateCodec(codec defs.ICodec)

func (*Connection) WriteComplete

func (c *Connection) WriteComplete()

func (*Connection) WriteData

func (c *Connection) WriteData(data []byte)

func (*Connection) WriteDataAwait

func (c *Connection) WriteDataAwait(data []byte) (defs.IPacket, error)

func (*Connection) WriteDataById

func (c *Connection) WriteDataById(id string, data []byte)

func (*Connection) WriteDataByIdAwait

func (c *Connection) WriteDataByIdAwait(id string, data []byte) (defs.IPacket, error)

func (*Connection) WritePacket

func (c *Connection) WritePacket(packet defs.IPacket)

func (*Connection) WritePacketAwait

func (c *Connection) WritePacketAwait(packet defs.IPacket) (defs.IPacket, error)

type ConnectionMgr

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

func NewConnMgr

func NewConnMgr() *ConnectionMgr

func (*ConnectionMgr) AddConn

func (cm *ConnectionMgr) AddConn(conn defs.IConnection)

func (*ConnectionMgr) Clean

func (cm *ConnectionMgr) Clean()

func (*ConnectionMgr) ConnCount

func (cm *ConnectionMgr) ConnCount() int

func (*ConnectionMgr) DelConn

func (cm *ConnectionMgr) DelConn(connId string)

func (*ConnectionMgr) GetConn

func (cm *ConnectionMgr) GetConn(connId string) defs.IConnection

type Connector

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

func NewConnector

func NewConnector(addr string) *Connector

func (*Connector) CancelHandle

func (c *Connector) CancelHandle()

func (*Connector) Close

func (c *Connector) Close(v bool)

func (*Connector) IsWorking

func (c *Connector) IsWorking() bool

func (*Connector) SetCancelCallback

func (c *Connector) SetCancelCallback(cb func())

func (*Connector) SetConnCallback

func (c *Connector) SetConnCallback(cb defs.ClientConnCallback)

func (*Connector) Start

func (c *Connector) Start(timeout time.Duration)

type Map

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

func (*Map) Add

func (m *Map) Add(key, value interface{})

func (*Map) Del

func (m *Map) Del(key interface{})

func (*Map) Get

func (m *Map) Get(key interface{}) (interface{}, bool)

func (*Map) Length

func (m *Map) Length() int64

func (*Map) Range

func (m *Map) Range(f func(k, v interface{}) bool)

type Server

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

func NewServer

func NewServer(name string, confPath ...string) *Server

func (*Server) AddRemoteClient

func (s *Server) AddRemoteClient(cfg *conf.ServerConfig) *TcpClient

func (*Server) GetCfg

func (s *Server) GetCfg() *conf.ServerConfig

func (*Server) GetConn

func (s *Server) GetConn(connId string) defs.ISession

func (*Server) GetConnNum

func (s *Server) GetConnNum() int64

func (*Server) GetRemoteClient

func (s *Server) GetRemoteClient(name string) *TcpClient

func (*Server) Host

func (s *Server) Host() string

func (*Server) OnDisConn

func (s *Server) OnDisConn(conn defs.IConnection)

func (*Server) OnNewConn

func (s *Server) OnNewConn(conn defs.IConnection)

func (*Server) OnServiceHandle

func (s *Server) OnServiceHandle(session defs.ISession, packet defs.IPacket) bool

func (*Server) RangeConn

func (s *Server) RangeConn(f func(string, defs.ISession) bool)

func (*Server) RegisterService

func (s *Server) RegisterService(rcvr interface{}, cb ...defs.ParseMethodNameCallback)

func (*Server) SetDisConnCallback

func (s *Server) SetDisConnCallback(cb defs.ConnCallback)

func (*Server) SetNewConnCallback

func (s *Server) SetNewConnCallback(cb defs.ConnCallback)

func (*Server) Start

func (s *Server) Start()

type ServerMgr

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

func GetSrvMgr

func GetSrvMgr() *ServerMgr

func (*ServerMgr) AddServer

func (sm *ServerMgr) AddServer(server defs.IServer)

func (*ServerMgr) AllDelete

func (sm *ServerMgr) AllDelete()

func (*ServerMgr) AllStop

func (sm *ServerMgr) AllStop()

func (*ServerMgr) DelServer

func (sm *ServerMgr) DelServer(server defs.IServer)

func (*ServerMgr) DelServerByName

func (sm *ServerMgr) DelServerByName(name string)

func (*ServerMgr) StopServer

func (sm *ServerMgr) StopServer(server defs.IServer)

func (*ServerMgr) StopServerByName

func (sm *ServerMgr) StopServerByName(name string)

type ServiceHandle

type ServiceHandle func(defs.ISession, defs.IPacket) bool

type Session

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

func NewSession

func NewSession(conn defs.IConnection, sessionId string, serviceHandle ServiceHandle, async ...bool) *Session

func NewSession(conn defs.IConnection, sessionId string, serve defs.ServeObj, async ...bool) *Session {

func (*Session) Close

func (s *Session) Close() bool

func (*Session) CloseSession

func (s *Session) CloseSession() bool

func (*Session) GetConn

func (s *Session) GetConn() defs.IConnection

func (*Session) GetConnId

func (s *Session) GetConnId() string

func (*Session) GetContext

func (s *Session) GetContext(key interface{}) interface{}

func (*Session) GetPacket

func (s *Session) GetPacket() defs.IPacket

func (*Session) GetSessionId

func (s *Session) GetSessionId() string

func (*Session) OnService

func (s *Session) OnService(session defs.ISession, packet defs.IPacket) bool

func (*Session) SetContext

func (s *Session) SetContext(key, value interface{})

func (*Session) SetPacket

func (s *Session) SetPacket(packet defs.IPacket)

func (*Session) WriteData

func (s *Session) WriteData(data []byte)

func (*Session) WriteDataAwait

func (s *Session) WriteDataAwait(data []byte) (defs.IPacket, error)

func (*Session) WriteDataById

func (s *Session) WriteDataById(id string, data []byte)

func (*Session) WriteDataByIdAwait

func (s *Session) WriteDataByIdAwait(id string, data []byte) (defs.IPacket, error)

func (*Session) WritePacket

func (s *Session) WritePacket(packet defs.IPacket)

func (*Session) WritePacketAwait

func (s *Session) WritePacketAwait(packet defs.IPacket) (defs.IPacket, error)

type SessionMgr

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

func GetSessionMgr

func GetSessionMgr() *SessionMgr

func NewSessionMgr

func NewSessionMgr() *SessionMgr

func (*SessionMgr) AddSession

func (sm *SessionMgr) AddSession(s defs.ISession)

func (*SessionMgr) DelConnSession

func (sm *SessionMgr) DelConnSession(connId string) []defs.ISession

func (*SessionMgr) DelSession

func (sm *SessionMgr) DelSession(sessionId string) defs.ISession

func (*SessionMgr) GetSession

func (sm *SessionMgr) GetSession(sessionId string) defs.ISession

func (*SessionMgr) RangeSession

func (sm *SessionMgr) RangeSession(f func(string, defs.ISession) bool)

func (*SessionMgr) SessionCount

func (sm *SessionMgr) SessionCount() int64

type TcpClient

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

func NewTcpClient

func NewTcpClient(name, addr string) *TcpClient

func (*TcpClient) Cancel

func (tcpClient *TcpClient) Cancel()

func (*TcpClient) Close

func (tcpClient *TcpClient) Close() bool

func (*TcpClient) CloseConnection

func (tcpClient *TcpClient) CloseConnection(conn defs.IConnection)

func (*TcpClient) Connect

func (tcpClient *TcpClient) Connect() defs.IConnection

func (*TcpClient) GetConn

func (tcpClient *TcpClient) GetConn() defs.IConnection

func (*TcpClient) IsWorking

func (tcpClient *TcpClient) IsWorking() bool

func (*TcpClient) Name

func (tcpClient *TcpClient) Name() string

func (*TcpClient) SendData

func (tcpClient *TcpClient) SendData(data []byte)

func (*TcpClient) SendDataAwait

func (tcpClient *TcpClient) SendDataAwait(data []byte) (defs.IPacket, error)

func (*TcpClient) SendDataById

func (tcpClient *TcpClient) SendDataById(id string, data []byte)

func (*TcpClient) SendDataByIdAwait

func (tcpClient *TcpClient) SendDataByIdAwait(id string, data []byte) (defs.IPacket, error)

func (*TcpClient) SendPacket

func (tcpClient *TcpClient) SendPacket(packet defs.IPacket)

func (*TcpClient) SendPacketAwait

func (tcpClient *TcpClient) SendPacketAwait(packet defs.IPacket) (defs.IPacket, error)

func (*TcpClient) SetCodec

func (tcpClient *TcpClient) SetCodec(codec defs.ICodec)

func (*TcpClient) SetConnCallback

func (tcpClient *TcpClient) SetConnCallback(cb defs.ConnCallback)

func (*TcpClient) SetIOModule

func (tcpClient *TcpClient) SetIOModule(ioModule defs.IIOModule)

func (*TcpClient) SetMsgCallback

func (tcpClient *TcpClient) SetMsgCallback(cb defs.MsgCallback)

func (*TcpClient) SetOneStep

func (tcpClient *TcpClient) SetOneStep(val bool)

func (*TcpClient) SetRetry

func (tcpClient *TcpClient) SetRetry(v bool)

func (*TcpClient) SetTimeout

func (tcpClient *TcpClient) SetTimeout(val time.Duration)

func (*TcpClient) Start

func (tcpClient *TcpClient) Start()

type TcpServer

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

func NewTcpServer

func NewTcpServer(addr, name string, maxConn int) *TcpServer

func (*TcpServer) CloseConnection

func (tcpServer *TcpServer) CloseConnection(conn defs.IConnection)

func (*TcpServer) Host

func (tcpServer *TcpServer) Host() string

func (*TcpServer) Name

func (tcpServer *TcpServer) Name() string

func (*TcpServer) Serve

func (tcpServer *TcpServer) Serve()

func (*TcpServer) SetAuthorizedCallback

func (tcpServer *TcpServer) SetAuthorizedCallback(cb defs.AuthorizedCallback)

func (*TcpServer) SetCodec

func (tcpServer *TcpServer) SetCodec(codec defs.ICodec)

func (*TcpServer) SetConnCallback

func (tcpServer *TcpServer) SetConnCallback(cb defs.ConnCallback)

func (*TcpServer) SetExitCallback

func (tcpServer *TcpServer) SetExitCallback(cb defs.ExitCallback)

func (*TcpServer) SetMsgCallback

func (tcpServer *TcpServer) SetMsgCallback(cb defs.MsgCallback)

func (*TcpServer) SetNewIOModuleCallback

func (tcpServer *TcpServer) SetNewIOModuleCallback(newCallback defs.NewIOModuleCallback)

func (*TcpServer) SetWriteCompleteCallback

func (tcpServer *TcpServer) SetWriteCompleteCallback(cb defs.WriteCompleteCallback)

func (*TcpServer) Stop

func (tcpServer *TcpServer) Stop()

type WSClient

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

func NewWSClient

func NewWSClient(name, addr string, path ...string) *WSClient

func (*WSClient) Close

func (wsclient *WSClient) Close() bool

func (*WSClient) CloseConnection

func (wsclient *WSClient) CloseConnection(conn defs.IConnection)

func (*WSClient) Connect

func (wsclient *WSClient) Connect() defs.IConnection

func (*WSClient) Name

func (wsclient *WSClient) Name() string

func (*WSClient) SendData

func (wsclient *WSClient) SendData(data []byte)

func (*WSClient) SendPacket

func (wsclient *WSClient) SendPacket(packet defs.IPacket)

func (*WSClient) SetCodec

func (wsclient *WSClient) SetCodec(codec defs.ICodec)

func (*WSClient) SetConnCallback

func (wsclient *WSClient) SetConnCallback(cb defs.ConnCallback)

func (*WSClient) SetIOModule

func (wsclient *WSClient) SetIOModule(ioModule defs.IIOModule)

func (*WSClient) SetMsgCallback

func (wsclient *WSClient) SetMsgCallback(cb defs.MsgCallback)

func (*WSClient) SetMsgType

func (wsclient *WSClient) SetMsgType(msgType int)

func (*WSClient) SetRetry

func (wsclient *WSClient) SetRetry(v bool)

type WSConnection

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

func NewWSConnection

func NewWSConnection(conn *websocket.Conn) *WSConnection

func (*WSConnection) Close

func (wsc *WSConnection) Close() bool

func (*WSConnection) DelContext

func (wsc *WSConnection) DelContext(key interface{})

func (*WSConnection) GetConn

func (wsc *WSConnection) GetConn() *websocket.Conn

func (*WSConnection) GetContext

func (wsc *WSConnection) GetContext(key interface{}) interface{}

func (*WSConnection) GetId

func (wsc *WSConnection) GetId() string

func (*WSConnection) GetMsgType

func (wsc *WSConnection) GetMsgType() int

func (*WSConnection) IsClosed

func (wsc *WSConnection) IsClosed() bool

func (*WSConnection) LocalAddr

func (wsc *WSConnection) LocalAddr() string

func (*WSConnection) OnConnection

func (wsc *WSConnection) OnConnection()

func (*WSConnection) ReadPacket

func (wsc *WSConnection) ReadPacket(packet defs.IPacket)

func (*WSConnection) RemoteAddr

func (wsc *WSConnection) RemoteAddr() string

func (*WSConnection) SetAuthorized

func (wsc *WSConnection) SetAuthorized(val bool)

func (*WSConnection) SetAuthorizedCallback

func (wsc *WSConnection) SetAuthorizedCallback(cb defs.AuthorizedCallback)

func (*WSConnection) SetCloseCallback

func (wsc *WSConnection) SetCloseCallback(cb defs.CloseCallback)

func (*WSConnection) SetCodec

func (wsc *WSConnection) SetCodec(codec defs.ICodec)

func (*WSConnection) SetConnCallback

func (wsc *WSConnection) SetConnCallback(cb defs.ConnCallback)

func (*WSConnection) SetContext

func (wsc *WSConnection) SetContext(key, value interface{})

func (*WSConnection) SetIOModule

func (wsc *WSConnection) SetIOModule(ioModule defs.IIOModule)

func (*WSConnection) SetMsgCallback

func (wsc *WSConnection) SetMsgCallback(cb defs.MsgCallback)

func (*WSConnection) SetMsgType

func (wsc *WSConnection) SetMsgType(msgType int)

func (*WSConnection) SetWriteCompleteCallback

func (wsc *WSConnection) SetWriteCompleteCallback(cb defs.WriteCompleteCallback)

func (*WSConnection) Start

func (wsc *WSConnection) Start() bool

func (*WSConnection) UpdateCodec

func (wsc *WSConnection) UpdateCodec(codec defs.ICodec)

func (*WSConnection) WriteComplete

func (wsc *WSConnection) WriteComplete()

func (*WSConnection) WriteData

func (wsc *WSConnection) WriteData(data []byte)

func (*WSConnection) WriteDataAwait

func (wsc *WSConnection) WriteDataAwait(data []byte) (defs.IPacket, error)

func (*WSConnection) WriteDataById

func (wsc *WSConnection) WriteDataById(id string, data []byte)

func (*WSConnection) WriteDataByIdAwait

func (wsc *WSConnection) WriteDataByIdAwait(id string, data []byte) (defs.IPacket, error)

func (*WSConnection) WritePacket

func (wsc *WSConnection) WritePacket(packet defs.IPacket)

func (*WSConnection) WritePacketAwait

func (wsc *WSConnection) WritePacketAwait(packet defs.IPacket) (defs.IPacket, error)

type WSServer

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

func NewWSServer

func NewWSServer(name, addr string, maxConn int, path ...string) *WSServer

func (*WSServer) EnablePong

func (ws *WSServer) EnablePong(val bool)

func (*WSServer) Host

func (ws *WSServer) Host() string

func (*WSServer) Name

func (ws *WSServer) Name() string

func (*WSServer) Serve

func (ws *WSServer) Serve()

func (*WSServer) ServeHTTP

func (ws *WSServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*WSServer) SetAuthorizedCallback

func (ws *WSServer) SetAuthorizedCallback(cb defs.AuthorizedCallback)

func (*WSServer) SetCodec

func (ws *WSServer) SetCodec(codec defs.ICodec)

func (*WSServer) SetConnCallback

func (ws *WSServer) SetConnCallback(cb defs.ConnCallback)

func (*WSServer) SetExitCallback

func (ws *WSServer) SetExitCallback(cb defs.ExitCallback)

func (*WSServer) SetMsgCallback

func (ws *WSServer) SetMsgCallback(cb defs.MsgCallback)

func (*WSServer) SetMsgType

func (ws *WSServer) SetMsgType(msgType int)

func (*WSServer) SetNewIOModuleCallback

func (ws *WSServer) SetNewIOModuleCallback(newCallback defs.NewIOModuleCallback)

func (*WSServer) SetWriteCompleteCallback

func (ws *WSServer) SetWriteCompleteCallback(cb defs.WriteCompleteCallback)

func (*WSServer) Stop

func (ws *WSServer) Stop()

Jump to

Keyboard shortcuts

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