channel

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: GPL-2.0 Imports: 12 Imported by: 5

Documentation

Index

Constants

View Source
const (
	Int16Size int32 = 2
	Int32Size int32 = 4
)
View Source
const (
	ChannelChanSize int32 = 10 // 线程队列池大小,太小容易死锁
)
View Source
const (
	ChannelKey string = "ChannelKey"
)

Variables

This section is empty.

Functions

func Int16ToByte

func Int16ToByte(v int16) (buf []byte)

func Int32ToByte

func Int32ToByte(v int32) (buf []byte)

Types

type Attr

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

func NewAttr

func NewAttr(params map[string]interface{}) (attr *Attr)

func (*Attr) Get

func (attr *Attr) Get(key string) (value interface{})

func (*Attr) GetBool

func (attr *Attr) GetBool(key string) bool

func (*Attr) GetInt

func (attr *Attr) GetInt(key string) int

func (*Attr) GetInt16

func (attr *Attr) GetInt16(key string) int16

func (*Attr) GetInt32

func (attr *Attr) GetInt32(key string) int32

func (*Attr) GetInt64

func (attr *Attr) GetInt64(key string) int64

func (*Attr) GetInt8

func (attr *Attr) GetInt8(key string) int8

func (*Attr) GetString

func (attr *Attr) GetString(key string) string

func (*Attr) Set

func (attr *Attr) Set(key string, value interface{})

type Channel

type Channel interface {
	IAttr

	Write(data []byte)

	Close()

	ID() string

	RemoteAddr() string
}

type ChannelBuilder

type ChannelBuilder interface {
	Create(conn *net.TCPConn, channelInitializer ChannelInitializer)
}

type ChannelContext

type ChannelContext interface {
	ChannelInboundInvoker

	ChannelOutboundInvoker

	ContextAttr() IAttr

	ID() string

	RemoteAddr() string

	/*发起写事件,消息将被送往管道处理*/
	Write(data interface{})

	/*发起关闭事件,消息将被送往管道处理*/
	Close()
	// contains filtered or unexported methods
}

type ChannelHandler

type ChannelHandler interface {
	ExceptionCaught(ctx ChannelContext, err error)
}

type ChannelInboundHandler

type ChannelInboundHandler interface {
	ChannelHandler
	ChannelActive(ctx ChannelContext) (goonNext bool)
	MessageReceived(ctx ChannelContext, e interface{}) (ret interface{}, goonNext bool)
	ChannelInactive(ctx ChannelContext) (goonNext bool)
}

type ChannelInboundInvoker

type ChannelInboundInvoker interface {
	FireChannelActive()
	FireMessageReceived(event interface{})
	FireChannelInactive()
	FireExceptionCaught(err error)
}

type ChannelInitializer

type ChannelInitializer interface {
	InitChannel(pipeline ChannelPipeline)
}

type ChannelOutboundHandler

type ChannelOutboundHandler interface {
	ChannelHandler
	Write(ctx ChannelContext, e interface{}) (ret interface{})
	Close(ctx ChannelContext)
}

type ChannelOutboundInvoker

type ChannelOutboundInvoker interface {
	FireMessageWrite(e interface{})
	FireChannelClose()
}

type ChannelPipeline

type ChannelPipeline interface {
	ChannelInboundInvoker
	ChannelOutboundInvoker
	AddFirst(name string, handler ChannelHandler) (pipeline ChannelPipeline)
	AddLast(name string, handler ChannelHandler) (pipeline ChannelPipeline)

	ContextAttr() IAttr
	// contains filtered or unexported methods
}

type DefaultChannelHandlerContext

type DefaultChannelHandlerContext struct {
	Name string
	Next *DefaultChannelHandlerContext
	Prev *DefaultChannelHandlerContext
	// contains filtered or unexported fields
}

func (*DefaultChannelHandlerContext) Close

func (this *DefaultChannelHandlerContext) Close()

发起关闭事件,消息将被送往管道处理

func (*DefaultChannelHandlerContext) ContextAttr

func (this *DefaultChannelHandlerContext) ContextAttr() IAttr

func (*DefaultChannelHandlerContext) FireChannelActive

func (this *DefaultChannelHandlerContext) FireChannelActive()

func (*DefaultChannelHandlerContext) FireChannelClose

func (this *DefaultChannelHandlerContext) FireChannelClose()

func (*DefaultChannelHandlerContext) FireChannelInactive

func (this *DefaultChannelHandlerContext) FireChannelInactive()

func (*DefaultChannelHandlerContext) FireExceptionCaught

func (this *DefaultChannelHandlerContext) FireExceptionCaught(err error)

func (*DefaultChannelHandlerContext) FireMessageReceived

func (this *DefaultChannelHandlerContext) FireMessageReceived(event interface{})

func (*DefaultChannelHandlerContext) FireMessageWrite

func (this *DefaultChannelHandlerContext) FireMessageWrite(event interface{})

func (*DefaultChannelHandlerContext) ID

func (*DefaultChannelHandlerContext) RemoteAddr

func (this *DefaultChannelHandlerContext) RemoteAddr() string

func (*DefaultChannelHandlerContext) Write

func (this *DefaultChannelHandlerContext) Write(e interface{})

发起写事件,消息将被送往管道处理

type DefaultChannelPipeline

type DefaultChannelPipeline struct {
	Lock *sync.Mutex
	Head *DefaultChannelHandlerContext
	Tail *DefaultChannelHandlerContext
	// contains filtered or unexported fields
}

func NewDefaultChannelPipeline

func NewDefaultChannelPipeline(channel Channel) (pipeline *DefaultChannelPipeline)

func (*DefaultChannelPipeline) AddFirst

func (pipeline *DefaultChannelPipeline) AddFirst(name string, handler ChannelHandler) ChannelPipeline

func (*DefaultChannelPipeline) AddLast

func (pipeline *DefaultChannelPipeline) AddLast(name string, handler ChannelHandler) ChannelPipeline

func (*DefaultChannelPipeline) ContextAttr

func (this *DefaultChannelPipeline) ContextAttr() IAttr

func (*DefaultChannelPipeline) FireChannelActive

func (this *DefaultChannelPipeline) FireChannelActive()

func (*DefaultChannelPipeline) FireChannelClose

func (this *DefaultChannelPipeline) FireChannelClose()

func (*DefaultChannelPipeline) FireChannelInactive

func (this *DefaultChannelPipeline) FireChannelInactive()

func (*DefaultChannelPipeline) FireExceptionCaught

func (this *DefaultChannelPipeline) FireExceptionCaught(err error)

func (*DefaultChannelPipeline) FireMessageReceived

func (this *DefaultChannelPipeline) FireMessageReceived(event interface{})

func (*DefaultChannelPipeline) FireMessageWrite

func (this *DefaultChannelPipeline) FireMessageWrite(event interface{})

type DefaultMessageSpliter

type DefaultMessageSpliter struct {
}

func NewDefaultMessageSpliter

func NewDefaultMessageSpliter() (this *DefaultMessageSpliter)

func (*DefaultMessageSpliter) GetBytesCountForMessageLength

func (builder *DefaultMessageSpliter) GetBytesCountForMessageLength() int8

type HeadHandler

type HeadHandler struct {
}

func (*HeadHandler) ChannelActive

func (this *HeadHandler) ChannelActive(ctx ChannelContext) (goonNext bool)

func (*HeadHandler) ChannelInactive

func (this *HeadHandler) ChannelInactive(ctx ChannelContext) (goonNext bool)

func (*HeadHandler) ExceptionCaught

func (this *HeadHandler) ExceptionCaught(ctx ChannelContext, err error)

func (*HeadHandler) MessageReceived

func (this *HeadHandler) MessageReceived(ctx ChannelContext, e interface{}) (ret interface{}, goonNext bool)

type IAttr

type IAttr interface {
	Get(key string) (value interface{})
	GetBool(key string) bool
	GetInt8(key string) (value int8)
	GetInt16(key string) (value int16)
	GetInt32(key string) (value int32)
	GetInt64(key string) (value int64)
	GetInt(key string) (value int)
	GetString(key string) (value string)
	Set(key string, value interface{})
}

type IChannelCallBack

type IChannelCallBack interface {
	Active()
	MsgReceived(data []byte)
	Inactive()
}

type IChannelError

type IChannelError interface {
	IOReadError(err error)
	IOWriteError(err error)
}

type MessageSpliter

type MessageSpliter interface {
	GetBytesCountForMessageLength() int8
}

type SocketChannel

type SocketChannel struct {
	Attr
	// contains filtered or unexported fields
}

func NewSocketChannel

func NewSocketChannel(params map[string]interface{}, conn net.Conn, channelInitializer ChannelInitializer) (this *SocketChannel)

func (*SocketChannel) Active

func (chanenl *SocketChannel) Active()

for ChannelCallBack

func (*SocketChannel) Close

func (chanenl *SocketChannel) Close()

for Channel

func (*SocketChannel) ID

func (chanenl *SocketChannel) ID() string

func (*SocketChannel) IOReadError

func (chanenl *SocketChannel) IOReadError(err error)

for ChannelError

func (*SocketChannel) IOWriteError

func (chanenl *SocketChannel) IOWriteError(err error)

func (*SocketChannel) Inactive

func (chanenl *SocketChannel) Inactive()

for ChannelCallBack

func (*SocketChannel) MsgReceived

func (chanenl *SocketChannel) MsgReceived(data []byte)

for ChannelCallBack

func (*SocketChannel) RemoteAddr

func (chanenl *SocketChannel) RemoteAddr() string

for Channel

func (*SocketChannel) Start

func (chanenl *SocketChannel) Start()

func (*SocketChannel) Write

func (chanenl *SocketChannel) Write(data []byte)

for Channel

type SocketChannelBuilder

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

func NewSocketChannelBuilder

func NewSocketChannelBuilder() (this *SocketChannelBuilder)

func (*SocketChannelBuilder) Create

func (builder *SocketChannelBuilder) Create(conn net.Conn, channelInitializer ChannelInitializer)

func (*SocketChannelBuilder) Params

func (builder *SocketChannelBuilder) Params(channelParams map[string]interface{})

type SocketChannelReader

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

func NewSocketChannelReader

func NewSocketChannelReader(mConn net.Conn,
	mContext Channel,
	mChannelError IChannelError,
	mChannelCallBack IChannelCallBack) (this *SocketChannelReader)

func (*SocketChannelReader) Start

func (reader *SocketChannelReader) Start()

type SocketChannelWriter

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

func NewSocketChannelWriter

func NewSocketChannelWriter(mConn net.Conn,
	mContext Channel,
	mChannelError IChannelError,
	mChannelCallBack IChannelCallBack) (this *SocketChannelWriter)

func (*SocketChannelWriter) Close

func (chanenl *SocketChannelWriter) Close()

关闭写线程消息队列

func (*SocketChannelWriter) Start

func (chanenl *SocketChannelWriter) Start()

func (*SocketChannelWriter) Write

func (chanenl *SocketChannelWriter) Write(data []byte)

往写线程消息队列发送消息

type TailHandler

type TailHandler struct {
}

func (*TailHandler) Close

func (this *TailHandler) Close(ctx ChannelContext)

func (*TailHandler) ExceptionCaught

func (this *TailHandler) ExceptionCaught(ctx ChannelContext, err error)

func (*TailHandler) Write

func (this *TailHandler) Write(ctx ChannelContext, e interface{}) (ret interface{})

type WSConn

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

WSConn is an adapter to t.Conn, which implements all t.Conn interface base on *websocket.Conn

func NewWSConn

func NewWSConn(conn *websocket.Conn) (*WSConn, error)

NewWSConn return an initialized *WSConn

func (*WSConn) Close

func (c *WSConn) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*WSConn) LocalAddr

func (c *WSConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*WSConn) Read

func (c *WSConn) Read(b []byte) (int, error)

Read reads data from the connection. Read can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.

func (*WSConn) RemoteAddr

func (c *WSConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*WSConn) SetDeadline

func (c *WSConn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.

An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.

A zero value for t means I/O operations will not time out.

func (*WSConn) SetReadDeadline

func (c *WSConn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.

func (*WSConn) SetWriteDeadline

func (c *WSConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.

func (*WSConn) Write

func (c *WSConn) Write(b []byte) (int, error)

Write writes data to the connection. Write can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline.

type WriteEvent

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

func NewWriteEvent

func NewWriteEvent(data []byte, isClose bool) (this *WriteEvent)

Jump to

Keyboard shortcuts

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