Documentation ¶
Index ¶
- Constants
- func BytesToInt32(b []byte, order binary.ByteOrder) int32
- func BytesToInt64(b []byte, order binary.ByteOrder) int64
- func BytesToNumber[T int8 | int16 | int32 | int64 | uint16 | uint32 | uint64 | float32 | float64](b []byte, order binary.ByteOrder) T
- func BytesToUInt16(b []byte, order binary.ByteOrder) uint16
- func CheckConns(root *Conn)
- func CheckWorks(works *Work)
- func NumberToBytes[T int8 | int16 | int32 | int64 | uint16 | uint32 | uint64 | float32 | float64](v T, order binary.ByteOrder) []byte
- func SliceString(array []byte) string
- type Conn
- func (c *Conn) Add(conn *Conn)
- func (c *Conn) CheckReadable(checker func(buffer *[]byte, i int32, o int32, length int32) bool) bool
- func (c *Conn) GetId() int32
- func (c *Conn) Handler()
- func (c *Conn) Read(data *[]byte, length int32)
- func (c *Conn) Reconnect()
- func (c *Conn) Release()
- func (c *Conn) SetDisconnectTime(second time.Duration)
- func (c *Conn) SetReadBuffer(packet *Packet)
- func (c *Conn) SetWriteBuffer(data *[]byte, length int32)
- func (c *Conn) String() string
- func (c *Conn) Write() error
- type ConnBuffer
- type ConnMode
- type LoopState
- type OnEventsFunc
- type Packet
- type Tcp0
- type TransData
- func (t *TransData) AddBoolean(v bool)
- func (t *TransData) AddByte(v byte)
- func (t *TransData) AddByteArray(v []byte)
- func (t *TransData) AddFloat32(v float32)
- func (t *TransData) AddFloat64(v float64)
- func (t *TransData) AddInt16(v int16)
- func (t *TransData) AddInt32(v int32)
- func (t *TransData) AddInt64(v int64)
- func (t *TransData) AddInt8(v int8)
- func (t *TransData) AddJson(v map[string]string)
- func (t *TransData) AddRawData(v []byte)
- func (t *TransData) AddString(v string)
- func (t *TransData) AddUInt16(v uint16)
- func (t *TransData) AddUInt32(v uint32)
- func (t *TransData) AddUInt64(v uint64)
- func (t *TransData) Clear()
- func (t TransData) FormData() []byte
- func (t *TransData) GetCapacity() int32
- func (t TransData) GetData() []byte
- func (t *TransData) GetLength() int32
- func (t *TransData) InsertInt32(v int32)
- func (t *TransData) PopBoolean() bool
- func (t *TransData) PopByte() byte
- func (t *TransData) PopByteArray() []byte
- func (t *TransData) PopFloat32() float32
- func (t *TransData) PopFloat64() float64
- func (t *TransData) PopInt16() int16
- func (t *TransData) PopInt32() int32
- func (t *TransData) PopInt64() int64
- func (t *TransData) PopInt8() int8
- func (t *TransData) PopJson() map[string]string
- func (t *TransData) PopString() string
- func (t *TransData) PopUInt16() uint16
- func (t *TransData) PopUInt32() uint32
- func (t *TransData) PopUInt64() uint64
- func (t *TransData) ResetIndex()
- func (t *TransData) SetCapacity(capacity int32)
- func (t *TransData) SetOrder(order binary.ByteOrder)
- type Work
- type WorkState
Constants ¶
View Source
const ( // max int32 = 2^31,這裡取小於 max int32 的最大二次冪數 LIMIT_SIZE int32 = 1073741824 )
View Source
const ( // 最大傳輸單元(Maximum Transmission Unit): 最大封包大小 MTU int32 = 1500 )
Variables ¶
This section is empty.
Functions ¶
func BytesToNumber ¶
func CheckConns ¶
func CheckConns(root *Conn)
func CheckWorks ¶
func CheckWorks(works *Work)
func NumberToBytes ¶
func NumberToBytes[T int8 | int16 | int32 | int64 | uint16 | uint32 | uint64 | float32 | float64](v T, order binary.ByteOrder) []byte
===== 轉 byte 陣列 ===== 數字 轉 byte 陣列
func SliceString ¶
Types ¶
type Conn ¶
type Conn struct { // ================================================== // 連線結構 // ================================================== // 連線物件 NetConn net.Conn // 連線狀態 State define.ConnectState // 連線模式(當 client 和 server 通信時對於長鏈接如何進行處理。) Mode ConnMode // 斷線時間戳(數秒後才切斷連線,預留時間給對方讀取數據) DisconnectTime time.Time // 下一個連線結構的指標 Next *Conn // ================================================== // 讀寫結構 // ================================================== // 緩衝長度 BufferLength int32 // 可讀取長度(readInput ~ readOutput 之間的數據量) ReadableLength int32 // 下次讀取長度 ReadLength int32 // 讀取封包通道 ReadCh chan *Packet // 可寫出長度(writeInput ~ writeOutput 之間的數據量) WritableLength int32 // contains filtered or unexported fields }
func (*Conn) CheckReadable ¶
func (c *Conn) CheckReadable(checker func(buffer *[]byte, i int32, o int32, length int32) bool) bool
根據 checker 函式,檢查是否已讀取到所需的數據(條件可能是 長度 或 換行符 等)
func (*Conn) Reconnect ¶
func (c *Conn) Reconnect()
當有需要重新連線的情況下,首先就會發生 Socket 讀取異常,並導致 Handler 的 goroutine 結束,因此無須再利用 c.stopCh 將 Handler 結束
func (*Conn) SetDisconnectTime ¶
func (*Conn) SetWriteBuffer ¶
將寫出數據加入緩存 TODO: 檢查 c.writeInput 是否反超 c.writeOutput,若反超,表示緩衝大小不足
type ConnBuffer ¶
type OnEventsFunc ¶ added in v1.2.2
type Packet ¶
type Tcp0 ¶
type Tcp0 struct { // 讀取狀態值 | 0: 讀取數據長度, 1: 根據前一階段取得的長度,讀取數據 State int8 HeaderSize int32 ReadLength int32 }
func (*Tcp0) ReadableChecker ¶
檢查是否滿足:可讀長度 大於 欲讀取長度
func (*Tcp0) ResetReadLength ¶
func (t *Tcp0) ResetReadLength()
type TransData ¶
type TransData struct {
// contains filtered or unexported fields
}
func LoadTransData ¶
func NewTransData ¶
func NewTransData() *TransData
func (*TransData) AddBoolean ¶
func (*TransData) AddByteArray ¶
func (*TransData) AddFloat32 ¶
func (*TransData) AddFloat64 ¶
func (*TransData) AddRawData ¶
func (*TransData) GetCapacity ¶
func (*TransData) InsertInt32 ¶
func (*TransData) PopBoolean ¶
func (*TransData) PopByteArray ¶
func (*TransData) PopFloat32 ¶
func (*TransData) PopFloat64 ¶
func (*TransData) ResetIndex ¶
func (t *TransData) ResetIndex()
func (*TransData) SetCapacity ¶
type Work ¶
type Work struct { // 對應的 Conn id 的 Index(空閒 Context id = -1,因此 Index 預設值為 -2,要和前者做區分) Index int32 // 請求發起的時間(若距離實際處理的時間過長,則不處理) RequestTime time.Time // 下一個工作 Next *Work // 工作狀態 -1: 空閒; 0: 完成; 1: 尚未完成; 2: 需寫出數據 State WorkState // 數據緩衝 Data []byte // 數據長度 Length int32 // 數據封裝容器 Body *TransData // contains filtered or unexported fields }
封裝基本連線物件,提供給外部存取
Source Files ¶
Click to show internal directories.
Click to hide internal directories.