Compare commits
9 Commits
bcaf9030aa
...
5b63b517c8
Author | SHA1 | Date |
---|---|---|
|
5b63b517c8 | |
|
c5b755c8bb | |
|
147f0a31a0 | |
|
9c596a8a9d | |
|
389de7c57c | |
|
be6af14261 | |
|
4b50f06f43 | |
|
6d0b8fe6c5 | |
|
30072b17a4 |
21
CHANGELOG.md
21
CHANGELOG.md
|
@ -1,5 +1,26 @@
|
|||
# Changelog
|
||||
|
||||
## [0.5.8](https://github.com/kercylan98/minotaur/compare/v0.5.7...v0.5.8) (2024-05-01)
|
||||
|
||||
|
||||
### Features | 新特性
|
||||
|
||||
* server 新增 NewOfflineConn 函数,兼容部分特殊操作 ([147f0a3](https://github.com/kercylan98/minotaur/commit/147f0a31a0859502cc32775751cadb48fd31181f))
|
||||
|
||||
## [0.5.7](https://github.com/kercylan98/minotaur/compare/v0.5.6...v0.5.7) (2024-04-23)
|
||||
|
||||
|
||||
### Bug Fixes | 修复
|
||||
|
||||
* 修复 timer.Pool 在获取到池中 Ticker 时,可选项不生效的问题 ([be6af14](https://github.com/kercylan98/minotaur/commit/be6af14261a200ac3911ebdef1edf2cae2e35f3d))
|
||||
|
||||
## [0.5.6](https://github.com/kercylan98/minotaur/compare/v0.5.5...v0.5.6) (2024-04-19)
|
||||
|
||||
|
||||
### Bug Fixes | 修复
|
||||
|
||||
* 修复 timer.Ticker 死锁 ([45024f3](https://github.com/kercylan98/minotaur/commit/45024f3b9fe41131dab65ba0ead4361ad0a0d23b))
|
||||
|
||||
## [0.5.5](https://github.com/kercylan98/minotaur/compare/v0.5.4...v0.5.5) (2024-04-10)
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/panjf2000/gnet"
|
||||
"github.com/xtaci/kcp-go/v5"
|
||||
"io"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -83,6 +84,26 @@ func newWebsocketConn(server *Server, ws *websocket.Conn, ip string) *Conn {
|
|||
return c
|
||||
}
|
||||
|
||||
// NewOfflineConn 创建一个离线连接
|
||||
func NewOfflineConn(server *Server) *Conn {
|
||||
addr := &net.TCPAddr{
|
||||
IP: net.ParseIP(random.IPv4()),
|
||||
Port: random.Int(65536, math.MaxInt),
|
||||
}
|
||||
c := &Conn{
|
||||
ctx: server.ctx,
|
||||
connection: &connection{
|
||||
server: server,
|
||||
remoteAddr: addr,
|
||||
ip: addr.String(),
|
||||
data: map[any]any{},
|
||||
openTime: time.Now(),
|
||||
offline: true,
|
||||
},
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// newBotConn 创建一个适用于测试等情况的机器人连接
|
||||
func newBotConn(server *Server) *Conn {
|
||||
ip, port := random.NetIP(), random.Port()
|
||||
|
@ -132,6 +153,7 @@ type connection struct {
|
|||
delay time.Duration
|
||||
fluctuation time.Duration
|
||||
botWriter atomic.Pointer[io.Writer]
|
||||
offline bool
|
||||
}
|
||||
|
||||
// Ticker 获取定时器
|
||||
|
@ -257,6 +279,9 @@ func (slf *Conn) PushUniqueAsyncMessage(name string, caller func() error, callba
|
|||
|
||||
// Write 向连接中写入数据
|
||||
func (slf *Conn) Write(packet []byte, callback ...func(err error)) {
|
||||
if slf.offline {
|
||||
return
|
||||
}
|
||||
if slf.gw != nil {
|
||||
slf.gw(packet)
|
||||
return
|
||||
|
@ -333,6 +358,10 @@ func (slf *Conn) init() {
|
|||
|
||||
// Close 关闭连接
|
||||
func (slf *Conn) Close(err ...error) {
|
||||
if slf.offline {
|
||||
slf.server.dispatcherMgr.UnBindProducer(slf.GetID())
|
||||
return
|
||||
}
|
||||
slf.mu.Lock()
|
||||
if slf.closed {
|
||||
if slf.ticker != nil {
|
||||
|
|
|
@ -46,6 +46,9 @@ func (slf *Pool) GetTicker(size int, options ...Option) *Ticker {
|
|||
if len(slf.tickers) > 0 {
|
||||
ticker = slf.tickers[0]
|
||||
slf.tickers = slf.tickers[1:]
|
||||
for _, option := range options {
|
||||
option(ticker)
|
||||
}
|
||||
return ticker
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue