From 1fb1a840b74318bc0844d261508d16c1c60bdfe6 Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Thu, 5 Sep 2019 22:34:26 +0800 Subject: [PATCH] =?UTF-8?q?package=20mockserver:=20bugfix=20MockAcceptServ?= =?UTF-8?q?er=20=E6=AD=BB=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + pkg/mockserver/acceptserver.go | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e78f756..a0b26ea 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ pkg/ ......源码包 |-- connection/ ......对 net.Conn 接口的二次封装 |-- errors/ ......错误处理相关 |-- log/ ......日志库 + |-- mockserver ......模拟一些服务端,用于快速测试其它代码 |-- unique/ ......对象唯一ID demo/ ......示例相关的代码 |-- connstat/ ......简单测试 net.Conn.SetWriteDeadline 的性能 diff --git a/pkg/mockserver/acceptserver.go b/pkg/mockserver/acceptserver.go index 9c386f6..8b583ee 100644 --- a/pkg/mockserver/acceptserver.go +++ b/pkg/mockserver/acceptserver.go @@ -18,9 +18,7 @@ func (s *MockAcceptServer) Run(addr string) (err error) { if err != nil { return } - s.m.Lock() c, err := s.l.Accept() - s.m.Unlock() if err != nil { return } @@ -30,7 +28,10 @@ func (s *MockAcceptServer) Run(addr string) (err error) { func (s *MockAcceptServer) Dispose() { s.m.Lock() - s.l.Close() + if s.l != nil { + s.l.Close() + + } s.m.Unlock() }