Documentation ¶
Index ¶
- Constants
- func Int16ToByte(v int16) (buf []byte)
- func Int32ToByte(v int32) (buf []byte)
- type Attr
- func (attr *Attr) Get(key string) (value interface{})
- func (attr *Attr) GetBool(key string) bool
- func (attr *Attr) GetInt(key string) int
- func (attr *Attr) GetInt16(key string) int16
- func (attr *Attr) GetInt32(key string) int32
- func (attr *Attr) GetInt64(key string) int64
- func (attr *Attr) GetInt8(key string) int8
- func (attr *Attr) GetString(key string) string
- func (attr *Attr) Set(key string, value interface{})
- type Channel
- type ChannelBuilder
- type ChannelContext
- type ChannelHandler
- type ChannelInboundHandler
- type ChannelInboundInvoker
- type ChannelInitializer
- type ChannelOutboundHandler
- type ChannelOutboundInvoker
- type ChannelPipeline
- type DefaultChannelHandlerContext
- func (this *DefaultChannelHandlerContext) Close()
- func (this *DefaultChannelHandlerContext) ContextAttr() IAttr
- func (this *DefaultChannelHandlerContext) FireChannelActive()
- func (this *DefaultChannelHandlerContext) FireChannelClose()
- func (this *DefaultChannelHandlerContext) FireChannelInactive()
- func (this *DefaultChannelHandlerContext) FireExceptionCaught(err error)
- func (this *DefaultChannelHandlerContext) FireMessageReceived(event interface{})
- func (this *DefaultChannelHandlerContext) FireMessageWrite(event interface{})
- func (this *DefaultChannelHandlerContext) ID() string
- func (this *DefaultChannelHandlerContext) RemoteAddr() string
- func (this *DefaultChannelHandlerContext) Write(e interface{})
- type DefaultChannelPipeline
- func (pipeline *DefaultChannelPipeline) AddFirst(name string, handler ChannelHandler) ChannelPipeline
- func (pipeline *DefaultChannelPipeline) AddLast(name string, handler ChannelHandler) ChannelPipeline
- func (this *DefaultChannelPipeline) ContextAttr() IAttr
- func (this *DefaultChannelPipeline) FireChannelActive()
- func (this *DefaultChannelPipeline) FireChannelClose()
- func (this *DefaultChannelPipeline) FireChannelInactive()
- func (this *DefaultChannelPipeline) FireExceptionCaught(err error)
- func (this *DefaultChannelPipeline) FireMessageReceived(event interface{})
- func (this *DefaultChannelPipeline) FireMessageWrite(event interface{})
- type DefaultMessageSpliter
- type HeadHandler
- func (this *HeadHandler) ChannelActive(ctx ChannelContext) (goonNext bool)
- func (this *HeadHandler) ChannelInactive(ctx ChannelContext) (goonNext bool)
- func (this *HeadHandler) ExceptionCaught(ctx ChannelContext, err error)
- func (this *HeadHandler) MessageReceived(ctx ChannelContext, e interface{}) (ret interface{}, goonNext bool)
- type IAttr
- type IChannelCallBack
- type IChannelError
- type MessageSpliter
- type SocketChannel
- func (chanenl *SocketChannel) Active()
- func (chanenl *SocketChannel) Close()
- func (chanenl *SocketChannel) ID() string
- func (chanenl *SocketChannel) IOReadError(err error)
- func (chanenl *SocketChannel) IOWriteError(err error)
- func (chanenl *SocketChannel) Inactive()
- func (chanenl *SocketChannel) MsgReceived(data []byte)
- func (chanenl *SocketChannel) RemoteAddr() string
- func (chanenl *SocketChannel) Start()
- func (chanenl *SocketChannel) Write(data []byte)
- type SocketChannelBuilder
- type SocketChannelReader
- type SocketChannelWriter
- type TailHandler
- type WSConn
- func (c *WSConn) Close() error
- func (c *WSConn) LocalAddr() net.Addr
- func (c *WSConn) Read(b []byte) (int, error)
- func (c *WSConn) RemoteAddr() net.Addr
- func (c *WSConn) SetDeadline(t time.Time) error
- func (c *WSConn) SetReadDeadline(t time.Time) error
- func (c *WSConn) SetWriteDeadline(t time.Time) error
- func (c *WSConn) Write(b []byte) (int, error)
- type WriteEvent
Constants ¶
const ( Int16Size int32 = 2 Int32Size int32 = 4 )
const (
ChannelChanSize int32 = 10 // 线程队列池大小,太小容易死锁
)
const (
ChannelKey string = "ChannelKey"
)
Variables ¶
This section is empty.
Functions ¶
func Int16ToByte ¶
func Int32ToByte ¶
Types ¶
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 (this *DefaultChannelHandlerContext) ID() string
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 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) 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) MsgReceived ¶
func (chanenl *SocketChannel) MsgReceived(data []byte)
for ChannelCallBack
func (*SocketChannel) Start ¶
func (chanenl *SocketChannel) Start()
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) 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 (*WSConn) Close ¶
Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.
func (*WSConn) Read ¶
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 ¶
RemoteAddr returns the remote network address.
func (*WSConn) SetDeadline ¶
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 ¶
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 ¶
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.
type WriteEvent ¶
type WriteEvent struct {
// contains filtered or unexported fields
}
func NewWriteEvent ¶
func NewWriteEvent(data []byte, isClose bool) (this *WriteEvent)
Source Files ¶
- Attr.go
- Channel.go
- ChannelConsts.go
- ChannelHandlerContext.go
- ChannelPipeline.go
- DefaultChannelHandlerContext.go
- DefaultChannelPipeline.go
- DefaultMessageSpliter.go
- Handler.go
- IAttr.go
- Invoker.go
- MessageSpliter.go
- PipelineInitializer.go
- SocketChannel.go
- SocketChannelBuilder.go
- SocketChannelReader.go
- SocketChannelWriter.go
- ws.go