network

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 19 Imported by: 1

README

network

network

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreeMessage added in v1.0.5

func FreeMessage(msg *Message)

FreeMessage puts a Message into the pool.

func HttpServer added in v1.0.6

func HttpServer(handler http.Handler) *http.Server

func ResetMessage added in v1.0.5

func ResetMessage(m *Message)

ResetMessage reset a Message

func SetRouteVars added in v1.0.6

func SetRouteVars(r *http.Request, val interface{})

func Vars added in v1.0.6

func Vars(r *http.Request) map[string]string

Types

type BufferPacker added in v1.0.4

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

func (*BufferPacker) Pack added in v1.0.4

func (p *BufferPacker) Pack(msgID uint64, msg interface{}) ([]byte, error)

func (*BufferPacker) Read added in v1.0.4

func (p *BufferPacker) Read(conn *TcpSession) ([]byte, error)

Read goroutine safe

func (*BufferPacker) SetMsgLen added in v1.0.4

func (p *BufferPacker) SetMsgLen(lenMsgLen int32, minMsgLen uint32, maxMsgLen uint32)

SetMsgLen It's dangerous to call the method on reading or writing

func (*BufferPacker) Unpack added in v1.0.4

func (p *BufferPacker) Unpack(data []byte) (*Message, error)

Unpack id + protobuf data

func (*BufferPacker) Write added in v1.0.4

func (p *BufferPacker) Write(conn *TcpSession, buff ...byte) error

goroutine safe

type ByteBuffer added in v1.0.4

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

ByteBuffer 字节buff

func NewByteBuffer added in v1.0.4

func NewByteBuffer() *ByteBuffer

NewByteBuffer 创建一个字节buffer

func (*ByteBuffer) Append added in v1.0.4

func (bf *ByteBuffer) Append(buff []byte)

Append ...

func (*ByteBuffer) AppendInt16 added in v1.0.4

func (bf *ByteBuffer) AppendInt16(x int16)

AppendInt16 ...

func (*ByteBuffer) AppendInt32 added in v1.0.4

func (bf *ByteBuffer) AppendInt32(x int32)

AppendInt32 ...

func (*ByteBuffer) AppendInt64 added in v1.0.4

func (bf *ByteBuffer) AppendInt64(x int64)

AppendInt64 ...

func (*ByteBuffer) EnsureWritableBytes added in v1.0.4

func (bf *ByteBuffer) EnsureWritableBytes(len int32)

EnsureWritableBytes ...

func (*ByteBuffer) Length added in v1.0.4

func (bf *ByteBuffer) Length() int32

Length ...

func (*ByteBuffer) NextBytes added in v1.0.4

func (bf *ByteBuffer) NextBytes(len int32) []byte

NextBytes 读取N字节

func (*ByteBuffer) ReadBuff added in v1.0.4

func (bf *ByteBuffer) ReadBuff() []byte

ReadBuff ...

func (*ByteBuffer) ReadInt16 added in v1.0.4

func (bf *ByteBuffer) ReadInt16() int16

ReadInt16 ...

func (*ByteBuffer) ReadInt32 added in v1.0.4

func (bf *ByteBuffer) ReadInt32() int32

ReadInt32 ...

func (*ByteBuffer) ReadInt64 added in v1.0.4

func (bf *ByteBuffer) ReadInt64() int64

ReadInt64 ...

func (*ByteBuffer) Reserve added in v1.0.4

func (bf *ByteBuffer) Reserve(len int32)

Reserve ...

func (*ByteBuffer) Reset added in v1.0.4

func (bf *ByteBuffer) Reset()

Reset ...

func (*ByteBuffer) Retrieve added in v1.0.4

func (bf *ByteBuffer) Retrieve(len int32)

Retrieve ...

func (*ByteBuffer) SetByteOrder added in v1.0.4

func (bf *ByteBuffer) SetByteOrder(littleEndian bool)

SetByteOrder It's dangerous to call the method on reading or writing

func (*ByteBuffer) Skip added in v1.0.4

func (bf *ByteBuffer) Skip(len int32)

Skip advances the reading index of the buffer

func (*ByteBuffer) Swap added in v1.0.4

func (bf *ByteBuffer) Swap(other *ByteBuffer)

Swap ...

func (*ByteBuffer) Truncate added in v1.0.4

func (bf *ByteBuffer) Truncate(n int32)

Truncate ...

func (*ByteBuffer) WriteBuff added in v1.0.4

func (bf *ByteBuffer) WriteBuff() []byte

WriteBuff ...

func (*ByteBuffer) WriteBytes added in v1.0.4

func (bf *ByteBuffer) WriteBytes(n int32)

WriteBytes 写入n字节

type HttpRouter added in v1.0.6

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

func NewHttpRouter added in v1.0.6

func NewHttpRouter() *HttpRouter

func (*HttpRouter) GetPageView added in v1.0.6

func (g *HttpRouter) GetPageView() int64

func (*HttpRouter) Handle added in v1.0.6

func (g *HttpRouter) Handle(method, path string, h http.Handler)

func (*HttpRouter) HandleFunc added in v1.0.6

func (g *HttpRouter) HandleFunc(method, path string, h func(http.ResponseWriter, *http.Request))

func (*HttpRouter) HandleStaticFile added in v1.0.6

func (g *HttpRouter) HandleStaticFile(method, path, dir string)

func (*HttpRouter) ServeHTTP added in v1.0.6

func (g *HttpRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*HttpRouter) SetNotFoundHandler added in v1.0.6

func (g *HttpRouter) SetNotFoundHandler(h http.Handler)

type IPacker

type IPacker interface {
	Pack(msgID uint16, msg interface{}) ([]byte, error)
	Read(*TcpSession) ([]byte, error)
	Unpack([]byte) (*Message, error)
}

type ISession added in v1.0.9

type ISession interface {
	OnConnect()
	OnClose()
	OnMessage(*Message, *TcpSession)
}

type Message

type Message struct {
	ID   uint64
	Data []byte
}

func GetPooledMessage added in v1.0.5

func GetPooledMessage() *Message

GetPooledMessage gets a pooled Message.

type NormalPacker

type NormalPacker struct {
	ByteOrder binary.ByteOrder
}

func (*NormalPacker) Pack

func (p *NormalPacker) Pack(msgID uint16, msg interface{}) ([]byte, error)

func (*NormalPacker) Read added in v1.0.4

func (p *NormalPacker) Read(conn *TcpSession) ([]byte, error)

func (*NormalPacker) Unpack

func (p *NormalPacker) Unpack(data []byte) (*Message, error)

Unpack id + protobuf data

type Packet added in v1.0.4

type Packet struct {
	Msg  *Message
	Conn *TcpSession
}

type RpcServer added in v1.0.6

type RpcServer struct {
	Addr string
	// contains filtered or unexported fields
}

func (*RpcServer) Close added in v1.0.6

func (srv *RpcServer) Close()

func (*RpcServer) Init added in v1.0.6

func (srv *RpcServer) Init(addr string)

func (*RpcServer) Run added in v1.0.6

func (srv *RpcServer) Run()

type TCPKeepAliveListener added in v1.0.8

type TCPKeepAliveListener struct {
	*net.TCPListener
}

func (TCPKeepAliveListener) Accept added in v1.0.8

func (ln TCPKeepAliveListener) Accept() (c net.Conn, err error)

type TcpClient added in v1.0.5

type TcpClient struct {
	*TcpSession
	Address     string
	ChMsg       chan *Message
	OnMessageCb func(message *Packet)

	OnCloseCallBack func()
	// contains filtered or unexported fields
}

func NewClient

func NewClient(address string, connBuffSize int, logger *spoor.Spoor) *TcpClient

func (*TcpClient) Close added in v1.0.5

func (c *TcpClient) Close()

Close 关闭连接

func (*TcpClient) Dial added in v1.0.5

func (c *TcpClient) Dial() (*net.TCPConn, error)

func (*TcpClient) IsRunning added in v1.1.1

func (c *TcpClient) IsRunning() bool

func (*TcpClient) OnClose added in v1.0.5

func (c *TcpClient) OnClose()

func (*TcpClient) OnMessage added in v1.0.5

func (c *TcpClient) OnMessage(data *Message, conn *TcpSession)

func (*TcpClient) Run added in v1.0.5

func (c *TcpClient) Run()

type TcpServer added in v1.0.9

type TcpServer struct {
	Addr       string
	MaxConnNum int

	MessageHandler func(packet *Packet)
	// contains filtered or unexported fields
}

func NewTcpServer added in v1.0.9

func NewTcpServer(addr string, maxConnNum int, buffSize int, logger *spoor.Spoor) *TcpServer

func (*TcpServer) Close added in v1.0.9

func (s *TcpServer) Close()

func (*TcpServer) Init added in v1.0.9

func (s *TcpServer) Init()

func (*TcpServer) OnClose added in v1.0.9

func (s *TcpServer) OnClose()

func (*TcpServer) OnConnect added in v1.0.9

func (s *TcpServer) OnConnect()

func (*TcpServer) OnMessage added in v1.0.9

func (s *TcpServer) OnMessage(message *Message, conn *TcpSession)

func (*TcpServer) Run added in v1.0.9

func (s *TcpServer) Run()

type TcpSession added in v1.0.5

type TcpSession struct {
	Conn   net.Conn
	Impl   ISession
	ConnID int64
	// contains filtered or unexported fields
}

func NewTcpSession added in v1.0.5

func NewTcpSession(conn *net.TCPConn, msgBuffSize int, logger *spoor.Spoor) (*TcpSession, error)

func (*TcpSession) AsyncSend added in v1.0.5

func (c *TcpSession) AsyncSend(msgID uint64, msg interface{}) bool

func (*TcpSession) AsyncSendLastPacket added in v1.0.5

func (c *TcpSession) AsyncSendLastPacket(msgID uint64, msg interface{}) bool

AsyncSendLastPacket 缓存在发送队列里等待发送goroutine取出 (发送最后一个消息 发送会关闭tcp连接 终止tcp goroutine)

func (*TcpSession) AsyncSendRowMsg added in v1.0.5

func (c *TcpSession) AsyncSendRowMsg(data []byte) bool

func (*TcpSession) Close added in v1.0.5

func (c *TcpSession) Close()

func (*TcpSession) Connect added in v1.0.5

func (c *TcpSession) Connect()

func (*TcpSession) HandleRead added in v1.0.5

func (c *TcpSession) HandleRead()

func (*TcpSession) HandleWrite added in v1.0.5

func (c *TcpSession) HandleWrite()

func (*TcpSession) IsClosed added in v1.0.5

func (c *TcpSession) IsClosed() bool

func (*TcpSession) IsShutdown added in v1.0.5

func (c *TcpSession) IsShutdown() bool

func (*TcpSession) LastSignal added in v1.0.5

func (c *TcpSession) LastSignal(signal []byte) error

func (*TcpSession) LocalAddr added in v1.0.5

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

func (*TcpSession) OnClose added in v1.0.5

func (c *TcpSession) OnClose()

func (*TcpSession) OnConnect added in v1.0.5

func (c *TcpSession) OnConnect()

OnConnect ...

func (*TcpSession) Read added in v1.0.5

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

func (*TcpSession) RemoteAddr added in v1.0.5

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

func (*TcpSession) Reset added in v1.0.5

func (c *TcpSession) Reset()

func (*TcpSession) Signal added in v1.0.5

func (c *TcpSession) Signal(signal []byte) error

func (*TcpSession) Verified added in v1.0.5

func (c *TcpSession) Verified() bool

func (*TcpSession) Verify added in v1.0.5

func (c *TcpSession) Verify()

func (*TcpSession) Write added in v1.0.5

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

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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