Skip to content
New issue

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

感觉可以优化的地方 #12

Closed
xiaodoujiao opened this issue May 26, 2019 · 2 comments
Closed

感觉可以优化的地方 #12

xiaodoujiao opened this issue May 26, 2019 · 2 comments

Comments

@xiaodoujiao
Copy link

xiaodoujiao commented May 26, 2019

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类似改法。

@xiaodoujiao

This comment has been minimized.

@aceld
Copy link
Owner

aceld commented Jun 3, 2019

不错,用反射得到TcpServer是否有实体对象指向,然后再使用,这样、类型和野指针就都做了判断。 很感谢。

但是reflect会很耗性能,如果CallOnConnStop()这个函数,不经常被调用 你说的这种方式更好。

@aceld aceld closed this as completed Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants