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

ServerSocketClient协程被阻塞 #8

Open
hsz8250 opened this issue Oct 30, 2021 · 2 comments
Open

ServerSocketClient协程被阻塞 #8

hsz8250 opened this issue Oct 30, 2021 · 2 comments

Comments

@hsz8250
Copy link

hsz8250 commented Oct 30, 2021

建议不要在Socket的Stop函数中不要去关闭conn,因为有可能导致Run中的conn.Read会阻塞无法返回,导致无法释放
然后最好在conn.Read之前加一个读取超时,可以跟心跳测试的间隔时间一致的30秒,把conn.Stop 放在Socket.Close一起处理
让Run这个协程能够顺利执行和释放,原来的Socket的Stop只是改变一个状态,然后再Run的loop函数中针对状态,如果状态是SSF_STOP 直接退出循环,特别是在KCP模式下很容阻塞不释放。

if this.GetState() != SSF_RUN {
return false
}

this.conn.(kcp.UDPSession).SetDeadline(time.Now().Add(time.SecondHEART_TIME_OUT))
GJ%5OVDFC80$3Y)_QV VTAR

F `B5(P}3FZ7JEA1EU)UY7P

@buguang01
Copy link

但不关闭连接的时候,如果客户端不发消息了,不是会阻塞在Read这里吗?

@bobohume
Copy link
Owner

h

建议不要在Socket的Stop函数中不要去关闭conn,因为有可能导致Run中的conn.Read会阻塞无法返回,导致无法释放 然后最好在conn.Read之前加一个读取超时,可以跟心跳测试的间隔时间一致的30秒,把conn.Stop 放在Socket.Close一起处理 让Run这个协程能够顺利执行和释放,原来的Socket的Stop只是改变一个状态,然后再Run的loop函数中针对状态,如果状态是SSF_STOP 直接退出循环,特别是在KCP模式下很容阻塞不释放。

if this.GetState() != SSF_RUN { return false }

this.conn.(_kcp.UDPSession).SetDeadline(time.Now().Add(time.Second_HEART_TIME_OUT)) GJ%5OVDFC80$3Y)_QV VTAR

F `B5(P}3FZ7JEA1EU)UY7P

是可以这么做,再stop的时候设置SetDeadline

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

3 participants