From 0918aca1eafd20452e86087f3567a817960eb869 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 6 Sep 2020 08:00:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96=E4=BA=86=20Client=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E9=81=BF=E5=85=8D=E5=BE=AA=E7=8E=AF=E5=BC=95?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/client.go | 12 ++++++++++++ dbus/client.go | 10 ++-------- dbus/peer.go | 5 +++-- dbus/plugin.go | 2 +- dbus/server.go | 2 +- dtu/link.go | 5 ++--- 6 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 base/client.go diff --git a/base/client.go b/base/client.go new file mode 100644 index 0000000..f6e239f --- /dev/null +++ b/base/client.go @@ -0,0 +1,12 @@ +package base + +import "github.com/zgwit/dtu-admin/packet" + +type Client interface { + CLose() error + Send(msg *packet.Packet) error + Write(b []byte) error + Handle(msg *packet.Packet) +} + + diff --git a/dbus/client.go b/dbus/client.go index 8b004ee..857f59e 100644 --- a/dbus/client.go +++ b/dbus/client.go @@ -1,19 +1,13 @@ package dbus import ( + "github.com/zgwit/dtu-admin/base" "github.com/zgwit/dtu-admin/packet" "log" "net" "time" ) -type Client interface { - CLose() error - Send(msg *packet.Packet) error - Write(b []byte) error - handle(msg *packet.Packet) -} - type baseClient struct { conn net.Conn } @@ -47,7 +41,7 @@ func (p *baseClient) Write(b []byte) error { return nil } -func NewClient() Client { +func NewClient() base.Client { //根据类型 return nil } \ No newline at end of file diff --git a/dbus/peer.go b/dbus/peer.go index 7847d3a..c228f62 100644 --- a/dbus/peer.go +++ b/dbus/peer.go @@ -1,6 +1,7 @@ package dbus import ( + "github.com/zgwit/dtu-admin/dtu" "github.com/zgwit/dtu-admin/packet" "log" ) @@ -9,10 +10,10 @@ import ( type Peer struct { baseClient - //link *dtu.Link + link *dtu.Link } -func (p *Peer) handle(msg *packet.Packet) { +func (p *Peer) Handle(msg *packet.Packet) { switch msg.Type { case packet.TypeConnect: p.handleConnect(msg) diff --git a/dbus/plugin.go b/dbus/plugin.go index 0ee504b..a39451d 100644 --- a/dbus/plugin.go +++ b/dbus/plugin.go @@ -9,7 +9,7 @@ type Plugin struct { baseClient } -func (p *Plugin) handle(msg *packet.Packet) { +func (p *Plugin) Handle(msg *packet.Packet) { switch msg.Type { case packet.TypeConnect: p.handleConnect(msg) diff --git a/dbus/server.go b/dbus/server.go index e623c2d..c782ce1 100644 --- a/dbus/server.go +++ b/dbus/server.go @@ -64,7 +64,7 @@ func (s *Server) receive(conn net.Conn) { } packs := parser.Parse(buf[:n]) for _, pack := range packs { - c.handle(pack) + c.Handle(pack) } } diff --git a/dtu/link.go b/dtu/link.go index d887a91..69a294e 100644 --- a/dtu/link.go +++ b/dtu/link.go @@ -4,7 +4,6 @@ import ( "errors" "github.com/zgwit/dtu-admin/base" "github.com/zgwit/dtu-admin/db" - "github.com/zgwit/dtu-admin/dbus" "github.com/zgwit/dtu-admin/model" "github.com/zgwit/dtu-admin/packet" "log" @@ -25,9 +24,9 @@ type Link struct { cache [][]byte //透传链接 - peer dbus.Client + peer base.Client - plugin dbus.Client + plugin base.Client //监视器连接, monitor *Monitor -- GitLab