We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
znet/connection.go 第151 和第164行,可以接口断言下用户是否写了hook函数,再决定是否要调用:例如可以把第164行的:c.TcpServer.CallOnConnStop(c) 替换成下面的代码: ival := reflect.ValueOf(c.TcpServer).Interface() if _,ok := ival.(*Server);ok{ if val.OnConnStop!=nil{//这一句是判断用户有没有写钩子函数 c.Server.CallOnConnStop(c) } } 同理151类似改法。
The text was updated successfully, but these errors were encountered:
不错,用反射得到TcpServer是否有实体对象指向,然后再使用,这样、类型和野指针就都做了判断。 很感谢。
但是reflect会很耗性能,如果CallOnConnStop()这个函数,不经常被调用 你说的这种方式更好。
Sorry, something went wrong.
No branches or pull requests
znet/connection.go 第151 和第164行,可以接口断言下用户是否写了hook函数,再决定是否要调用:例如可以把第164行的:c.TcpServer.CallOnConnStop(c) 替换成下面的代码:
ival := reflect.ValueOf(c.TcpServer).Interface()
if _,ok := ival.(*Server);ok{
if val.OnConnStop!=nil{//这一句是判断用户有没有写钩子函数
c.Server.CallOnConnStop(c)
}
}
同理151类似改法。
The text was updated successfully, but these errors were encountered: