stnet

package module
v0.0.0-...-36052fc Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 21 Imported by: 0

README

stnet is a simple net lib. example

rpc server

package main

import (
	"github.com/gotask/gost/stnet"
	"time"
)

type Test struct {
}

func (t *Test) Loop() {

}
func (t *Test) HandleError(current *stnet.CurrentContent, err error) {

}

func (t *Test) HashProcessor(current *stnet.CurrentContent) (processorID int) {
	return -1
}

func (t *Test) Add(a, b int) int {
	return a + b
}

func main() {
	s := stnet.NewServer(10, 32)
	rpc := stnet.NewServiceRpc(&Test{})
	s.AddRpcService("ht", ":8085", 0, rpc, 0)
	s.Start()

	for {
		time.Sleep(time.Hour)
	}
}

rpc client

func main() {
	s := stnet.NewServer(10, 32)
	rpc := stnet.NewServiceRpc(&Test{})
	svr, e := s.AddRpcService("ht", "", 0, rpc, 0)
	if e != nil {
		fmt.Println(e)
		return
	}
	c := svr.NewConnect("127.0.0.1:8085", nil)
	s.Start()

	for {
		rpc.RpcCall(c.Session(), "Add", 1, 2, func(r int) {
			fmt.Println(r)
		}, func(r int32) {
			fmt.Println(r)
		})
		time.Sleep(time.Second)
	}
}

SpbServer

package main

import (
	"fmt"
	"time"

	"github.com/gotask/gost/stnet"
)

type ProA struct {
	A int
	S string
}

type Test struct {
}

func (t *Test) Init() bool {
	return true
}

func (t *Test) Loop() {

}
func (t *Test) Handle(current *stnet.CurrentContent, cmdId uint64, cmd interface{}, e error) {
	//fmt.Println(cmdId, cmd)
	if e != nil {
		fmt.Println(e)
	} else if cmdId == 1{
		fmt.Printf("%+v\n", cmd.(*ProA))
	}else if cmdId == 2 {
		fmt.Println(*cmd.(*string)) 
	}
}

func (t *Test) HashProcessor(current *stnet.CurrentContent, cmdId uint64) (processorID int) {
	return -1
}

func main() {
	s := stnet.NewServer(10, 32)
	ser := stnet.NewServiceSpb(&Test{})
	
	//register msg
	ser.RegisterMsg(1, ProA{})
	var t string = "123"
	ser.RegisterMsg(2, t)
	
	s.AddSpbService("", ":6060", 0, ser, 0)
	//c := svr.NewConnect("127.0.0.1:6060", nil)
	s.Start()
	time.Sleep(time.Hour)
}

Json Server

package main

import (
	"fmt"
	"github.com/gotask/gost/stnet"
	"time"
)

type JsonS struct {
}

func (j *JsonS) Init() bool {
	return true
}
func (j *JsonS) Loop() {

}
func (j *JsonS) Handle(current *stnet.CurrentContent, cmd stnet.JsonProto, e error) {
	fmt.Println(cmd, e)
	//stnet.SendJsonCmd(current.Sess, cmd.CmdId+1, cmd.CmdData)
}
func (j *JsonS) HashProcessor(current *stnet.CurrentContent, cmd stnet.JsonProto) (processorID int) {
	return -1
}

func main() {
	s := stnet.NewServer(10, 32)
	s.AddJsonService("js", ":8086", 0, &JsonS{}, 1)
	s.Start()

	for {
		time.Sleep(time.Hour)
	}
}

Documentation

Overview

a simple log lib some code from code.google.com/p/log4go console log is open, file and sock log is close by default you can use functin SetxxxLevel open or close the log pattern it will only print the log whose level is higher than the pattern's level

Index

Constants

View Source
const (
	EncodeTyepSpb  = 0
	EncodeTyepJson = 1
)
View Source
const (
	RpcErrNoRemoteFunc = -1
	RpcErrCallTimeout  = -2
	RpcErrFuncParamErr = -3
)
View Source
const (
	SpbPackDataType_Integer_Positive = 0
	SpbPackDataType_Integer_Negative = 1
	SpbPackDataType_Float            = 2
	SpbPackDataType_Double           = 3
	SpbPackDataType_String           = 4
	SpbPackDataType_Vector           = 5
	SpbPackDataType_Map              = 6
	SpbPackDataType_StructBegin      = 7
	SpbPackDataType_StructEnd        = 8
)

Variables

View Source
var (
	ErrSocketClosed = errors.New("socket closed")
	ErrSocketIsOpen = errors.New("socket is open")
	//ErrSendOverTime   = errors.New("send message over time")
	// length of send(recv) buffer = 256(tcp) 10240(udp) default
	ErrSendBuffIsFull = errors.New("send buffer is full")
	ErrMsgParseNil    = errors.New("MsgParse is nil")
)
View Source
var (
	MsgBuffSize = 1024
	MinMsgSize  = 64
	MaxMsgSize  = 2 * 1024 * 1024

	//the length of send(recv) queue
	WriterListLen = 256
	RecvListLen   = 256
)

message recv buffer size

View Source
var GlobalSessionID uint64

session id

View Source
var (
	TimeOut int64 = 5 //sec
)

Functions

func CanSetBool

func CanSetBool(x reflect.Value) bool

func CanSetFloat

func CanSetFloat(x reflect.Value) bool

func CanSetInt

func CanSetInt(x reflect.Value) bool

func CanSetUint

func CanSetUint(x reflect.Value) bool

func EncodeProtocol

func EncodeProtocol(msg interface{}, encode int) ([]byte, error)

func FormatLogRecord

func FormatLogRecord(rec *LogRecord) string

func Marshal

func Marshal(m interface{}, encodeType int) ([]byte, error)

func MsgLen

func MsgLen(b []byte) uint32

func SendJsonCmd

func SendJsonCmd(sess *Session, msgID uint64, msg []byte) error

func SendSpbCmd

func SendSpbCmd(sess *Session, msgID uint64, msg interface{}) error

func SpbDecode

func SpbDecode(data []byte, x interface{}) error

func SpbEncode

func SpbEncode(data interface{}) ([]byte, error)

func Unmarshal

func Unmarshal(data []byte, m interface{}, encodeType int) error

Types

type BufferPool

type BufferPool struct {
}

func (*BufferPool) Alloc

func (bp *BufferPool) Alloc(bufsize int) []byte

func (*BufferPool) Free

func (bp *BufferPool) Free([]byte)

type CMDType

type CMDType int
const (
	Data CMDType = 0 + iota
	Open
	Close
	HeartBeat
	System
)

type Closer

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

func NewCloser

func NewCloser(isclose bool) *Closer

func (*Closer) Close

func (c *Closer) Close()

func (*Closer) IsClose

func (c *Closer) IsClose() bool

func (*Closer) Open

func (c *Closer) Open()

type Connect

type Connect struct {
	*Connector
	Master *Service
}

func (*Connect) Close

func (ct *Connect) Close()

func (*Connect) Imp

func (ct *Connect) Imp() ServiceImp

type Connector

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

func NewConnector

func NewConnector(address string, msgparse MsgParse, userdata interface{}) *Connector

NewConnector reconnect at 0 1 4 9 16...times reconnectMSec(100ms);when call send or changeAddr, it will NotifyReconn and reconnect at once;when call Close, reconnect will stop

func (*Connector) Addr

func (c *Connector) Addr() string

func (*Connector) ChangeAddr

func (c *Connector) ChangeAddr(addr string)

func (*Connector) Close

func (c *Connector) Close()

func (*Connector) GetID

func (c *Connector) GetID() uint64

func (*Connector) IsClose

func (c *Connector) IsClose() bool

func (*Connector) IsConnected

func (c *Connector) IsConnected() bool

func (*Connector) NotifyReconn

func (c *Connector) NotifyReconn()

func (*Connector) ReconnCount

func (c *Connector) ReconnCount() int

func (*Connector) Send

func (c *Connector) Send(data []byte) error

func (*Connector) Session

func (c *Connector) Session() *Session

type CurrentContent

type CurrentContent struct {
	GoroutineID int //thead id
	Sess        *Session
	UserDefined interface{}
	Peer        net.Addr //use in udp
}

type FileLogWriter

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

This log writer sends output to a file

type FuncOnClose

type FuncOnClose = func(*Session)

FuncOnClose will be called when session closed

type FuncOnOpen

type FuncOnOpen = func(*Session)

FuncOnOpen will be called when session open

type HttpHandler

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

func (*HttpHandler) Handle

func (h *HttpHandler) Handle(pattern string, handler http.Handler)

Handle registers the handler for the given pattern in the DefaultServeMux. The documentation for ServeMux explains how patterns are matched.

func (*HttpHandler) HandleFunc

func (h *HttpHandler) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers the handler function for the given pattern.

func (*HttpHandler) Handler

func (h *HttpHandler) Handler(r *http.Request) (http.Handler, string)

func (*HttpHandler) ServeHTTP

func (h *HttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL.

type HttpService

type HttpService interface {
	Init() bool
	Loop()
	HandleError(current *CurrentContent, e error)
	HashProcessor(current *CurrentContent, req *http.Request) (processorID int)
}

type JsonProto

type JsonProto struct {
	CmdId   uint64 `json:"id"`
	CmdData []byte `json:"cmd"`
}

type JsonService

type JsonService interface {
	Init() bool
	Loop()
	Handle(current *CurrentContent, cmd JsonProto, e error)
	HashProcessor(current *CurrentContent, cmd JsonProto) (processorID int)
}

type Level

type Level int
const (
	SYSTEM Level = iota
	DEBUG
	INFO
	WARNING
	ERROR
	CRITICAL
	CLOSE
)

func (Level) String

func (l Level) String() string

type Listener

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

func NewListener

func NewListener(address string, msgparse MsgParse, heartbeat uint32) (*Listener, error)

func NewUdpListener

func NewUdpListener(address string, msgparse MsgParse, heartbeat uint32) (*Listener, error)

func (*Listener) Close

func (ls *Listener) Close()

func (*Listener) GetSession

func (ls *Listener) GetSession(id uint64) *Session

func (*Listener) IterateSession

func (ls *Listener) IterateSession(callback func(*Session) bool)

type LogRecord

type LogRecord struct {
	Level   Level     // The log level
	Created time.Time // The time at which the log message was created (nanoseconds)
	Source  string    // The message source
	Message string    // The log message
}

type Logger

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

func NewFileLogger

func NewFileLogger(fname string) *Logger

func NewFileLoggerWithoutTerm

func NewFileLoggerWithoutTerm(fname string) *Logger

func NewLogger

func NewLogger() *Logger

func (*Logger) Close

func (log *Logger) Close()

func (*Logger) Critical

func (log *Logger) Critical(arg0 interface{}, args ...interface{})

func (*Logger) Debug

func (log *Logger) Debug(arg0 interface{}, args ...interface{})

func (*Logger) Error

func (log *Logger) Error(arg0 interface{}, args ...interface{})

func (*Logger) Info

func (log *Logger) Info(arg0 interface{}, args ...interface{})

func (*Logger) SetFileLevel

func (log *Logger) SetFileLevel(lvl Level, fname string, param ...int)

等级 文件名 log文件最大值 是否每天滚动 最大备份文件个数 param: maxsize int (the maxsize of single log file), daily int(is rotate daily), maxbackup int(max count of the backup log files)

func (*Logger) SetLevel

func (log *Logger) SetLevel(lvl Level)

func (*Logger) SetTermLevel

func (log *Logger) SetTermLevel(lvl Level)

func (*Logger) System

func (log *Logger) System(arg0 interface{}, args ...interface{})

func (*Logger) Warn

func (log *Logger) Warn(arg0 interface{}, args ...interface{})

type LoopService

type LoopService interface {
	Init() bool
	Loop()
}

type MsgParse

type MsgParse interface {
	//*Session:session which recved message
	//CMDType:event type of msg
	//[]byte:recved data now;
	//int:length of recved data parsed;
	ParseMsg(sess *Session, data []byte) int
	// contains filtered or unexported methods
}

type ReqProto

type ReqProto struct {
	ReqCmdId  uint32
	ReqCmdSeq uint32
	ReqData   []byte
	IsOneWay  bool
	FuncName  string
}

type RpcFuncException

type RpcFuncException func(rspCode int32)

type RpcService

type RpcService interface {
	Loop()
	HandleError(current *CurrentContent, err error)

	HashProcessor(current *CurrentContent) (processorID int)
}

type RspProto

type RspProto struct {
	RspCmdId  uint32
	RspCmdSeq uint32
	PushSeqId uint32
	RspCode   int32
	RspData   []byte
	FuncName  string
}

type Server

type Server struct {
	ProcessorThreadsNum int //number of threads in server.
	// contains filtered or unexported fields
}

func NewServer

func NewServer(loopmsec uint32, threadnum int) *Server

NewServer threadnum is the number of the server's running thread.

func (*Server) AddEchoService

func (svr *Server) AddEchoService(name, address string, heartbeat uint32, threadId int) (*Service, error)

func (*Server) AddHttpService

func (svr *Server) AddHttpService(name, address string, heartbeat uint32, imp HttpService, h *HttpHandler, threadId int) (*Service, error)

AddHttpService rsp: HttpHandler

func (*Server) AddJsonService

func (svr *Server) AddJsonService(name, address string, heartbeat uint32, imp JsonService, threadId int) (*Service, error)

AddJsonService use SendJsonCmd to send message

func (*Server) AddLoopService

func (svr *Server) AddLoopService(name string, imp LoopService, threadId int) (*Service, error)

func (*Server) AddRpcService

func (svr *Server) AddRpcService(name, address string, heartbeat uint32, imp *ServiceRpc, threadId int) (*Service, error)

AddRpcService imp: NewServiceRpc

func (*Server) AddService

func (svr *Server) AddService(name, address string, heartbeat uint32, imp ServiceImp, threadId int) (*Service, error)

AddService must be called before server started. address could be null,then you get a service without listen; address could be udp,example udp:127.0.0.1:6060,default use tcp(127.0.0.1:6060) when heartbeat(second)=0,heartbeat will be close. threadId should be between 1-ProcessorThreadsNum. call Service.NewConnect start a connector

func (*Server) AddSpbService

func (svr *Server) AddSpbService(name, address string, heartbeat uint32, imp *ServiceSpb, threadId int) (*Service, error)

AddSpbService imp: NewServiceSpb, use SendSpbCmd to send message, RegisterMsg to register msg.

func (*Server) AddTcpProxyService

func (svr *Server) AddTcpProxyService(address string, heartbeat uint32, threadId int, proxyaddr []string, proxyweight []int) error

func (*Server) PushRequest

func (svr *Server) PushRequest(servicename string, sess *Session, msgid int64, msg interface{}) error

PushRequest push message into handle thread;id of thread is the result of ServiceImp.HashProcessor

func (*Server) SetLogLvl

func (svr *Server) SetLogLvl(lvl Level)

SetLogLvl open or close system log.

func (*Server) Start

func (svr *Server) Start() error

func (*Server) Stop

func (svr *Server) Stop()

type Service

type Service struct {
	*Listener
	Name string
	// contains filtered or unexported fields
}

func (*Service) GetConnect

func (service *Service) GetConnect(id uint64) *Connect

func (*Service) Imp

func (service *Service) Imp() ServiceImp

func (*Service) IterateConnect

func (service *Service) IterateConnect(callback func(*Connect) bool)

func (*Service) NewConnect

func (service *Service) NewConnect(address string, userdata interface{}) *Connect

NewConnect reconnect at 0 1 4 9 16...times reconnectMSec(100ms);when call send or changeAddr, it will NotifyReconn and reconnect at once;when call Close, reconnect will stop

func (*Service) ParseMsg

func (service *Service) ParseMsg(sess *Session, data []byte) int

func (*Service) PushRequest

func (service *Service) PushRequest(sess *Session, msgid int64, msg interface{}) error

type ServiceBase

type ServiceBase struct {
}

ServiceImpBase

func (*ServiceBase) Destroy

func (service *ServiceBase) Destroy()

func (*ServiceBase) HandleError

func (service *ServiceBase) HandleError(current *CurrentContent, err error)

func (*ServiceBase) HandleMessage

func (service *ServiceBase) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})

func (*ServiceBase) HashProcessor

func (service *ServiceBase) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)

processorID is the thread who process this msg;it should between 1-ProcessorThreadsNum. if processorID == 0, it only uses main thread of the service. if processorID < 0, it will use hash of session id.

func (*ServiceBase) HeartBeatTimeOut

func (service *ServiceBase) HeartBeatTimeOut(sess *Session)

func (*ServiceBase) Init

func (service *ServiceBase) Init() bool

func (*ServiceBase) Loop

func (service *ServiceBase) Loop()

func (*ServiceBase) SessionClose

func (service *ServiceBase) SessionClose(sess *Session)

func (*ServiceBase) SessionOpen

func (service *ServiceBase) SessionOpen(sess *Session)

func (*ServiceBase) Unmarshal

func (service *ServiceBase) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)

type ServiceEcho

type ServiceEcho struct {
	ServiceBase
}

ServiceImpEcho

func (*ServiceEcho) HashProcessor

func (service *ServiceEcho) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)

func (*ServiceEcho) Unmarshal

func (service *ServiceEcho) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)

type ServiceHttp

type ServiceHttp struct {
	ServiceBase
	// contains filtered or unexported fields
}

ServiceHttp

func (*ServiceHttp) HandleError

func (service *ServiceHttp) HandleError(current *CurrentContent, err error)

