断开时关闭连接

This commit is contained in:
kercylan98 2023-05-19 19:34:09 +08:00
parent 750992cfe4
commit 174a01f864
2 changed files with 1 additions and 2 deletions

View File

@ -64,6 +64,7 @@ func (slf *event) OnConnectionClosedEvent(conn *Conn) {
for _, handle := range slf.connectionClosedEventHandles { for _, handle := range slf.connectionClosedEventHandles {
handle(slf.Server, conn) handle(slf.Server, conn)
} }
conn.Close()
} }
// RegConnectionOpenedEvent 在连接打开后将立刻执行被注册的事件处理函数 // RegConnectionOpenedEvent 在连接打开后将立刻执行被注册的事件处理函数

View File

@ -165,7 +165,6 @@ func (slf *Server) Run(addr string) error {
go func(conn *Conn) { go func(conn *Conn) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
conn.Close()
slf.OnConnectionClosedEvent(conn) slf.OnConnectionClosedEvent(conn)
} }
}() }()
@ -242,7 +241,6 @@ func (slf *Server) Run(addr string) error {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
conn.Close()
slf.OnConnectionClosedEvent(conn) slf.OnConnectionClosedEvent(conn)
} }
}() }()