Skip to content

Commit 530affb

Browse files
committed
注册ProcBundle时,可以透传参数
1 parent 4f8cb89 commit 530affb

6 files changed

Lines changed: 10 additions & 12 deletions

File tree

proc/gorillaws/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func init() {
99

10-
proc.RegisterProcessor("gorillaws.ltv", func(bundle proc.ProcessorBundle, userCallback cellnet.EventCallback) {
10+
proc.RegisterProcessor("gorillaws.ltv", func(bundle proc.ProcessorBundle, userCallback cellnet.EventCallback, args ...interface{}) {
1111

1212
bundle.SetTransmitter(new(WSMessageTransmitter))
1313
bundle.SetHooker(new(MsgHooker))

proc/http/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func init() {
99

10-
proc.RegisterProcessor("http", func(bundle proc.ProcessorBundle, userCallback cellnet.EventCallback) {
10+
proc.RegisterProcessor("http", func(bundle proc.ProcessorBundle, userCallback cellnet.EventCallback, args ...interface{}) {
1111
// 如果http的peer有队列,依然会在队列中排队执行
1212
bundle.SetCallback(proc.NewQueuedEventCallback(userCallback))
1313
})

proc/procreg.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sort"
77
)
88

9-
type ProcessorBinder func(bundle ProcessorBundle, userCallback cellnet.EventCallback)
9+
type ProcessorBinder func(bundle ProcessorBundle, userCallback cellnet.EventCallback, args ...interface{})
1010

1111
var (
1212
procByName = map[string]ProcessorBinder{}
@@ -49,13 +49,13 @@ func getPackageByCodecName(name string) string {
4949
}
5050

5151
// 绑定固定回调处理器, procName来源于RegisterProcessor注册的处理器,形如: 'tcp.ltv'
52-
func BindProcessorHandler(peer cellnet.Peer, procName string, userCallback cellnet.EventCallback) {
52+
func BindProcessorHandler(peer cellnet.Peer, procName string, userCallback cellnet.EventCallback, args ...interface{}) {
5353

5454
if proc, ok := procByName[procName]; ok {
5555

5656
bundle := peer.(ProcessorBundle)
5757

58-
proc(bundle, userCallback)
58+
proc(bundle, userCallback, args...)
5959

6060
} else {
6161
panic(fmt.Sprintf("processor not found '%s'\ntry to add code below:\nimport (\n _ \"%s\"\n)\n\n",

proc/tcp/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func init() {
99

10-
proc.RegisterProcessor("tcp.ltv", func(bundle proc.ProcessorBundle, userCallback cellnet.EventCallback) {
10+
proc.RegisterProcessor("tcp.ltv", func(bundle proc.ProcessorBundle, userCallback cellnet.EventCallback, args ...interface{}) {
1111

1212
bundle.SetTransmitter(new(TCPMessageTransmitter))
1313
bundle.SetHooker(new(MsgHooker))

proc/udp/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (UDPMessageTransmitter) OnSendMessage(ses cellnet.Session, msg interface{})
3333

3434
func init() {
3535

36-
proc.RegisterProcessor("udp.ltv", func(bundle proc.ProcessorBundle, userCallback cellnet.EventCallback) {
36+
proc.RegisterProcessor("udp.ltv", func(bundle proc.ProcessorBundle, userCallback cellnet.EventCallback, args ...interface{}) {
3737

3838
bundle.SetTransmitter(new(UDPMessageTransmitter))
3939
bundle.SetCallback(userCallback)

util/sys.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ func StackToString(count int) string {
1414

1515
var sb strings.Builder
1616

17-
var lastStr string
18-
1917
for i := startStack; i < startStack+count; i++ {
2018
_, file, line, ok := runtime.Caller(i)
2119

@@ -28,16 +26,16 @@ func StackToString(count int) string {
2826
}
2927

3028
// 折叠??
31-
if lastStr != "??" || str != "??" {
29+
if str != "??" {
3230
if i > startStack {
3331
sb.WriteString(" -> ")
3432
}
3533

3634
sb.WriteString(str)
35+
} else {
36+
break
3737
}
3838

39-
lastStr = str
40-
4139
}
4240

4341
return sb.String()

0 commit comments

Comments
 (0)