func (*ServiceHttp) HandleMessage

func (service *ServiceHttp) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})

func (*ServiceHttp) HashProcessor

func (service *ServiceHttp) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)

func (*ServiceHttp) Init

func (service *ServiceHttp) Init() bool

func (*ServiceHttp) Loop

func (service *ServiceHttp) Loop()

func (*ServiceHttp) Unmarshal

func (service *ServiceHttp) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)

type ServiceImp

type ServiceImp interface {
	Init() bool
	Loop()
	Destroy()

	//in hash thread by HashProcessor
	HandleMessage(current *CurrentContent, msgID uint64, msg interface{})
	//in main thread of service
	HandleError(*CurrentContent, error)
	SessionClose(sess *Session)
	HeartBeatTimeOut(sess *Session)
	//in random thread
	SessionOpen(sess *Session)

	// Unmarshal protocol parsed
	//lenParsed is the length read from 'data'.
	//msgID and msg are messages parsed from data.
	//when lenParsed <= 0 or msgID < 0,msg and err will be ignored.
	Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)

	// HashProcessor sess msgID msg are returned by func of Unmarshal
	//processorID is the thread who process this msg;it should be between 1-ProcessorThreadsNum.
	//if processorID == 0, it only uses main thread of the service.
	//if processorID < 0, it will use hash of session id.
	HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)
}

type ServiceJson

type ServiceJson struct {
	ServiceBase
	// contains filtered or unexported fields
}

ServiceJson

func (*ServiceJson) HandleError

func (service *ServiceJson) HandleError(current *CurrentContent, err error)

func (*ServiceJson) HandleMessage

func (service *ServiceJson) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})

func (*ServiceJson) HashProcessor

func (service *ServiceJson) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)

func (*ServiceJson) Init

func (service *ServiceJson) Init() bool

func (*ServiceJson) Loop

func (service *ServiceJson) Loop()

func (*ServiceJson) Unmarshal

func (service *ServiceJson) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)

type ServiceLoop

type ServiceLoop struct {
	ServiceBase
	// contains filtered or unexported fields
}

func (*ServiceLoop) Init

func (service *ServiceLoop) Init() bool

func (*ServiceLoop) Loop

func (service *ServiceLoop) Loop()

type ServiceProxyC

type ServiceProxyC struct {
	ServiceBase
}

func (*ServiceProxyC) HashProcessor

func (service *ServiceProxyC) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)

func (*ServiceProxyC) Unmarshal

func (service *ServiceProxyC) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)

type ServiceProxyS

type ServiceProxyS struct {
	ServiceBase
	// contains filtered or unexported fields
}

func (*ServiceProxyS) HandleError

func (service *ServiceProxyS) HandleError(current *CurrentContent, err error)

func (*ServiceProxyS) HashProcessor

func (service *ServiceProxyS) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)

func (*ServiceProxyS) HeartBeatTimeOut

func (service *ServiceProxyS) HeartBeatTimeOut(sess *Session)

func (*ServiceProxyS) SessionClose

func (service *ServiceProxyS) SessionClose(sess *Session)

func (*ServiceProxyS) SessionOpen

func (service *ServiceProxyS) SessionOpen(sess *Session)

func (*ServiceProxyS) Unmarshal

func (service *ServiceProxyS) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)

type ServiceRpc

type ServiceRpc struct {
	ServiceBase
	// contains filtered or unexported fields
}

func NewServiceRpc

func NewServiceRpc(imp RpcService) *ServiceRpc

func (*ServiceRpc) HandleError

func (service *ServiceRpc) HandleError(current *CurrentContent, err error)

func (*ServiceRpc) HandleMessage

func (service *ServiceRpc) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})

func (*ServiceRpc) HashProcessor

func (service *ServiceRpc) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)

func (*ServiceRpc) Init

func (service *ServiceRpc) Init() bool

func (*ServiceRpc) Loop

func (service *ServiceRpc) Loop()

func (*ServiceRpc) RpcCall

func (service *ServiceRpc) RpcCall(sess *Session, funcName string, params ...interface{}) error

RpcCall remotesession remotefunction(string) functionparams callback(could nil) exception(could nil, func(rspCode int32))

func (*ServiceRpc) RpcCall_Sync

func (service *ServiceRpc) RpcCall_Sync(sess *Session, funcName string, params ...interface{}) error

func (*ServiceRpc) UdpRpcCall

func (service *ServiceRpc) UdpRpcCall(sess *Session, peer net.Addr, funcName string, params ...interface{}) error

func (*ServiceRpc) UdpRpcCall_Sync

func (service *ServiceRpc) UdpRpcCall_Sync(sess *Session, peer net.Addr, funcName string, params ...interface{}) error

func (*ServiceRpc) Unmarshal

func (service *ServiceRpc) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)

type ServiceSpb

type ServiceSpb struct {
	ServiceBase
	// contains filtered or unexported fields
}

ServiceSpb

func NewServiceSpb

func NewServiceSpb(imp SpbService) *ServiceSpb

func (*ServiceSpb) HandleError

func (service *ServiceSpb) HandleError(current *CurrentContent, err error)

func (*ServiceSpb) HandleMessage

func (service *ServiceSpb) HandleMessage(current *CurrentContent, msgID uint64, msg interface{})

func (*ServiceSpb) HashProcessor

func (service *ServiceSpb) HashProcessor(current *CurrentContent, msgID uint64, msg interface{}) (processorID int)

func (*ServiceSpb) Init

func (service *ServiceSpb) Init() bool

func (*ServiceSpb) Loop

func (service *ServiceSpb) Loop()

func (*ServiceSpb) RegisterMsg

func (service *ServiceSpb) RegisterMsg(msgId uint64, msg interface{}) error

func (*ServiceSpb) Unmarshal

func (service *ServiceSpb) Unmarshal(sess *Session, data []byte) (lenParsed int, msgID int64, msg interface{}, err error)

type Session

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

func NewSession

func NewSession(con net.Conn, msgparse MsgParse, onopen FuncOnOpen, onclose FuncOnClose, heartbeat uint32, isudp bool) (*Session, error)

func (*Session) Close

func (s *Session) Close()

func (*Session) Connector

func (s *Session) Connector() *Connector

func (*Session) GetID

func (s *Session) GetID() uint64

func (*Session) IsClose

func (s *Session) IsClose() bool

func (*Session) Peer

func (s *Session) Peer() net.Addr

func (*Session) RemoteAddr

func (s *Session) RemoteAddr() string

func (*Session) Send

func (s *Session) Send(data []byte, peerUdp net.Addr) error

Send peer is used in udp

type Spb

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

type SpbService

type SpbService interface {
	Init() bool
	Loop()
	Handle(current *CurrentContent, cmdId uint64, cmd interface{}, e error)
	HashProcessor(current *CurrentContent, cmdId uint64) (processorID int)
}

Jump to

Keyboard shortcuts

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