From 854c9b0ad776ab59111faeb0cee5890af6c9f991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BE=B7=E6=BB=A1?= Date: Sat, 17 Apr 2021 23:58:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E9=BB=98=E8=AE=A4=E7=9A=84?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E7=AE=A1=E7=90=86=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- storage/IStorage.go | 2 +- storage/connection.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/storage/IStorage.go b/storage/IStorage.go index df29e81..121747b 100644 --- a/storage/IStorage.go +++ b/storage/IStorage.go @@ -18,7 +18,7 @@ type IConnection interface { // Store 存储 Store(ctx *context.WSContext) // Del 移除 - Del(ctx *context.WSContext) + Del(ctx *context.WSContext, message string) // GetCtxList 获取连接列表 GetCtxList(cidList ...string) []*context.WSContext // Clear 清空连接 diff --git a/storage/connection.go b/storage/connection.go index 6fe7bc5..0bda9d1 100644 --- a/storage/connection.go +++ b/storage/connection.go @@ -31,7 +31,11 @@ func (c *connection) Store(ctx *context.WSContext) { c.table.Set(ctx.ConnectionID, ctx) } -func (c *connection) Del(ctx *context.WSContext) { +func (c *connection) Del(ctx *context.WSContext, message string) { + if len(message) > 0 { + _ = ctx.Session.Write([]byte(message)) + _ = ctx.Session.Close() + } c.table.Del(ctx.ConnectionID) }