void

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: MIT Imports: 7 Imported by: 0

README

void

An another net libary of golang.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatchPanic

func CatchPanic(err *error, goRoutine string, functionName string)

CatchPanic is used to catch any Panic and log exceptions to Stdout. It will also write the stack trace.

func NewError

func NewError(s string) error

func NewErrorContext

func NewErrorContext(s string, context interface{}) error

Types

type CloseReason

type CloseReason int32
const (
	CloseReason_IO     CloseReason = iota // 普通IO断开
	CloseReason_Manual                    // 关闭前,调用过Session.Close
)

func (CloseReason) String

func (r CloseReason) String() string

type Codec

type Codec interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
	Name() string
	MimeType() string
}

type Error

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

func (*Error) Error

func (e *Error) Error() string

type Event

type Event interface {
	Session() Session
	Message() interface{}
}

type EventHandler

type EventHandler func(e Event)

type EventHooker

type EventHooker interface {
	OnInboundEvent(input Event) (output Event)
	OnOutboundEvent(input Event) (output Event)
}

type EventQueue

type EventQueue interface {
	StartLoop() EventQueue
	StopLoop() EventQueue
	Wait()
	Post(callback func())
}

type MessageTransmitter

type MessageTransmitter interface {
	OnRecvMessage(s Session) (msg interface{}, err error)
	OnSendMessage(s Session, msg interface{}) error
}

type Meta

type Meta interface {
	TypeName() string
	GetType() reflect.Type
	GetID() int
	NewType() interface{}
	GetCodec() Codec
}

type Peer

type Peer interface {
	PeerProperty
	Start() Peer
	Stop()
	TypeName() string
}

type PeerListener

type PeerListener interface {
	Port() int
}

type PeerProperty

type PeerProperty interface {
	Name() string
	Address() string
	Queue() EventQueue
	SetName(string)
	SetAddress(string)
	SetQueue(EventQueue)
}

type Pipe

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

不限制大小,添加不发生阻塞,接收阻塞等待

func NewPipe

func NewPipe() *Pipe

func (*Pipe) Add

func (p *Pipe) Add(msg interface{})

Add 添加时不会发送阻塞

func (*Pipe) Pick

func (p *Pipe) Pick(retList *[]interface{}) (exit bool)

Pick 从列表获取数据,并清空列表;如果没有数据,发生阻塞

func (*Pipe) Reset

func (p *Pipe) Reset()

type Processor

type Processor interface {
	SetHooker(h EventHooker)
	SetTransmitter(t MessageTransmitter)
	SetHandler(handler EventHandler)
	ReadMessage(s Session) (msg interface{}, err error)
	SendMessage(e Event)
	ProcessEvent(e Event)
}

type Session

type Session interface {
	Raw() interface{}
	Peer() Peer
	Send(msg interface{})
	Close()
	ID() int64
	SetID(int64)
}

type SessionAccepted

type SessionAccepted struct{}

func (*SessionAccepted) String

func (s *SessionAccepted) String() string

func (*SessionAccepted) SystemMessage

func (s *SessionAccepted) SystemMessage()

type SessionAccessor

type SessionAccessor interface {
	GetSession(int64) Session
	VisitSession(func(Session) bool)
	SessionCount() int
	CloseAllSession()
}

type SessionCloseNotify

type SessionCloseNotify struct{}

udp通知关闭,内部使用

func (*SessionCloseNotify) String

func (s *SessionCloseNotify) String() string

func (*SessionCloseNotify) SystemMessage

func (s *SessionCloseNotify) SystemMessage()

type SessionClosed

type SessionClosed struct {
	Reason CloseReason // 断开原因
}

func (*SessionClosed) String

func (s *SessionClosed) String() string

func (*SessionClosed) SystemMessage

func (s *SessionClosed) SystemMessage()

type SessionConnectError

type SessionConnectError struct{}

func (*SessionConnectError) String

func (s *SessionConnectError) String() string

func (*SessionConnectError) SystemMessage

func (s *SessionConnectError) SystemMessage()

type SessionConnected

type SessionConnected struct{}

func (*SessionConnected) String

func (s *SessionConnected) String() string

func (*SessionConnected) SystemMessage

func (s *SessionConnected) SystemMessage()

type SessionInit

type SessionInit struct{}

func (*SessionInit) String

func (s *SessionInit) String() string

func (*SessionInit) SystemMessage

func (s *SessionInit) SystemMessage()

使用类型断言判断是否为系统消息

type SessionManager

type SessionManager interface {
	SessionAccessor
	Add(s Session)
	Remove(s Session)
	Count() int
	SetIDBase(base int64)
}

type TCPAcceptor

type TCPAcceptor interface {
	Peer
	PeerListener
	SessionAccessor
	TCPSocketOption
}

type TCPConnector

type TCPConnector interface {
	Peer
	PeerListener
	TCPSocketOption

	SetReconnectDuration(time.Duration)
	ReconnectDuration() time.Duration
	Session() Session
	SetSessionManager(raw interface{})
}

type TCPSocketOption

type TCPSocketOption interface {
	// 收发缓冲大小,默认-1
	SetSocketBuffer(readBufferSize, writeBufferSize int, noDelay bool)

	// 设置最大的封包大小
	SetMaxPacketSize(maxSize int)

	// 设置读写超时,默认0,不超时
	SetSocketDeadline(read, write time.Duration)

	ApplySocketOption(conn net.Conn)

	MaxPacketSize() int
	ApplySocketReadTimeout(conn net.Conn, callback func())
	ApplySocketWriteTimeout(conn net.Conn, callback func())

	Init()
}

Directories

Path Synopsis
gob
xml
examples
tcp
tcp
lru

Jump to

Keyboard shortcuts

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